| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """Prepares a local hermetic Go installation. | 6 """Prepares a local hermetic Go installation. |
| 7 | 7 |
| 8 - Downloads and unpacks the Go toolset in ../../golang. | 8 - Downloads and unpacks the Go toolset in ../../golang. |
| 9 - Downloads and installs Glide (used by deps.py). | 9 - Downloads and installs Glide (used by deps.py). |
| 10 - Fetches code dependencies via deps.py. | 10 - Fetches code dependencies via deps.py. |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 413 |
| 414 Supposed to be called at the beginning of some script (it modifies logger). | 414 Supposed to be called at the beginning of some script (it modifies logger). |
| 415 | 415 |
| 416 Args: | 416 Args: |
| 417 go_paths: list of paths to search for deps.lock, for each path deps.py | 417 go_paths: list of paths to search for deps.lock, for each path deps.py |
| 418 will install all dependencies in <path>/.vendor/src/*. | 418 will install all dependencies in <path>/.vendor/src/*. |
| 419 logging_level: logging level of bootstrap process. | 419 logging_level: logging level of bootstrap process. |
| 420 """ | 420 """ |
| 421 logging.basicConfig() | 421 logging.basicConfig() |
| 422 LOGGER.setLevel(logging_level) | 422 LOGGER.setLevel(logging_level) |
| 423 updated = ensure_toolset_installed(TOOLSET_ROOT) | 423 |
| 424 ensure_glide_installed(TOOLSET_ROOT) | 424 # We need to build and run some Go binaries during bootstrap (e.g. glide), so |
| 425 for p in go_paths: | 425 # make sure cross-compilation mode is disabled during bootstrap. Restore it |
| 426 update_vendor_packages(p, force=updated) | 426 # back once bootstrap is finished. |
| 427 if updated: | 427 prev_environ = {} |
| 428 # GOPATH/pkg may have binaries generated with previous version of toolset, | 428 for k in ('GOOS', 'GOARCH', 'GOARM'): |
| 429 # they may not be compatible and "go build" isn't smart enough to rebuild | 429 prev_environ[k] = os.environ.pop(k, None) |
| 430 # them. | 430 |
| 431 try: |
| 432 updated = ensure_toolset_installed(TOOLSET_ROOT) |
| 433 ensure_glide_installed(TOOLSET_ROOT) |
| 431 for p in go_paths: | 434 for p in go_paths: |
| 432 remove_directory([p, 'pkg']) | 435 update_vendor_packages(p, force=updated) |
| 436 if updated: |
| 437 # GOPATH/pkg may have binaries generated with previous version of toolset, |
| 438 # they may not be compatible and "go build" isn't smart enough to rebuild |
| 439 # them. |
| 440 for p in go_paths: |
| 441 remove_directory([p, 'pkg']) |
| 442 finally: |
| 443 # Restore os.environ back. Have to do it key-by-key to actually modify the |
| 444 # process environment (replacing os.environ object as a whole does nothing). |
| 445 for k, v in prev_environ.iteritems(): |
| 446 if v is not None: |
| 447 os.environ[k] = v |
| 433 | 448 |
| 434 | 449 |
| 435 def prepare_go_environ(): | 450 def prepare_go_environ(): |
| 436 """Returns dict with environment variables to set to use Go toolset. | 451 """Returns dict with environment variables to set to use Go toolset. |
| 437 | 452 |
| 438 Installs or updates the toolset and vendored dependencies if necessary. | 453 Installs or updates the toolset and vendored dependencies if necessary. |
| 439 """ | 454 """ |
| 440 bootstrap([WORKSPACE], logging.INFO) | 455 bootstrap([WORKSPACE], logging.INFO) |
| 441 return get_go_environ( | 456 return get_go_environ( |
| 442 toolset_root=TOOLSET_ROOT, | 457 toolset_root=TOOLSET_ROOT, |
| 443 workspace=WORKSPACE, # primary GOPATH with source code | 458 workspace=WORKSPACE, # primary GOPATH with source code |
| 444 vendor_paths=[WORKSPACE], # where to look for deps.yaml and .vendor dirs | 459 vendor_paths=[WORKSPACE], # where to look for deps.yaml and .vendor dirs |
| 445 go_appengine_path=GO_APPENGINE) | 460 go_appengine_path=GO_APPENGINE) |
| 446 | 461 |
| 447 | 462 |
| 448 def find_executable(name, workspaces): | 463 def find_executable(name, workspaces): |
| 449 """Returns full path to an executable in some bin/ (in GOROOT or GOBIN).""" | 464 """Returns full path to an executable in some bin/ (in GOROOT or GOBIN).""" |
| 450 basename = name | 465 basename = name |
| 451 if EXE_SFX and basename.endswith(EXE_SFX): | 466 if EXE_SFX and basename.endswith(EXE_SFX): |
| 452 basename = basename[:-len(EXE_SFX)] | 467 basename = basename[:-len(EXE_SFX)] |
| 453 roots = [os.path.join(TOOLSET_ROOT, 'go', 'bin')] | 468 roots = [os.path.join(TOOLSET_ROOT, 'go', 'bin')] |
| 454 for path in workspaces: | 469 for path in workspaces: |
| 455 roots.extend([ | 470 roots.extend([ |
| 456 os.path.join(path, '.vendor', 'bin'), | 471 os.path.join(path, '.vendor', 'bin'), |
| 457 os.path.join(path, 'bin'), | 472 os.path.join(path, 'bin'), |
| 458 ]) | 473 ]) |
| 459 for root in roots: | 474 for root in roots: |
| 460 full_path = os.path.join(root, basename + EXE_SFX) | 475 full_path = os.path.join(root, basename + EXE_SFX) |
| 461 if os.path.exists(full_path): | 476 if os.path.exists(full_path): |
| 462 return full_path | 477 return full_path |
| 463 return name | 478 return name |
| 464 | 479 |
| 465 | 480 |
| 466 def main(): | 481 def main(): |
| 467 bootstrap([WORKSPACE], logging.DEBUG) | 482 bootstrap([WORKSPACE], logging.DEBUG) |
| 468 return 0 | 483 return 0 |
| 469 | 484 |
| 470 | 485 |
| 471 if __name__ == '__main__': | 486 if __name__ == '__main__': |
| 472 sys.exit(main()) | 487 sys.exit(main()) |
| OLD | NEW |