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 | |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 15 | def genasciidoc_htmlonly( |
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 = [], |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 19 | attributes = [], |
| 20 | backend = None, |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 21 | searchbox = True, |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 22 | visibility = []): |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 23 | EXPN = '.' + name + '_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 = [ |
| 26 | '$(exe //lib/asciidoctor:asciidoc)', |
| 27 | '-z', '$OUT', |
Yuxuan 'fishy' Wang | f73c12a | 2014-08-20 17:14:11 -0700 | [diff] [blame] | 28 | '--base-dir', '$SRCDIR', |
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 | de83795 | 2014-08-29 10:19:22 -0700 | [diff] [blame] | 38 | newsrcs = [":doc.css"] |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 39 | for src in srcs: |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 40 | fn = src |
David Ostrovsky | d8af092 | 2014-05-30 12:42:32 +0200 | [diff] [blame] | 41 | # 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 Zu | d8db1d6 | 2014-06-11 16:57:06 +0800 | [diff] [blame] | 46 | passed_src = fn |
David Ostrovsky | d8af092 | 2014-05-30 12:42:32 +0200 | [diff] [blame] | 47 | if fn.startswith(':') : |
David Ostrovsky | d8af092 | 2014-05-30 12:42:32 +0200 | [diff] [blame] | 48 | fn = src[1:] |
| 49 | srcs = [] |
Bruce Zu | d8db1d6 | 2014-06-11 16:57:06 +0800 | [diff] [blame] | 50 | passed_src = '$(location :%s)' % fn |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 51 | ex = fn + EXPN |
| 52 | |
Yuxuan 'fishy' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 53 | genrule( |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 54 | name = ex, |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 55 | cmd = '$(exe :replace_macros) --suffix="%s"' % EXPN + |
| 56 | ' -s ' + passed_src + ' -o $OUT' + |
| 57 | (' --searchbox' if searchbox else ' --no-searchbox'), |
David Ostrovsky | d8af092 | 2014-05-30 12:42:32 +0200 | [diff] [blame] | 58 | srcs = srcs, |
Shawn Pearce | 5691035 | 2013-09-05 09:14:24 -0700 | [diff] [blame] | 59 | out = ex, |
Yuxuan 'fishy' Wang | e6cbae9 | 2013-09-03 18:26:54 -0700 | [diff] [blame] | 60 | ) |
David Ostrovsky | d8af092 | 2014-05-30 12:42:32 +0200 | [diff] [blame] | 61 | |
Yuxuan 'fishy' Wang | f73c12a | 2014-08-20 17:14:11 -0700 | [diff] [blame] | 62 | # 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' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 65 | |
| 66 | genrule( |
| 67 | name = name, |
| 68 | cmd = ' '.join(asciidoc), |
| 69 | srcs = newsrcs, |
Yuxuan 'fishy' Wang | 29db1f6 | 2013-09-11 16:24:08 -0700 | [diff] [blame] | 70 | out = out, |
| 71 | visibility = visibility, |
| 72 | ) |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 73 | |
| 74 | def 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 | ) |