Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 1 | import os |
| 2 | import subprocess |
| 3 | |
| 4 | #### UTILITIES #### |
| 5 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6 | |
| 7 | def enum(*sequential, **named): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 8 | enums = dict(zip(sequential, range(len(sequential))), **named) |
| 9 | return type('Enum', (), enums) |
| 10 | |
| 11 | #### SETTINGS #### |
| 12 | |
| 13 | #### INTERFACE TO THE XCODEPROJ #### |
| 14 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 15 | |
| 16 | def lldb_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 17 | return os.environ.get('SRCROOT') |
| 18 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | |
| 20 | def expected_llvm_build_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 21 | if build_type() == BuildType.Xcode: |
| 22 | return package_build_path() |
| 23 | else: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | return os.path.join( |
| 25 | os.environ.get('LLDB_PATH_TO_LLVM_BUILD'), |
| 26 | package_build_dir_name("llvm")) |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | |
| 29 | def archives_txt(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 30 | return os.path.join(expected_package_build_path(), "archives.txt") |
| 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | |
| 33 | def expected_package_build_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 34 | return os.path.abspath(os.path.join(expected_llvm_build_path(), "..")) |
| 35 | |
Enrico Granata | 5edef42 | 2016-09-22 17:59:58 +0000 | [diff] [blame] | 36 | def is_host_build(): |
Enrico Granata | 9a4a6b2 | 2016-09-22 17:47:33 +0000 | [diff] [blame] | 37 | rc_project_name = os.environ.get('RC_ProjectName') |
| 38 | if rc_project_name: |
Enrico Granata | 5edef42 | 2016-09-22 17:59:58 +0000 | [diff] [blame] | 39 | if rc_project_name == 'lldb_host': return True |
| 40 | return False |
| 41 | |
| 42 | def rc_release_target(): |
| 43 | return os.environ.get('RC_RELEASE', '') |
| 44 | |
Enrico Granata | f880250 | 2016-09-23 22:30:08 +0000 | [diff] [blame] | 45 | def rc_platform_name(): |
| 46 | return os.environ.get('RC_PLATFORM_NAME', 'macOS') |
| 47 | |
Enrico Granata | 5edef42 | 2016-09-22 17:59:58 +0000 | [diff] [blame] | 48 | def architecture(): |
| 49 | if is_host_build(): return 'macosx' |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 50 | platform_name = os.environ.get('RC_PLATFORM_NAME') |
| 51 | if not platform_name: |
| 52 | platform_name = os.environ.get('PLATFORM_NAME') |
| 53 | platform_arch = os.environ.get('ARCHS').split()[-1] |
| 54 | return platform_name + "-" + platform_arch |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | |
| 57 | def lldb_configuration(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 58 | return os.environ.get('CONFIGURATION') |
| 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | |
| 61 | def llvm_configuration(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 62 | return os.environ.get('LLVM_CONFIGURATION') |
| 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | |
| 65 | def llvm_build_dirtree(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 66 | return os.environ.get('LLVM_BUILD_DIRTREE') |
| 67 | |
| 68 | # Edit the code below when adding build styles. |
| 69 | |
| 70 | BuildType = enum('Xcode') # (Debug,DebugClang,Release) |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | |
| 73 | def build_type(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 74 | return BuildType.Xcode |
| 75 | |
| 76 | #### VCS UTILITIES #### |
| 77 | |
| 78 | VCS = enum('git', |
| 79 | 'svn') |
| 80 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 82 | def run_in_directory(args, path): |
| 83 | return subprocess.check_output(args, cwd=path) |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 86 | class Git: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | |
| 88 | def __init__(self, spec): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 89 | self.spec = spec |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | |
| 91 | def status(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 92 | return run_in_directory(["git", "branch", "-v"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | |
| 94 | def diff(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 95 | return run_in_directory(["git", "diff"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | |
| 97 | def check_out(self): |
| 98 | run_in_directory(["git", |
| 99 | "clone", |
| 100 | "--depth=1", |
| 101 | self.spec['url'], |
| 102 | self.spec['root']], |
| 103 | lldb_source_path()) |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 104 | run_in_directory(["git", "fetch", "--all"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | run_in_directory(["git", "checkout", self.spec[ |
| 106 | 'ref']], self.spec['root']) |
| 107 | |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 108 | |
| 109 | class SVN: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | |
| 111 | def __init__(self, spec): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 112 | self.spec = spec |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | |
| 114 | def status(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 115 | return run_in_directory(["svn", "info"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | |
| 117 | def diff(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 118 | return run_in_directory(["svn", "diff"], self.spec['root']) |
| 119 | # TODO implement check_out |
| 120 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 121 | |
| 122 | def vcs(spec): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 123 | if spec['vcs'] == VCS.git: |
| 124 | return Git(spec) |
| 125 | elif spec['vcs'] == VCS.svn: |
| 126 | return SVN(spec) |
| 127 | else: |
| 128 | return None |
| 129 | |
| 130 | #### SOURCE PATHS #### |
| 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | |
| 133 | def llvm_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 134 | if build_type() == BuildType.Xcode: |
| 135 | return os.path.join(lldb_source_path(), "llvm") |
| 136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | |
| 138 | def clang_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 139 | if build_type() == BuildType.Xcode: |
| 140 | return os.path.join(llvm_source_path(), "tools", "clang") |
| 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | |
| 143 | def ninja_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 144 | if build_type() == BuildType.Xcode: |
| 145 | return os.path.join(lldb_source_path(), "ninja") |
| 146 | |
| 147 | #### BUILD PATHS #### |
| 148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | |
| 150 | def packages(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 151 | return ["llvm"] |
| 152 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | |
| 154 | def package_build_dir_name(package): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 155 | return package + "-" + architecture() |
| 156 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | |
| 158 | def expected_package_build_path_for(package): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 159 | if build_type() == BuildType.Xcode: |
| 160 | if package != "llvm": |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | raise "On Xcode build, we only support the llvm package: requested {}" |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 162 | return package_build_path() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | return os.path.join( |
| 164 | expected_package_build_path(), |
| 165 | package_build_dir_name(package)) |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 166 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 167 | |
| 168 | def expected_package_build_paths(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 169 | return [expected_package_build_path_for(package) for package in packages()] |
| 170 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | |
| 172 | def library_path(build_path): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 173 | return build_path + "/lib" |
| 174 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | |
| 176 | def library_paths(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 177 | if build_type() == BuildType.Xcode: |
| 178 | package_build_paths = [package_build_path()] |
| 179 | else: |
| 180 | package_build_paths = expected_package_build_paths() |
| 181 | return [library_path(build_path) for build_path in package_build_paths] |
| 182 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | |
| 184 | def package_build_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 185 | return os.path.join( |
| 186 | llvm_build_dirtree(), |
| 187 | os.environ["LLVM_CONFIGURATION"], |
| 188 | os.environ["CURRENT_ARCH"]) |