blob: 2520c74f46a4ae8997a51dae6aa256eba3e3a1b8 [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
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -070015def genasciidoc_htmlonly(
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070016 name,
17 out,
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070018 srcs = [],
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070019 attributes = [],
20 backend = None,
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -070021 searchbox = True,
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070022 visibility = []):
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -070023 EXPN = '.' + name + '_expn'
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070024
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070025 asciidoc = [
26 '$(exe //lib/asciidoctor:asciidoc)',
27 '-z', '$OUT',
Yuxuan 'fishy' Wangf73c12a2014-08-20 17:14:11 -070028 '--base-dir', '$SRCDIR',
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' Wangde837952014-08-29 10:19:22 -070038 newsrcs = [":doc.css"]
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070039 for src in srcs:
Shawn Pearce56910352013-09-05 09:14:24 -070040 fn = src
David Ostrovskyd8af0922014-05-30 12:42:32 +020041 # We have two cases: regular source files and generated files.
42 # Generated files are passed as targets ':foo', and ':' is removed.
43 # 1. regular files: cmd = '-s foo', srcs = ['foo']
44 # 2. generated files: cmd = '-s $(location :foo)', srcs = []
45 srcs = [src]
Bruce Zud8db1d62014-06-11 16:57:06 +080046 passed_src = fn
David Ostrovskyd8af0922014-05-30 12:42:32 +020047 if fn.startswith(':') :
David Ostrovskyd8af0922014-05-30 12:42:32 +020048 fn = src[1:]
49 srcs = []
Bruce Zud8db1d62014-06-11 16:57:06 +080050 passed_src = '$(location :%s)' % fn
Shawn Pearce56910352013-09-05 09:14:24 -070051 ex = fn + EXPN
52
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070053 genrule(
Shawn Pearce56910352013-09-05 09:14:24 -070054 name = ex,
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -070055 cmd = '$(exe :replace_macros) --suffix="%s"' % EXPN +
56 ' -s ' + passed_src + ' -o $OUT' +
57 (' --searchbox' if searchbox else ' --no-searchbox'),
David Ostrovskyd8af0922014-05-30 12:42:32 +020058 srcs = srcs,
Shawn Pearce56910352013-09-05 09:14:24 -070059 out = ex,
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070060 )
David Ostrovskyd8af0922014-05-30 12:42:32 +020061
Yuxuan 'fishy' Wangf73c12a2014-08-20 17:14:11 -070062 # The new AsciiDoctor requires both the css file and include files are under
63 # the same directory. Luckily Buck allows us to use :target as SRCS now.
64 newsrcs.append(':%s' % ex)
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070065
66 genrule(
67 name = name,
68 cmd = ' '.join(asciidoc),
69 srcs = newsrcs,
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070070 out = out,
71 visibility = visibility,
72 )
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -070073
74def genasciidoc(
75 name,
76 out,
77 docdir,
78 srcs = [],
79 attributes = [],
80 backend = None,
81 searchbox = True,
82 visibility = []):
83 SUFFIX = '_htmlonly'
84
85 genasciidoc_htmlonly(
86 name = name + SUFFIX,
87 srcs = srcs,
88 attributes = attributes,
89 backend = backend,
90 searchbox = searchbox,
91 out = name + SUFFIX + '.zip',
92 )
93
94 genrule(
95 name = name,
96 cmd = 'cd $TMP;' +
97 'mkdir -p %s/images;' % docdir +
98 'unzip -q $(location %s) -d %s/;'
99 % (':' + name + SUFFIX, docdir) +
100 'for s in $SRCS;do ln -s $s %s;done;' % docdir +
101 'mv %s/*.{jpg,png} %s/images;' % (docdir, docdir) +
102 'cp $(location %s) LICENSES.txt;' % ':licenses.txt' +
103 'zip -qr $OUT *',
104 srcs = glob([
105 'images/*.jpg',
106 'images/*.png',
107 ]) + [':doc.css'],
108 out = out,
109 visibility = visibility,
110 )