blob: 01754310d5fe30e850d11226bff113922ccd1298 [file] [log] [blame]
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -07001# Copyright (C) 2013 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15def genasciidoc(
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070016 name,
17 out,
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070018 srcs = [],
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070019 deps = [],
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070020 attributes = [],
21 backend = None,
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070022 visibility = []):
Shawn Pearce56910352013-09-05 09:14:24 -070023 EXPN = '.expn'
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070024
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070025 asciidoc = [
Yuxuan 'fishy' Wanga487b6c2013-10-17 09:36:33 -070026 'cd $SRCDIR;',
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070027 '$(exe //lib/asciidoctor:asciidoc)',
28 '-z', '$OUT',
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -080029 '--tmp', '$TMP',
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070030 '--in-ext', '".txt%s"' % EXPN,
31 '--out-ext', '".html"',
32 ]
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070033 if backend:
Shawn Pearce56910352013-09-05 09:14:24 -070034 asciidoc.extend(['-b', backend])
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070035 for attribute in attributes:
Shawn Pearce56910352013-09-05 09:14:24 -070036 asciidoc.extend(['-a', attribute])
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070037 asciidoc.append('$SRCS')
Yuxuan 'fishy' Wanga487b6c2013-10-17 09:36:33 -070038 newsrcs = ["doc.css"]
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070039 newdeps = deps + ['//lib/asciidoctor:asciidoc']
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070040
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070041 for src in srcs:
Shawn Pearce56910352013-09-05 09:14:24 -070042 tx = []
43 fn = src
44 if fn.startswith('BUCKGEN:') :
45 fn = src[8:]
46 tx = [':' + fn]
47 ex = fn + EXPN
48
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070049 genrule(
Shawn Pearce56910352013-09-05 09:14:24 -070050 name = ex,
51 cmd = '$(exe :replace_macros) --suffix=' + EXPN +
52 ' -s $SRCDIR/%s' % fn +
53 ' -o $OUT',
54 srcs = [src],
55 deps = tx + [':replace_macros'],
56 out = ex,
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070057 )
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070058 newdeps.append(':' + ex)
59 newsrcs.append(genfile(ex))
60
61 genrule(
62 name = name,
63 cmd = ' '.join(asciidoc),
64 srcs = newsrcs,
65 deps = newdeps,
66 out = out,
67 visibility = visibility,
68 )