diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2024-11-13 18:40:51 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2024-11-13 21:17:16 +0530 |
commit | dce9eb937ad0bea55f3e676d4f8068655389d65c (patch) | |
tree | d8088598b189c4d8e0e794f78828698cf125ac1c | |
parent | cb98c369e423b611a1c6f534ad5c49a25b136d81 (diff) |
ci: Don't assume that all runners have the same homedir
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1635>
-rw-r--r-- | cerbero/commands/cache.py | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/cerbero/commands/cache.py b/cerbero/commands/cache.py index 579dc129..7b04f695 100644 --- a/cerbero/commands/cache.py +++ b/cerbero/commands/cache.py @@ -56,20 +56,27 @@ class BaseCache(Command): ] Command.__init__(self, args) - def get_ci_builds_dir(self, config): - if 'CI_BUILDS_DIR' in os.environ: - return os.environ['CI_BUILDS_DIR'].replace('\\', '/') - # For the convenience of people downloading the cache by hand - if config.platform == Platform.DARWIN: - return '/private/tmp/builds' - elif config.platform == Platform.WINDOWS: - return 'C:/Users/Administrator/runner/builds' - return '/builds' - - def get_cache_home_dir(self, config, namespace): - ci_builds_dir = self.get_ci_builds_dir(config) - ci_home_dir = os.environ.get('CERBERO_HOME', 'cerbero-build') - return f'{ci_builds_dir}/{namespace}/cerbero/{ci_home_dir}' + def get_cache_home_dir(self, config): + """ + Use the python virtual env config file in the build-tools dir to fetch + cerbero's home_dir. If it doesn't exist, we will error out loudly, + since it indicates a corrupted cache. + """ + cache_file = os.path.join(config.build_tools_prefix, 'pyvenv.cfg') + with open(cache_file, 'r', encoding='utf-8') as f: + for line in f: + if not line.startswith('command = '): + continue + _, cmd = line.split(' = ') + cache_build_tools_prefix = cmd.split(' -m venv ')[1].strip() + return os.path.dirname(cache_build_tools_prefix) + cache_file = os.path.join(config.build_tools_prefix, 'bin', 'meson') + with open(cache_file, 'r', encoding='utf-8') as f: + line = f.readline() + if line.startswith('#!'): + split_idx = line.rfind('/build-tools/bin/python') + return line[2:split_idx] + raise FatalError('Failed to relocate prefix: could not deduce cache homedir') def get_gnu_sed(self, config): if config.platform == Platform.DARWIN: @@ -164,14 +171,6 @@ class FetchCache(BaseCache): doc = N_('Fetch a cached build from external storage based on cerbero git ' 'revision.') name = 'fetch-cache' - def __init__(self, args=[]): - args.append( - ArgparseArgument( - '--namespace', action='store', type=str, default='gstreamer', help='GitLab namespace to relocate from' - ) - ) - BaseCache.__init__(self, args) - def find_dep(self, deps, sha, allow_old=False): for dep in deps: if dep['commit'] == sha: @@ -252,13 +251,13 @@ class FetchCache(BaseCache): f.truncate(0) pickle.dump(p, f) - def relocate_prefix(self, config, namespace): + def relocate_prefix(self, config): """ We need to relocate pc files that weren't generated by meson and python programs installed with pip because the shebang set by the virtualenv python uses an absolute path. """ - origin = self.get_cache_home_dir(config, namespace) + origin = self.get_cache_home_dir(config) dest = config.home_dir if origin == dest: return @@ -272,7 +271,7 @@ class FetchCache(BaseCache): elif config.platform == Platform.WINDOWS: self.mark_windows_build_tools_dirty(config) - async def fetch_dep(self, config, dep, namespace): + async def fetch_dep(self, config, dep): is_ci = 'CI' in os.environ try: dep_path = os.path.join(config.home_dir, os.path.basename(dep['url'])) @@ -287,10 +286,9 @@ class FetchCache(BaseCache): if is_ci: m.action('Unpack complete, deleting artifact') os.remove(dep_path) - - self.relocate_prefix(config, namespace) except FatalError as e: m.warning('Could not retrieve dependencies for commit %s: %s' % (dep['commit'], e.msg)) + self.relocate_prefix(config) def run(self, config, args): BaseCache.run(self, config, args) @@ -299,7 +297,7 @@ class FetchCache(BaseCache): deps = self.get_deps(config, args) dep = self.find_dep(deps, sha, allow_old=True) if dep: - run_until_complete(self.fetch_dep(config, dep, args.namespace)) + run_until_complete(self.fetch_dep(config, dep)) m.message('All done!') |