From 7be5e7df8c7cc25f60fc469a1f4f299966ca1db6 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Fri, 12 Mar 2021 18:05:00 +0000 Subject: [PATCH] populate-depot: Take source files from separate directories This avoids the depot being a mixture of source files and generated files. Signed-off-by: Simon McVittie <smcv@collabora.com> (originally steamrt/steamlinuxruntime@f36fbcda) --- pressure-vessel/populate-depot.py | 45 ++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/pressure-vessel/populate-depot.py b/pressure-vessel/populate-depot.py index 885d02472..507d473df 100755 --- a/pressure-vessel/populate-depot.py +++ b/pressure-vessel/populate-depot.py @@ -52,12 +52,16 @@ from debian.deb822 import ( Sources, ) + +HERE = os.path.dirname(os.path.abspath(__file__)) + + # git remote add --no-tags python-vdf https://github.com/ValvePython/vdf # Update with: # git subtree merge -P subprojects/python-vdf python-vdf/master sys.path[:0] = [ os.path.join( - os.path.dirname(__file__), + HERE, 'subprojects', 'python-vdf' ), @@ -330,6 +334,7 @@ class Main: include_sdk: bool = False, pressure_vessel: str = 'scout', runtimes: Sequence[str] = (), + source_dir: str = HERE, ssh_host: str = '', ssh_path: str = '', suite: str = '', @@ -392,6 +397,7 @@ class Main: self.images_uri = images_uri self.pressure_vessel = pressure_vessel self.runtimes = [] # type: List[Runtime] + self.source_dir = source_dir self.ssh_host = ssh_host self.ssh_path = ssh_path self.toolmanifest = toolmanifest @@ -438,9 +444,40 @@ class Main: ssh_path=self.ssh_path, ) + def merge_dir_into_depot( + self, + source_root: str, + ): + for (dirpath, dirnames, filenames) in os.walk(source_root): + relative_path = os.path.relpath(dirpath, source_root) + + for member in dirnames: + os.makedirs( + os.path.join(self.depot, relative_path, member), + exist_ok=True, + ) + + for member in filenames: + source = os.path.join(dirpath, member) + merged = os.path.join(self.depot, relative_path, member) + + with suppress(FileNotFoundError): + os.unlink(merged) + + os.makedirs(os.path.dirname(merged), exist_ok=True) + shutil.copy(source, merged) + def run(self) -> None: pv_version = ComponentVersion('pressure-vessel') + self.merge_dir_into_depot(os.path.join(self.source_dir, 'common')) + + for runtime in self.runtimes: + root = os.path.join(self.source_dir, runtime.name) + + if os.path.exists(root): + self.merge_dir_into_depot(root) + for runtime in self.runtimes: if runtime.name == self.pressure_vessel: logger.info( @@ -1046,6 +1083,12 @@ def main() -> None: '--include-sdk', default=False, action='store_true', help='Include a corresponding SDK', ) + parser.add_argument( + '--source-dir', default=HERE, + help=( + 'Source directory for files to include in the depot' + ) + ) parser.add_argument( '--toolmanifest', default=False, action='store_true', help='Generate toolmanifest.vdf', -- GitLab