blob: 694d6b5aa6743bb779945f5c1e1334ccad865631 [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(
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070016 srcs = [],
17 outs = [],
Shawn Pearce56910352013-09-05 09:14:24 -070018 deps = {},
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070019 attributes = [],
20 backend = None,
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070021 visibility = []):
Shawn Pearce56910352013-09-05 09:14:24 -070022 EXPN = '.expn'
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070023
Shawn Pearce56910352013-09-05 09:14:24 -070024 asciidoc = ['asciidoc']
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070025 if backend:
Shawn Pearce56910352013-09-05 09:14:24 -070026 asciidoc.extend(['-b', backend])
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070027 for attribute in attributes:
Shawn Pearce56910352013-09-05 09:14:24 -070028 asciidoc.extend(['-a', attribute])
29 asciidoc.extend(['-o', '$OUT'])
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070030
31 for p in zip(srcs, outs):
Shawn Pearce56910352013-09-05 09:14:24 -070032 src, out = p
33 dep = deps.get(src) or []
34
35 tx = []
36 fn = src
37 if fn.startswith('BUCKGEN:') :
38 fn = src[8:]
39 tx = [':' + fn]
40 ex = fn + EXPN
41
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070042 genrule(
Shawn Pearce56910352013-09-05 09:14:24 -070043 name = ex,
44 cmd = '$(exe :replace_macros) --suffix=' + EXPN +
45 ' -s $SRCDIR/%s' % fn +
46 ' -o $OUT',
47 srcs = [src],
48 deps = tx + [':replace_macros'],
49 out = ex,
Yuxuan 'fishy' Wange6cbae92013-09-03 18:26:54 -070050 )
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070051 genrule(
Shawn Pearce56910352013-09-05 09:14:24 -070052 name = out,
53 cmd = ' '.join(asciidoc + ['$SRCDIR/' + ex]),
54 srcs = [genfile(ex)] + [genfile(n + EXPN) for n in dep],
55 deps = [':' + ex] + [':' + n + EXPN for n in dep],
56 out = out,
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070057 visibility = visibility,
58 )