Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame^] | 1 | import os |
| 2 | import subprocess |
| 3 | |
| 4 | #### UTILITIES #### |
| 5 | |
| 6 | def enum (*sequential, **named): |
| 7 | enums = dict(zip(sequential, range(len(sequential))), **named) |
| 8 | return type('Enum', (), enums) |
| 9 | |
| 10 | #### SETTINGS #### |
| 11 | |
| 12 | #### INTERFACE TO THE XCODEPROJ #### |
| 13 | |
| 14 | def lldb_source_path (): |
| 15 | return os.environ.get('SRCROOT') |
| 16 | |
| 17 | def expected_llvm_build_path (): |
| 18 | if build_type() == BuildType.Xcode: |
| 19 | return package_build_path() |
| 20 | else: |
| 21 | return os.path.join(os.environ.get('LLDB_PATH_TO_LLVM_BUILD'), package_build_dir_name("llvm")) |
| 22 | |
| 23 | def archives_txt (): |
| 24 | return os.path.join(expected_package_build_path(), "archives.txt") |
| 25 | |
| 26 | def expected_package_build_path (): |
| 27 | return os.path.abspath(os.path.join(expected_llvm_build_path(), "..")) |
| 28 | |
| 29 | def architecture (): |
| 30 | platform_name = os.environ.get('RC_PLATFORM_NAME') |
| 31 | if not platform_name: |
| 32 | platform_name = os.environ.get('PLATFORM_NAME') |
| 33 | platform_arch = os.environ.get('ARCHS').split()[-1] |
| 34 | return platform_name + "-" + platform_arch |
| 35 | |
| 36 | def lldb_configuration (): |
| 37 | return os.environ.get('CONFIGURATION') |
| 38 | |
| 39 | def llvm_configuration (): |
| 40 | return os.environ.get('LLVM_CONFIGURATION') |
| 41 | |
| 42 | def llvm_build_dirtree (): |
| 43 | return os.environ.get('LLVM_BUILD_DIRTREE') |
| 44 | |
| 45 | # Edit the code below when adding build styles. |
| 46 | |
| 47 | BuildType = enum('Xcode') # (Debug,DebugClang,Release) |
| 48 | |
| 49 | def build_type (): |
| 50 | return BuildType.Xcode |
| 51 | |
| 52 | #### VCS UTILITIES #### |
| 53 | |
| 54 | VCS = enum('git', |
| 55 | 'svn') |
| 56 | |
| 57 | def run_in_directory(args, path): |
| 58 | return subprocess.check_output(args, cwd=path) |
| 59 | |
| 60 | class Git: |
| 61 | def __init__ (self, spec): |
| 62 | self.spec = spec |
| 63 | def status (self): |
| 64 | return run_in_directory(["git", "branch", "-v"], self.spec['root']) |
| 65 | def diff (self): |
| 66 | return run_in_directory(["git", "diff"], self.spec['root']) |
| 67 | def check_out (self): |
| 68 | run_in_directory(["git", "clone", self.spec['url'], self.spec['root']], lldb_source_path()) |
| 69 | run_in_directory(["git", "fetch", "--all"], self.spec['root']) |
| 70 | run_in_directory(["git", "checkout", self.spec['ref']], self.spec['root']) |
| 71 | |
| 72 | class SVN: |
| 73 | def __init__ (self, spec): |
| 74 | self.spec = spec |
| 75 | def status (self): |
| 76 | return run_in_directory(["svn", "info"], self.spec['root']) |
| 77 | def diff (self): |
| 78 | return run_in_directory(["svn", "diff"], self.spec['root']) |
| 79 | # TODO implement check_out |
| 80 | |
| 81 | def vcs (spec): |
| 82 | if spec['vcs'] == VCS.git: |
| 83 | return Git(spec) |
| 84 | elif spec['vcs'] == VCS.svn: |
| 85 | return SVN(spec) |
| 86 | else: |
| 87 | return None |
| 88 | |
| 89 | #### SOURCE PATHS #### |
| 90 | |
| 91 | def llvm_source_path (): |
| 92 | if build_type() == BuildType.Xcode: |
| 93 | return os.path.join(lldb_source_path(), "llvm") |
| 94 | |
| 95 | def clang_source_path (): |
| 96 | if build_type() == BuildType.Xcode: |
| 97 | return os.path.join(llvm_source_path(), "tools", "clang") |
| 98 | |
| 99 | def ninja_source_path (): |
| 100 | if build_type() == BuildType.Xcode: |
| 101 | return os.path.join(lldb_source_path(), "ninja") |
| 102 | |
| 103 | #### BUILD PATHS #### |
| 104 | |
| 105 | def packages (): |
| 106 | return ["llvm"] |
| 107 | |
| 108 | def package_build_dir_name (package): |
| 109 | return package + "-" + architecture() |
| 110 | |
| 111 | def expected_package_build_path_for (package): |
| 112 | if build_type() == BuildType.Xcode: |
| 113 | if package != "llvm": |
| 114 | raise("On Xcode build, we only support the llvm package: requested {}".format(package)) |
| 115 | return package_build_path() |
| 116 | return os.path.join(expected_package_build_path(), package_build_dir_name(package)) |
| 117 | |
| 118 | def expected_package_build_paths (): |
| 119 | return [expected_package_build_path_for(package) for package in packages()] |
| 120 | |
| 121 | def library_path (build_path): |
| 122 | return build_path + "/lib" |
| 123 | |
| 124 | def library_paths (): |
| 125 | if build_type() == BuildType.Xcode: |
| 126 | package_build_paths = [package_build_path()] |
| 127 | else: |
| 128 | package_build_paths = expected_package_build_paths() |
| 129 | return [library_path(build_path) for build_path in package_build_paths] |
| 130 | |
| 131 | def package_build_path (): |
| 132 | return os.path.join( |
| 133 | llvm_build_dirtree(), |
| 134 | os.environ["LLVM_CONFIGURATION"], |
| 135 | os.environ["CURRENT_ARCH"]) |