Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: build/go/go.py

Issue 556813003: Add Go build support for GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/go/rules.gni » ('j') | build/go/rules.gni » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """
7 This script invokes the go build tool.
8 Must be called as follows:
9 python go.py <go-binary> <build directory> <output file> <src directory>
10 <CGO_CFLAGS> <CGO_LDFLAGS> <go-binary options>
11 eg.
12 python go.py /usr/lib/google-golang/bin/go out/build out/a.out .. "-I."
13 "-L. -ltest" test -c test/test.go
14 """
15
16 import os
17 import shutil
18 import string
19 import sys
20
21 def main():
22 args = sys.argv
23 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.
24 build_dir = args[2]
25 out_file = os.path.abspath(args[3])
26 # The src directory specified is relative. We will later need this as an
27 # absolute path.
28 src_root = os.path.abspath(args[4]) + "/"
29 # GOPATH must be absolute, and point to one directory up from |src_Root|
30 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.
31 # CGO_CFLAGS and CGO_LDFLAGS contain a paths relative to |src_root|
32 # We need to make these absolute paths by prepending the (absolute) |src_root|
33 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
34 cgo_ldflags = string.replace(" " + args[6], " -L", " -L" + src_root)[1:]
35 go_options = args[7:]
36 try:
37 shutil.rmtree(build_dir, True)
38 os.mkdir(build_dir)
39 except:
40 pass
41 old_directory = os.getcwd()
42 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
43 os.environ["GOPATH"] = go_path
44 os.environ["CGO_CFLAGS"] = cgo_cflags
45 os.environ["CGO_LDFLAGS"] = cgo_ldflags
46 os.system("%s %s" % (go_binary, " ".join(go_options)))
47 out_files = [ f for f in os.listdir(".") if os.path.isfile(f)]
48 if (len(out_files) > 0):
49 shutil.move(out_files[0], out_file)
50 os.chdir(old_directory)
51 try:
52 shutil.rmtree(build_dir, True)
53 except:
54 pass
55
56 if __name__ == '__main__':
57 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/go/rules.gni » ('j') | build/go/rules.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698