blob: bfe8951461c0ebb14d11d56626f8a74f77cf9034 [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
Kate Stoneb9c1b512016-09-06 20:57:50 +000036
37def architecture():
Enrico Granata9a4a6b22016-09-22 17:47:33 +000038 rc_project_name = os.environ.get('RC_ProjectName')
39 if rc_project_name:
40 if rc_project_name == 'lldb_host': return 'macosx'
Todd Fiala2c0802c2016-01-28 07:36:44 +000041 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 Stoneb9c1b512016-09-06 20:57:50 +000047
48def lldb_configuration():
Todd Fiala2c0802c2016-01-28 07:36:44 +000049 return os.environ.get('CONFIGURATION')
50
Kate Stoneb9c1b512016-09-06 20:57:50 +000051
52def llvm_configuration():
Todd Fiala2c0802c2016-01-28 07:36:44 +000053 return os.environ.get('LLVM_CONFIGURATION')
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055
56def llvm_build_dirtree():
Todd Fiala2c0802c2016-01-28 07:36:44 +000057 return os.environ.get('LLVM_BUILD_DIRTREE')
58
59# Edit the code below when adding build styles.
60
61BuildType = enum('Xcode') # (Debug,DebugClang,Release)
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063
64def build_type():
Todd Fiala2c0802c2016-01-28 07:36:44 +000065 return BuildType.Xcode
66
67#### VCS UTILITIES ####
68
69VCS = enum('git',
70 'svn')
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072
Todd Fiala2c0802c2016-01-28 07:36:44 +000073def run_in_directory(args, path):
74 return subprocess.check_output(args, cwd=path)
75
Kate Stoneb9c1b512016-09-06 20:57:50 +000076
Todd Fiala2c0802c2016-01-28 07:36:44 +000077class Git:
Kate Stoneb9c1b512016-09-06 20:57:50 +000078
79 def __init__(self, spec):
Todd Fiala2c0802c2016-01-28 07:36:44 +000080 self.spec = spec
Kate Stoneb9c1b512016-09-06 20:57:50 +000081
82 def status(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +000083 return run_in_directory(["git", "branch", "-v"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +000084
85 def diff(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +000086 return run_in_directory(["git", "diff"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +000087
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 Fiala2c0802c2016-01-28 07:36:44 +000095 run_in_directory(["git", "fetch", "--all"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 run_in_directory(["git", "checkout", self.spec[
97 'ref']], self.spec['root'])
98
Todd Fiala2c0802c2016-01-28 07:36:44 +000099
100class SVN:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101
102 def __init__(self, spec):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000103 self.spec = spec
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104
105 def status(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000106 return run_in_directory(["svn", "info"], self.spec['root'])
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107
108 def diff(self):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000109 return run_in_directory(["svn", "diff"], self.spec['root'])
110 # TODO implement check_out
111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112
113def vcs(spec):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000114 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 Stoneb9c1b512016-09-06 20:57:50 +0000123
124def llvm_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000125 if build_type() == BuildType.Xcode:
126 return os.path.join(lldb_source_path(), "llvm")
127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128
129def clang_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000130 if build_type() == BuildType.Xcode:
131 return os.path.join(llvm_source_path(), "tools", "clang")
132
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133
134def ninja_source_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000135 if build_type() == BuildType.Xcode:
136 return os.path.join(lldb_source_path(), "ninja")
137
138#### BUILD PATHS ####
139
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140
141def packages():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000142 return ["llvm"]
143
Kate Stoneb9c1b512016-09-06 20:57:50 +0000144
145def package_build_dir_name(package):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000146 return package + "-" + architecture()
147
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148
149def expected_package_build_path_for(package):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000150 if build_type() == BuildType.Xcode:
151 if package != "llvm":
Kate Stoneb9c1b512016-09-06 20:57:50 +0000152 raise "On Xcode build, we only support the llvm package: requested {}"
Todd Fiala2c0802c2016-01-28 07:36:44 +0000153 return package_build_path()
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154 return os.path.join(
155 expected_package_build_path(),
156 package_build_dir_name(package))
Todd Fiala2c0802c2016-01-28 07:36:44 +0000157
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158
159def expected_package_build_paths():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000160 return [expected_package_build_path_for(package) for package in packages()]
161
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162
163def library_path(build_path):
Todd Fiala2c0802c2016-01-28 07:36:44 +0000164 return build_path + "/lib"
165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166
167def library_paths():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000168 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 Stoneb9c1b512016-09-06 20:57:50 +0000174
175def package_build_path():
Todd Fiala2c0802c2016-01-28 07:36:44 +0000176 return os.path.join(
177 llvm_build_dirtree(),
178 os.environ["LLVM_CONFIGURATION"],
179 os.environ["CURRENT_ARCH"])