blob: e2de7858cc37c59b3cdd4cbbc982f7094ac083b2 [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 = [
26 '$(exe //lib/asciidoctor:asciidoc)',
27 '-z', '$OUT',
28 '--in-ext', '".txt%s"' % EXPN,
29 '--out-ext', '".html"',
30 ]
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070031 if backend:
Shawn Pearce56910352013-09-05 09:14:24 -070032 asciidoc.extend(['-b', backend])
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070033 for attribute in attributes:
Shawn Pearce56910352013-09-05 09:14:24 -070034 asciidoc.extend(['-a', attribute])
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070035 asciidoc.append('$SRCS')
36 newsrcs = []
37 newdeps = deps + ['//lib/asciidoctor:asciidoc']
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070038
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070039 for src in srcs:
Shawn Pearce56910352013-09-05 09:14:24 -070040 tx = []
41 fn = src
42 if fn.startswith('BUCKGEN:') :
43 fn = src[8:]
44 tx = [':' + fn]
45 ex = fn + EXPN
46
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070047 genrule(
Shawn Pearce56910352013-09-05 09:14:24 -070048 name = ex,
49 cmd = '$(exe :replace_macros) --suffix=' + EXPN +
50 ' -s $SRCDIR/%s' % fn +
51 ' -o $OUT',
52 srcs = [src],
53 deps = tx + [':replace_macros'],
54 out = ex,
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070055 )
Yuxuan 'fishy' Wang29db1f62013-09-11 16:24:08 -070056 newdeps.append(':' + ex)
57 newsrcs.append(genfile(ex))
58
59 genrule(
60 name = name,
61 cmd = ' '.join(asciidoc),
62 srcs = newsrcs,
63 deps = newdeps,
64 out = out,
65 visibility = visibility,
66 )