OLD | NEW |
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 # This file contains a set of utilities functions used by other Python-based | 5 # This file contains a set of utilities functions used by other Python-based |
6 # scripts. | 6 # scripts. |
7 | 7 |
8 import commands | 8 import commands |
9 import datetime | 9 import datetime |
10 import json | 10 import json |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 print 'Executing: ' + ' '.join(cmd) | 558 print 'Executing: ' + ' '.join(cmd) |
559 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 559 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
560 shell=IsWindows()) | 560 shell=IsWindows()) |
561 output = pipe.communicate() | 561 output = pipe.communicate() |
562 if pipe.returncode != 0: | 562 if pipe.returncode != 0: |
563 raise Exception('Execution failed: ' + str(output)) | 563 raise Exception('Execution failed: ' + str(output)) |
564 return pipe.returncode, output | 564 return pipe.returncode, output |
565 | 565 |
566 | 566 |
567 def DartBinary(): | 567 def DartBinary(): |
| 568 # TODO(24311): Replace all uses of this with CheckedInSdk[Fix]Executable(). |
568 tools_dir = os.path.dirname(os.path.realpath(__file__)) | 569 tools_dir = os.path.dirname(os.path.realpath(__file__)) |
569 dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin') | 570 dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin') |
570 if IsWindows(): | 571 if IsWindows(): |
571 return os.path.join(dart_binary_prefix, 'windows', 'dart.exe') | 572 return os.path.join(dart_binary_prefix, 'windows', 'dart.exe') |
572 else: | 573 else: |
573 arch = GuessArchitecture() | 574 arch = GuessArchitecture() |
574 system = GuessOS() | 575 system = GuessOS() |
575 if arch == 'armv5te': | 576 if arch == 'armv5te': |
576 # TODO(zra): This binary does not exist, yet. Check one in once we have | 577 # TODO(zra): This binary does not exist, yet. Check one in once we have |
577 # sufficient stability. | 578 # sufficient stability. |
578 return os.path.join(dart_binary_prefix, system, 'dart-armv5te') | 579 return os.path.join(dart_binary_prefix, system, 'dart-armv5te') |
579 elif arch == 'arm': | 580 elif arch == 'arm': |
580 return os.path.join(dart_binary_prefix, system, 'dart-arm') | 581 return os.path.join(dart_binary_prefix, system, 'dart-arm') |
581 elif arch == 'arm64': | 582 elif arch == 'arm64': |
582 return os.path.join(dart_binary_prefix, system, 'dart-arm64') | 583 return os.path.join(dart_binary_prefix, system, 'dart-arm64') |
583 elif arch == 'mips': | 584 elif arch == 'mips': |
584 return os.path.join(dart_binary_prefix, system, 'dart-mips') | 585 return os.path.join(dart_binary_prefix, system, 'dart-mips') |
585 else: | 586 else: |
586 return os.path.join(dart_binary_prefix, system, 'dart') | 587 return os.path.join(dart_binary_prefix, system, 'dart') |
587 | 588 |
588 | 589 |
589 def DartSdkBinary(): | 590 def DartSdkBinary(): |
590 tools_dir = os.path.dirname(os.path.realpath(__file__)) | 591 tools_dir = os.path.dirname(os.path.realpath(__file__)) |
591 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') | 592 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') |
592 return os.path.join(dart_binary_prefix, 'dart') | 593 return os.path.join(dart_binary_prefix, 'dart') |
593 | 594 |
594 | 595 |
| 596 # The checked-in SDKs are documented at |
| 597 # https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools |
595 def CheckedInSdkPath(): | 598 def CheckedInSdkPath(): |
596 # We don't use the normal macos, linux, win32 directory names here, instead, | 599 # We don't use the normal macos, linux, win32 directory names here, instead, |
597 # we use the names that the download_from_google_storage script uses. | 600 # we use the names that the download_from_google_storage script uses. |
598 osdict = {'Darwin':'mac', 'Linux':'linux', 'Windows':'win'} | 601 osdict = {'Darwin':'mac', 'Linux':'linux', 'Windows':'win'} |
599 system = platform.system() | 602 system = platform.system() |
600 try: | 603 try: |
601 osname = osdict[system] | 604 osname = osdict[system] |
602 except KeyError: | 605 except KeyError: |
603 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system) | 606 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system) |
604 return None; | 607 return None; |
605 tools_dir = os.path.dirname(os.path.realpath(__file__)) | 608 tools_dir = os.path.dirname(os.path.realpath(__file__)) |
606 return os.path.join(tools_dir, | 609 return os.path.join(tools_dir, |
607 'sdks', | 610 'sdks', |
608 osname, | 611 osname, |
609 'dart-sdk') | 612 'dart-sdk') |
610 | 613 |
611 | 614 |
612 def CheckedInPubPath(): | 615 def CheckedInSdkExecutable(): |
613 executable_name = 'pub' | 616 name = 'dart' |
614 if platform.system() == 'Windows': | 617 if IsWindows(): |
615 executable_name = 'pub.bat' | 618 name = 'dart.exe' |
616 return os.path.join(CheckedInSdkPath(), 'bin', executable_name) | 619 elif GuessOS() == 'linux': |
| 620 arch = GuessArchitecture() |
| 621 if arch == 'mips': |
| 622 name = 'dart-mips' |
| 623 elif arch == 'arm': |
| 624 name = 'dart-arm' |
| 625 return os.path.join(CheckedInSdkPath(), 'bin', name) |
| 626 |
| 627 |
| 628 def CheckedInSdkCheckExecutable(): |
| 629 executable = CheckedInSdkExecutable() |
| 630 canary_script = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 631 'canary.dart') |
| 632 try: |
| 633 if 42 == subprocess.call([executable, canary_script]): |
| 634 return True |
| 635 except OSError as e: |
| 636 pass |
| 637 return False |
617 | 638 |
618 | 639 |
619 class TempDir(object): | 640 class TempDir(object): |
620 def __init__(self, prefix=''): | 641 def __init__(self, prefix=''): |
621 self._temp_dir = None | 642 self._temp_dir = None |
622 self._prefix = prefix | 643 self._prefix = prefix |
623 | 644 |
624 def __enter__(self): | 645 def __enter__(self): |
625 self._temp_dir = tempfile.mkdtemp(self._prefix) | 646 self._temp_dir = tempfile.mkdtemp(self._prefix) |
626 return self._temp_dir | 647 return self._temp_dir |
(...skipping 11 matching lines...) Expand all Loading... |
638 os.chdir(self._working_directory) | 659 os.chdir(self._working_directory) |
639 | 660 |
640 def __exit__(self, *_): | 661 def __exit__(self, *_): |
641 print "Enter directory = ", self._old_cwd | 662 print "Enter directory = ", self._old_cwd |
642 os.chdir(self._old_cwd) | 663 os.chdir(self._old_cwd) |
643 | 664 |
644 | 665 |
645 if __name__ == "__main__": | 666 if __name__ == "__main__": |
646 import sys | 667 import sys |
647 Main() | 668 Main() |
OLD | NEW |