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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | |
| 37 | def architecture(): |
Enrico Granata | 9a4a6b2 | 2016-09-22 17:47:33 +0000 | [diff] [blame^] | 38 | rc_project_name = os.environ.get('RC_ProjectName') |
| 39 | if rc_project_name: |
| 40 | if rc_project_name == 'lldb_host': return 'macosx' |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 41 | platform_name = os.environ.get('RC_PLATFORM_NAME') |
| 42 | if not platform_name: |
| 43 | platform_name = os.environ.get('PLATFORM_NAME') |
| 44 | platform_arch = os.environ.get('ARCHS').split()[-1] |
| 45 | return platform_name + "-" + platform_arch |
| 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | |
| 48 | def lldb_configuration(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 49 | return os.environ.get('CONFIGURATION') |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | |
| 52 | def llvm_configuration(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 53 | return os.environ.get('LLVM_CONFIGURATION') |
| 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | |
| 56 | def llvm_build_dirtree(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 57 | return os.environ.get('LLVM_BUILD_DIRTREE') |
| 58 | |
| 59 | # Edit the code below when adding build styles. |
| 60 | |
| 61 | BuildType = enum('Xcode') # (Debug,DebugClang,Release) |
| 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | |
| 64 | def build_type(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 65 | return BuildType.Xcode |
| 66 | |
| 67 | #### VCS UTILITIES #### |
| 68 | |
| 69 | VCS = enum('git', |
| 70 | 'svn') |
| 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 73 | def run_in_directory(args, path): |
| 74 | return subprocess.check_output(args, cwd=path) |
| 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 77 | class Git: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | |
| 79 | def __init__(self, spec): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 80 | self.spec = spec |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | |
| 82 | def status(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 83 | return run_in_directory(["git", "branch", "-v"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | |
| 85 | def diff(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 86 | return run_in_directory(["git", "diff"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | |
| 88 | def check_out(self): |
| 89 | run_in_directory(["git", |
| 90 | "clone", |
| 91 | "--depth=1", |
| 92 | self.spec['url'], |
| 93 | self.spec['root']], |
| 94 | lldb_source_path()) |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 95 | run_in_directory(["git", "fetch", "--all"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | run_in_directory(["git", "checkout", self.spec[ |
| 97 | 'ref']], self.spec['root']) |
| 98 | |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 99 | |
| 100 | class SVN: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | |
| 102 | def __init__(self, spec): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 103 | self.spec = spec |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | |
| 105 | def status(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 106 | return run_in_directory(["svn", "info"], self.spec['root']) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | |
| 108 | def diff(self): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 109 | return run_in_directory(["svn", "diff"], self.spec['root']) |
| 110 | # TODO implement check_out |
| 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | |
| 113 | def vcs(spec): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 114 | if spec['vcs'] == VCS.git: |
| 115 | return Git(spec) |
| 116 | elif spec['vcs'] == VCS.svn: |
| 117 | return SVN(spec) |
| 118 | else: |
| 119 | return None |
| 120 | |
| 121 | #### SOURCE PATHS #### |
| 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | |
| 124 | def llvm_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 125 | if build_type() == BuildType.Xcode: |
| 126 | return os.path.join(lldb_source_path(), "llvm") |
| 127 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | |
| 129 | def clang_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 130 | if build_type() == BuildType.Xcode: |
| 131 | return os.path.join(llvm_source_path(), "tools", "clang") |
| 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | |
| 134 | def ninja_source_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 135 | if build_type() == BuildType.Xcode: |
| 136 | return os.path.join(lldb_source_path(), "ninja") |
| 137 | |
| 138 | #### BUILD PATHS #### |
| 139 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 140 | |
| 141 | def packages(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 142 | return ["llvm"] |
| 143 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | |
| 145 | def package_build_dir_name(package): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 146 | return package + "-" + architecture() |
| 147 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | |
| 149 | def expected_package_build_path_for(package): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 150 | if build_type() == BuildType.Xcode: |
| 151 | if package != "llvm": |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | raise "On Xcode build, we only support the llvm package: requested {}" |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 153 | return package_build_path() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | return os.path.join( |
| 155 | expected_package_build_path(), |
| 156 | package_build_dir_name(package)) |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | |
| 159 | def expected_package_build_paths(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 160 | return [expected_package_build_path_for(package) for package in packages()] |
| 161 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 162 | |
| 163 | def library_path(build_path): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 164 | return build_path + "/lib" |
| 165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | |
| 167 | def library_paths(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 168 | if build_type() == BuildType.Xcode: |
| 169 | package_build_paths = [package_build_path()] |
| 170 | else: |
| 171 | package_build_paths = expected_package_build_paths() |
| 172 | return [library_path(build_path) for build_path in package_build_paths] |
| 173 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | |
| 175 | def package_build_path(): |
Todd Fiala | 2c0802c | 2016-01-28 07:36:44 +0000 | [diff] [blame] | 176 | return os.path.join( |
| 177 | llvm_build_dirtree(), |
| 178 | os.environ["LLVM_CONFIGURATION"], |
| 179 | os.environ["CURRENT_ARCH"]) |