2021-10-04 23:59:58 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-10-24 17:56:22 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Copies current subproject git repository to create a cache
|
|
|
|
"""
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
import argparse
|
2022-05-27 13:37:41 +00:00
|
|
|
import subprocess
|
2020-10-24 17:56:22 +00:00
|
|
|
|
|
|
|
PARSER = argparse.ArgumentParser()
|
|
|
|
PARSER.add_argument('subprojects_dir')
|
|
|
|
PARSER.add_argument('--build', action="store_true", default=False)
|
2023-08-29 06:10:49 +00:00
|
|
|
PARSER.add_argument('--cache-dir', default="/subprojects")
|
2020-10-24 17:56:22 +00:00
|
|
|
|
2021-10-04 23:59:58 +00:00
|
|
|
|
2020-10-24 17:56:22 +00:00
|
|
|
def create_cache_in_image(options):
|
2023-08-29 06:10:49 +00:00
|
|
|
os.makedirs(options.cache_dir, exist_ok=True)
|
2020-10-24 17:56:22 +00:00
|
|
|
print("Creating cache from %s" % options.subprojects_dir)
|
|
|
|
for project_name in os.listdir(options.subprojects_dir):
|
|
|
|
project_path = os.path.join(options.subprojects_dir, project_name)
|
|
|
|
|
|
|
|
if project_name != "packagecache" and not os.path.exists(os.path.join(project_path, '.git')):
|
|
|
|
continue
|
|
|
|
|
2023-08-29 06:10:49 +00:00
|
|
|
if os.path.exists(os.path.join(options.cache_dir, project_name)):
|
2021-12-02 22:57:09 +00:00
|
|
|
continue
|
|
|
|
|
2020-10-24 17:56:22 +00:00
|
|
|
print("Copying %s" % project_name)
|
2023-08-29 06:10:49 +00:00
|
|
|
shutil.copytree(project_path, os.path.join(options.cache_dir, project_name))
|
2020-10-24 17:56:22 +00:00
|
|
|
|
2021-12-02 22:57:09 +00:00
|
|
|
media_path = os.path.join(options.subprojects_dir, '..', '.git',
|
|
|
|
'modules', 'subprojects', 'gst-integration-testsuites', 'medias')
|
2023-08-29 06:10:49 +00:00
|
|
|
if os.path.exists(os.path.join(options.cache_dir, 'medias.git')):
|
2021-12-02 22:57:09 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if os.path.exists(media_path):
|
|
|
|
print("Creating media cache")
|
2023-08-29 06:10:49 +00:00
|
|
|
shutil.copytree(media_path, os.path.join(options.cache_dir, 'medias.git'))
|
2021-12-02 22:57:09 +00:00
|
|
|
else:
|
|
|
|
print("Did not find medias in %s" % media_path)
|
|
|
|
|
2020-10-24 17:56:22 +00:00
|
|
|
|
|
|
|
def copy_cache(options):
|
2023-11-09 12:46:31 +00:00
|
|
|
for path in [options.cache_dir]:
|
2020-10-24 17:56:22 +00:00
|
|
|
if not os.path.exists(path):
|
|
|
|
print("%s doesn't exist." % path)
|
|
|
|
continue
|
|
|
|
|
|
|
|
for project_name in os.listdir(path):
|
|
|
|
project_path = os.path.join(options.subprojects_dir, project_name)
|
|
|
|
cache_dir = os.path.join(path, project_name)
|
2021-12-02 22:57:09 +00:00
|
|
|
|
|
|
|
if project_name == 'medias.git':
|
|
|
|
project_path = os.path.join(options.subprojects_dir, '..', '.git', 'modules',
|
|
|
|
'subprojects', 'gst-integration-testsuites')
|
|
|
|
os.makedirs(project_path, exist_ok=True)
|
|
|
|
project_path = os.path.join(project_path, 'medias')
|
|
|
|
|
2020-10-24 17:56:22 +00:00
|
|
|
if os.path.exists(project_path):
|
|
|
|
print("- Ignoring %s" % cache_dir)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not os.path.isdir(cache_dir):
|
|
|
|
print("- Ignoring %s" % cache_dir)
|
|
|
|
continue
|
|
|
|
|
2021-12-02 22:57:09 +00:00
|
|
|
print("Copying from %s -> %s" % (cache_dir, project_path))
|
2020-10-24 17:56:22 +00:00
|
|
|
shutil.copytree(cache_dir, project_path)
|
2024-11-04 04:52:11 +00:00
|
|
|
|
|
|
|
# workaround `meson subprojects download` only providing a shallow
|
|
|
|
# clone.
|
|
|
|
# If we need to change refs, then the git repo will only ever be
|
|
|
|
# able to reference the originally cloned ref.
|
|
|
|
git_path = os.path.join(project_path, '.git')
|
|
|
|
if os.path.exists(git_path):
|
|
|
|
subprocess.check_call(['git', '-C', git_path, 'remote', 'set-branches', 'origin', '*'])
|
|
|
|
|
2022-05-27 13:37:41 +00:00
|
|
|
subprocess.check_call(['meson', 'subprojects', 'update', '--reset'])
|
2020-10-24 17:56:22 +00:00
|
|
|
|
|
|
|
|
2022-09-16 12:28:49 +00:00
|
|
|
def upgrade_meson():
|
|
|
|
# MESON_COMMIT variable can be set when creating a pipeline to test meson pre releases
|
|
|
|
meson_commit = os.environ.get('MESON_COMMIT')
|
|
|
|
if meson_commit:
|
|
|
|
url = f'git+https://github.com/mesonbuild/meson.git@{meson_commit}'
|
|
|
|
subprocess.check_call(['pip3', 'install', '--upgrade', url])
|
|
|
|
|
|
|
|
|
2020-10-24 17:56:22 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
options = PARSER.parse_args()
|
|
|
|
|
|
|
|
if options.build:
|
|
|
|
create_cache_in_image(options)
|
|
|
|
else:
|
2022-09-16 12:28:49 +00:00
|
|
|
upgrade_meson()
|
2021-10-04 23:59:58 +00:00
|
|
|
copy_cache(options)
|