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( |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 16 | name, |
| 17 | out, |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 18 | srcs = [], |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 19 | deps = [], |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 20 | attributes = [], |
| 21 | backend = None, |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 22 | visibility = []): |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 23 | EXPN = '.expn' |
Yuxuan 'fishy' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 24 | |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 25 | asciidoc = [ |
Yuxuan 'fishy' Wang | a487b6c | 2013-10-17 09:36:33 -0700 | [diff] [blame] | 26 | 'cd $SRCDIR;', |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 27 | '$(exe //lib/asciidoctor:asciidoc)', |
| 28 | '-z', '$OUT', |
Shawn Pearce | 4e1a8bc | 2013-11-28 18:38:30 -0800 | [diff] [blame] | 29 | '--tmp', '$TMP', |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 30 | '--in-ext', '".txt%s"' % EXPN, |
| 31 | '--out-ext', '".html"', |
| 32 | ] |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 33 | if backend: |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 34 | asciidoc.extend(['-b', backend]) |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 35 | for attribute in attributes: |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 36 | asciidoc.extend(['-a', attribute]) |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 37 | asciidoc.append('$SRCS') |
Yuxuan 'fishy' Wang | a487b6c | 2013-10-17 09:36:33 -0700 | [diff] [blame] | 38 | newsrcs = ["doc.css"] |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 39 | newdeps = deps + ['//lib/asciidoctor:asciidoc'] |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 40 | |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 41 | for src in srcs: |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 42 | tx = [] |
| 43 | fn = src |
| 44 | if fn.startswith('BUCKGEN:') : |
| 45 | fn = src[8:] |
| 46 | tx = [':' + fn] |
| 47 | ex = fn + EXPN |
| 48 | |
Yuxuan 'fishy' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 49 | genrule( |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 50 | 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' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 57 | ) |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 58 | 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 | ) |