| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ | 6 """ |
| 7 This script invokes the go build tool. | 7 This script invokes the go build tool. |
| 8 Must be called as follows: | 8 Must be called as follows: |
| 9 python go.py <go-binary> <build directory> <output file> <src directory> | 9 python go.py <go-binary> <build directory> <output file> <src directory> |
| 10 <CGO_CFLAGS> <CGO_LDFLAGS> <go-binary options> | 10 <CGO_CFLAGS> <CGO_LDFLAGS> <go-binary options> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 parser.add_argument('cgo_ldflags') | 28 parser.add_argument('cgo_ldflags') |
| 29 parser.add_argument('go_option', nargs='*') | 29 parser.add_argument('go_option', nargs='*') |
| 30 args = parser.parse_args() | 30 args = parser.parse_args() |
| 31 go_binary = args.go_binary | 31 go_binary = args.go_binary |
| 32 build_dir = args.build_directory | 32 build_dir = args.build_directory |
| 33 out_file = os.path.abspath(args.output_file) | 33 out_file = os.path.abspath(args.output_file) |
| 34 # The src directory specified is relative. We need this as an absolute path. | 34 # The src directory specified is relative. We need this as an absolute path. |
| 35 src_root = os.path.abspath(args.src_root) | 35 src_root = os.path.abspath(args.src_root) |
| 36 # GOPATH must be absolute, and point to one directory up from |src_Root| | 36 # GOPATH must be absolute, and point to one directory up from |src_Root| |
| 37 go_path = os.path.abspath(os.path.join(src_root, "..")) | 37 go_path = os.path.abspath(os.path.join(src_root, "..")) |
| 38 # GOPATH also includes any third_party/go libraries that have been imported |
| 39 go_path += ":" + os.path.abspath(os.path.join(src_root, "third_party/go")) |
| 38 go_options = args.go_option | 40 go_options = args.go_option |
| 39 try: | 41 try: |
| 40 shutil.rmtree(build_dir, True) | 42 shutil.rmtree(build_dir, True) |
| 41 os.mkdir(build_dir) | 43 os.mkdir(build_dir) |
| 42 except: | 44 except: |
| 43 pass | 45 pass |
| 44 old_directory = os.getcwd() | 46 old_directory = os.getcwd() |
| 45 os.chdir(build_dir) | 47 os.chdir(build_dir) |
| 46 os.environ["GOPATH"] = go_path | 48 os.environ["GOPATH"] = go_path |
| 47 os.environ["CGO_CFLAGS"] = args.cgo_cflags | 49 os.environ["CGO_CFLAGS"] = args.cgo_cflags |
| 48 os.environ["CGO_LDFLAGS"] = args.cgo_ldflags | 50 os.environ["CGO_LDFLAGS"] = args.cgo_ldflags |
| 49 os.system("%s %s" % (go_binary, " ".join(go_options))) | 51 os.system("%s %s" % (go_binary, " ".join(go_options))) |
| 50 out_files = [ f for f in os.listdir(".") if os.path.isfile(f)] | 52 out_files = [ f for f in os.listdir(".") if os.path.isfile(f)] |
| 51 if (len(out_files) > 0): | 53 if (len(out_files) > 0): |
| 52 shutil.move(out_files[0], out_file) | 54 shutil.move(out_files[0], out_file) |
| 53 os.chdir(old_directory) | 55 os.chdir(old_directory) |
| 54 try: | 56 try: |
| 55 shutil.rmtree(build_dir, True) | 57 shutil.rmtree(build_dir, True) |
| 56 except: | 58 except: |
| 57 pass | 59 pass |
| 58 | 60 |
| 59 if __name__ == '__main__': | 61 if __name__ == '__main__': |
| 60 sys.exit(main()) | 62 sys.exit(main()) |
| OLD | NEW |