Chromium Code Reviews| Index: build/go/go.py |
| diff --git a/build/go/go.py b/build/go/go.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..c2986fe1bdadc8e5f7eb15b977ef4d5ddffc66a3 |
| --- /dev/null |
| +++ b/build/go/go.py |
| @@ -0,0 +1,57 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +""" |
| +This script invokes the go build tool. |
| +Must be called as follows: |
| +python go.py <go-binary> <build directory> <output file> <src directory> |
| +<CGO_CFLAGS> <CGO_LDFLAGS> <go-binary options> |
| +eg. |
| +python go.py /usr/lib/google-golang/bin/go out/build out/a.out .. "-I." |
| +"-L. -ltest" test -c test/test.go |
| +""" |
| + |
| +import os |
| +import shutil |
| +import string |
| +import sys |
| + |
| +def main(): |
| + args = sys.argv |
| + go_binary = args[1] |
|
qsr
2014/09/15 09:54:24
You can use argpath. That would make it clearer wh
tburkard
2014/09/16 12:29:13
You mean argparse? I was trying to do that, howeve
qsr
2014/09/18 08:30:38
I'm not sure to understand, you can do something l
tburkard
2014/09/18 14:23:42
Yup, I tried doing that, however, if 'remaining' c
qsr
2014/09/18 14:30:55
You can use -- to tell argparse all arguments is p
tburkard
2014/09/18 15:20:09
Done.
|
| + build_dir = args[2] |
| + out_file = os.path.abspath(args[3]) |
| + # The src directory specified is relative. We will later need this as an |
| + # absolute path. |
| + src_root = os.path.abspath(args[4]) + "/" |
| + # GOPATH must be absolute, and point to one directory up from |src_Root| |
| + go_path = os.path.abspath(src_root + "..") |
|
qsr
2014/09/15 09:54:24
Instead of using concatenation, and so needing to
tburkard
2014/09/18 15:20:09
Done.
|
| + # CGO_CFLAGS and CGO_LDFLAGS contain a paths relative to |src_root| |
| + # We need to make these absolute paths by prepending the (absolute) |src_root| |
| + cgo_cflags = string.replace(" " + args[5], " -I", " -I" + src_root)[1:] |
|
qsr
2014/09/15 09:54:24
If you expect this to be a list of -Ifoo -Ibar, ju
tburkard
2014/09/16 12:29:13
Well, one issue is that Go works more consistently
qsr
2014/09/18 08:30:38
Hum, ok I see. Then should this script hardcode th
tburkard
2014/09/18 14:23:41
.. but there's a bit more to it than just the outp
qsr
2014/09/18 14:30:55
That I do not understand, your libs should all be
tburkard
2014/09/18 15:20:09
Ah, yes, that makes sense.
So I'd have a positiona
|
| + cgo_ldflags = string.replace(" " + args[6], " -L", " -L" + src_root)[1:] |
| + go_options = args[7:] |
| + try: |
| + shutil.rmtree(build_dir, True) |
| + os.mkdir(build_dir) |
| + except: |
| + pass |
| + old_directory = os.getcwd() |
| + os.chdir(build_dir) |
|
qsr
2014/09/15 09:54:23
Do you really need to chdir, doesn't the go compil
tburkard
2014/09/16 12:29:13
Go does support it for binaries, but not for test
|
| + os.environ["GOPATH"] = go_path |
| + os.environ["CGO_CFLAGS"] = cgo_cflags |
| + os.environ["CGO_LDFLAGS"] = cgo_ldflags |
| + os.system("%s %s" % (go_binary, " ".join(go_options))) |
| + out_files = [ f for f in os.listdir(".") if os.path.isfile(f)] |
| + if (len(out_files) > 0): |
| + shutil.move(out_files[0], out_file) |
| + os.chdir(old_directory) |
| + try: |
| + shutil.rmtree(build_dir, True) |
| + except: |
| + pass |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |