Ray Milkey | f80bbb2 | 2016-03-11 10:16:22 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (C) 2013 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from optparse import OptionParser |
| 17 | import re |
| 18 | from subprocess import check_call, CalledProcessError, Popen, PIPE |
| 19 | |
| 20 | MAIN = ['//buck-tools/eclipse:classpath'] |
| 21 | PAT = re.compile(r'"(//.*?)" -> "//buck-tools:download_file"') |
| 22 | # TODO(davido): Remove this hack when Buck bugs are fixed: |
| 23 | # https://github.com/facebook/buck/issues/656 |
| 24 | # https://github.com/facebook/buck/issues/658 |
| 25 | JGIT = re.compile(r'//org.eclipse.jgit.*') |
| 26 | CELL = '//lib/jgit' |
| 27 | |
| 28 | opts = OptionParser() |
| 29 | opts.add_option('--src', action='store_true') |
| 30 | args, _ = opts.parse_args() |
| 31 | |
| 32 | targets = set() |
| 33 | |
| 34 | p = Popen(['buck', 'audit', 'classpath', '--dot'] + MAIN, stdout = PIPE) |
| 35 | for line in p.stdout: |
| 36 | m = PAT.search(line) |
| 37 | if m: |
| 38 | n = m.group(1) |
| 39 | if JGIT.match(n): |
| 40 | n = CELL + n[1:] |
| 41 | if args.src and n.endswith('__download_bin'): |
| 42 | n = n[:-13] + 'src' |
| 43 | targets.add(n) |
| 44 | r = p.wait() |
| 45 | if r != 0: |
| 46 | exit(r) |
| 47 | |
| 48 | try: |
| 49 | check_call(['buck', 'build'] + sorted(targets)) |
| 50 | except CalledProcessError as err: |
| 51 | exit(1) |