Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | def genasciidoc( |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 16 | srcs = [], |
| 17 | outs = [], |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 18 | deps = {}, |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 19 | attributes = [], |
| 20 | backend = None, |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 21 | visibility = []): |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 22 | EXPN = '.expn' |
Yuxuan 'fishy' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 23 | |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 24 | asciidoc = ['asciidoc'] |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 25 | if backend: |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 26 | asciidoc.extend(['-b', backend]) |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 27 | for attribute in attributes: |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 28 | asciidoc.extend(['-a', attribute]) |
| 29 | asciidoc.extend(['-o', '$OUT']) |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 30 | |
| 31 | for p in zip(srcs, outs): |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 32 | 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' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 42 | genrule( |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 43 | 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' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 50 | ) |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 51 | genrule( |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame^] | 52 | 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 Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 57 | visibility = visibility, |
| 58 | ) |