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

Unified Diff: go/bootstrap.py

Issue 2095173002: Teach build.py to cross-compile go-based packages. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: prebuild stdlib Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/test_packages.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/bootstrap.py
diff --git a/go/bootstrap.py b/go/bootstrap.py
index 9881ab2cddaeaaf155155abfcbedb4d4479389bb..196f3dbd44cb981beb4996e1435a14f92ba425bf 100755
--- a/go/bootstrap.py
+++ b/go/bootstrap.py
@@ -420,16 +420,31 @@ def bootstrap(go_paths, logging_level):
"""
logging.basicConfig()
LOGGER.setLevel(logging_level)
- updated = ensure_toolset_installed(TOOLSET_ROOT)
- ensure_glide_installed(TOOLSET_ROOT)
- for p in go_paths:
- update_vendor_packages(p, force=updated)
- if updated:
- # GOPATH/pkg may have binaries generated with previous version of toolset,
- # they may not be compatible and "go build" isn't smart enough to rebuild
- # them.
+
+ # We need to build and run some Go binaries during bootstrap (e.g. glide), so
+ # make sure cross-compilation mode is disabled during bootstrap. Restore it
+ # back once bootstrap is finished.
+ prev_environ = {}
+ for k in ('GOOS', 'GOARCH', 'GOARM'):
+ prev_environ[k] = os.environ.pop(k, None)
+
+ try:
+ updated = ensure_toolset_installed(TOOLSET_ROOT)
+ ensure_glide_installed(TOOLSET_ROOT)
for p in go_paths:
- remove_directory([p, 'pkg'])
+ update_vendor_packages(p, force=updated)
+ if updated:
+ # GOPATH/pkg may have binaries generated with previous version of toolset,
+ # they may not be compatible and "go build" isn't smart enough to rebuild
+ # them.
+ for p in go_paths:
+ remove_directory([p, 'pkg'])
+ finally:
+ # Restore os.environ back. Have to do it key-by-key to actually modify the
+ # process environment (replacing os.environ object as a whole does nothing).
+ for k, v in prev_environ.iteritems():
+ if v is not None:
+ os.environ[k] = v
def prepare_go_environ():
@@ -439,10 +454,10 @@ def prepare_go_environ():
"""
bootstrap([WORKSPACE], logging.INFO)
return get_go_environ(
- toolset_root=TOOLSET_ROOT,
- workspace=WORKSPACE, # primary GOPATH with source code
- vendor_paths=[WORKSPACE], # where to look for deps.yaml and .vendor dirs
- go_appengine_path=GO_APPENGINE)
+ toolset_root=TOOLSET_ROOT,
+ workspace=WORKSPACE, # primary GOPATH with source code
+ vendor_paths=[WORKSPACE], # where to look for deps.yaml and .vendor dirs
+ go_appengine_path=GO_APPENGINE)
def find_executable(name, workspaces):
« no previous file with comments | « build/test_packages.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698