blob: 2924c0ec85771552e6f7f41bea12196b781e0361 [file] [log] [blame]
Todd Fiala2c0802c2016-01-28 07:36:44 +00001import os
2import subprocess
3
4#### UTILITIES ####
5
Kate Stoneb9c1b512016-09-06 20:57:50 +00006
7def enum(*sequential, **named):
Todd Fiala2c0802c2016-01-28 07:36:44 +00008 enums = dict(zip(sequential, range(len(sequential))), **named)
9 return type('Enum', (), enums)
10
11#### SETTINGS ####
12
13#### INTERFACE TO THE XCODEPROJ ####
14
Kate Stoneb9c1b512016-09-06 20:57:50 +000015
16def lldb_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +000017 return os.environ.get('SRCROOT')
18
Kate Stoneb9c1b512016-09-06 20:57:50 +000019
20def expected_llvm_build_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +000021 if build_type() == BuildType.Xcode:
22 return package_build_path()
23 else:
Kate Stoneb9c1b512016-09-06 20:57:50 +000024 return os.path.join(
25 os.environ.get('LLDB_PATH_TO_LLVM_BUILD'),
26 package_build_dir_name("llvm"))
Todd Fiala2c0802c2016-01-28 07:36:44 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028
29def archives_txt():
Todd Fiala2c0802c2016-01-28 07:36:44 +000030 return os.path.join(expected_package_build_path(), "archives.txt")
31
Kate Stoneb9c1b512016-09-06 20:57:50 +000032
33def expected_package_build_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +000034 return os.path.abspath(os.path.join(expected_llvm_build_path(), ".."))
35
Enrico Granata5edef422016-09-22 17:59:58 +000036def is_host_build():
Enrico Granata9a4a6b22016-09-22 17:47:33 +000037 rc_project_name = os.environ.get('RC_ProjectName')
38 if rc_project_name:
Enrico Granata5edef422016-09-22 17:59:58 +000039 if rc_project_name == 'lldb_host': return True
40 return False
41
42def rc_release_target():
43 return os.environ.get('RC_RELEASE', '')
44
45def architecture():
46 if is_host_build(): return 'macosx'
Todd Fiala2c0802c2016-01-28 07:36:44 +000047 platform_name = os.environ.get('RC_PLATFORM_NAME')
48 if not platform_name:
49 platform_name = os.environ.get('PLATFORM_NAME')
50 platform_arch = os.environ.get('ARCHS').split()[-1]
51 return platform_name + "-" + platform_arch
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053
54def lldb_configuration():
Todd Fiala2c0802c2016-01-28 07:36:44 +000055 return os.environ.get('CONFIGURATION')
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057
58def llvm_configuration():
Todd Fiala2c0802c2016-01-28 07:36:44 +000059 return os.environ.get('LLVM_CONFIGURATION')
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061
62def llvm_build_dirtree():
Todd Fiala2c0802c2016-01-28 07:36:44 +000063 return os.environ.get('LLVM_BUILD_DIRTREE')
64
65# Edit the code below when adding build styles.
66
67BuildType = enum('Xcode') # (Debug,DebugClang,Release)
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069
70def build_type():
Todd Fiala2c0802c2016-01-28 07:36:44 +000071 return BuildType.Xcode
72
73#### VCS UTILITIES ####
74
75VCS = enum('git',
76 'svn')
77
Kate Stoneb9c1b512016-09-06 20:57:50 +000078
Todd Fiala2c0802c2016-01-28 07:36:44 +000079def run_in_directory(args, path):
80 return subprocess.check_output(args, cwd=path)
81
Kate Stoneb9c1b512016-09-06 20:57:50 +000082
Todd Fiala2c0802c2016-01-28 07:36:44 +000083class Git:
Kate Stoneb9c1b512016-09-06 20:57:50 +000084
85 def __init__(self, spec):
Todd Fiala2c0802c2016-01-28 07:36:44 +000086 self.spec = spec
Kate Stoneb9c1b512016-09-06 20:57:50 +000087
88 def status(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +000089 return run_in_directory(["git", "branch", "-v"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +000090
91 def diff(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +000092 return run_in_directory(["git", "diff"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +000093
94 def check_out(self):
95 run_in_directory(["git",
96 "clone",
97 "--depth=1",
98 self.spec['url'],
99 self.spec['root']],
100 lldb_source_path())
Todd Fiala2c0802c2016-01-28 07:36:44 +0000101 run_in_directory(["git", "fetch", "--all"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 run_in_directory(["git", "checkout", self.spec[
103 'ref']], self.spec['root'])
104
Todd Fiala2c0802c2016-01-28 07:36:44 +0000105
106class SVN:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107
108 def __init__(self, spec):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000109 self.spec = spec
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110
111 def status(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000112 return run_in_directory(["svn", "info"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113
114 def diff(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000115 return run_in_directory(["svn", "diff"], self.spec['root'])
116 # TODO implement check_out
117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118
119def vcs(spec):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000120 if spec['vcs'] == VCS.git:
121 return Git(spec)
122 elif spec['vcs'] == VCS.svn:
123 return SVN(spec)
124 else:
125 return None
126
127#### SOURCE PATHS ####
128
Kate Stoneb9c1b512016-09-06 20:57:50 +0000129
130def llvm_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000131 if build_type() == BuildType.Xcode:
132 return os.path.join(lldb_source_path(), "llvm")
133
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134
135def clang_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000136 if build_type() == BuildType.Xcode:
137 return os.path.join(llvm_source_path(), "tools", "clang")
138
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139
140def ninja_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000141 if build_type() == BuildType.Xcode:
142 return os.path.join(lldb_source_path(), "ninja")
143
144#### BUILD PATHS ####
145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146
147def packages():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000148 return ["llvm"]
149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150
151def package_build_dir_name(package):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000152 return package + "-" + architecture()
153
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154
155def expected_package_build_path_for(package):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000156 if build_type() == BuildType.Xcode:
157 if package != "llvm":
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158 raise "On Xcode build, we only support the llvm package: requested {}"
Todd Fiala2c0802c2016-01-28 07:36:44 +0000159 return package_build_path()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160 return os.path.join(
161 expected_package_build_path(),
162 package_build_dir_name(package))
Todd Fiala2c0802c2016-01-28 07:36:44 +0000163
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164
165def expected_package_build_paths():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000166 return [expected_package_build_path_for(package) for package in packages()]
167
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168
169def library_path(build_path):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000170 return build_path + "/lib"
171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172
173def library_paths():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000174 if build_type() == BuildType.Xcode:
175 package_build_paths = [package_build_path()]
176 else:
177 package_build_paths = expected_package_build_paths()
178 return [library_path(build_path) for build_path in package_build_paths]
179
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180
181def package_build_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000182 return os.path.join(
183 llvm_build_dirtree(),
184 os.environ["LLVM_CONFIGURATION"],
185 os.environ["CURRENT_ARCH"])