Fix translation pot files when creating dist tarballs
[platform/upstream/gstreamer.git] / ci / scripts / handle-subprojects-cache.py
1 #!/usr/bin/env python3
2
3 """
4 Copies current subproject git repository to create a cache
5 """
6
7 import shutil
8 import os
9 import sys
10 import argparse
11 import subprocess
12
13 DEST = "/subprojects"
14 PARSER = argparse.ArgumentParser()
15 PARSER.add_argument('subprojects_dir')
16 PARSER.add_argument('--build', action="store_true", default=False)
17
18
19 def create_cache_in_image(options):
20     os.makedirs(DEST, exist_ok=True)
21     print("Creating cache from %s" % options.subprojects_dir)
22     for project_name in os.listdir(options.subprojects_dir):
23         project_path = os.path.join(options.subprojects_dir, project_name)
24
25         if project_name != "packagecache" and not os.path.exists(os.path.join(project_path, '.git')):
26             continue
27
28         if os.path.exists(os.path.join(DEST, project_name)):
29             continue
30
31         print("Copying %s" % project_name)
32         shutil.copytree(project_path, os.path.join(DEST, project_name))
33
34     media_path = os.path.join(options.subprojects_dir, '..', '.git',
35         'modules', 'subprojects', 'gst-integration-testsuites', 'medias')
36     if os.path.exists(os.path.join(DEST, 'medias.git')):
37         return
38
39     if os.path.exists(media_path):
40         print("Creating media cache")
41         shutil.copytree(media_path, os.path.join(DEST, 'medias.git'))
42     else:
43         print("Did not find medias in %s" % media_path)
44
45
46 def copy_cache(options):
47     # FIXME Remove when not needed anymore.
48     for path in [DEST, "/gst-build/subprojects", r"C:\gst-build\subprojects"]:
49         if not os.path.exists(path):
50             print("%s doesn't exist." % path)
51             continue
52
53         for project_name in os.listdir(path):
54             project_path = os.path.join(options.subprojects_dir, project_name)
55             cache_dir = os.path.join(path, project_name)
56
57             if project_name == 'medias.git':
58                 project_path = os.path.join(options.subprojects_dir, '..', '.git', 'modules',
59                     'subprojects', 'gst-integration-testsuites')
60                 os.makedirs(project_path, exist_ok=True)
61                 project_path = os.path.join(project_path, 'medias')
62
63             if os.path.exists(project_path):
64                 print("- Ignoring %s" % cache_dir)
65                 continue
66
67             if not os.path.isdir(cache_dir):
68                 print("- Ignoring %s" % cache_dir)
69                 continue
70
71             print("Copying from %s -> %s" % (cache_dir, project_path))
72             shutil.copytree(cache_dir, project_path)
73     subprocess.check_call(['meson', 'subprojects', 'update', '--reset'])
74
75
76 def upgrade_meson():
77     # MESON_COMMIT variable can be set when creating a pipeline to test meson pre releases
78     meson_commit = os.environ.get('MESON_COMMIT')
79     if meson_commit:
80         url = f'git+https://github.com/mesonbuild/meson.git@{meson_commit}'
81         subprocess.check_call(['pip3', 'install', '--upgrade', url])
82
83
84 if __name__ == "__main__":
85     options = PARSER.parse_args()
86
87     if options.build:
88         create_cache_in_image(options)
89     else:
90         upgrade_meson()
91         copy_cache(options)