#!/usr/bin/env python3 # # Copyright 2025 James Pace # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. # # This Source Code Form is "Incompatible With Secondary Licenses", as # defined by the Mozilla Public License, v. 2.0. # import argparse import os from pathlib import Path import subprocess def main(): parser = argparse.ArgumentParser() parser.add_argument("--project-dir", type=str, default=None) parser.add_argument("--install-path", type=str) args = parser.parse_args() export_vcs(args.project_dir, args.install_path) def export_vcs(project_directory, install_path): if not project_directory: # Assume we're being called from colcon and need to figure this out ourselves. # When run by colcon cwd is something like /build/package_name cwd = Path(os.getcwd()) project_directory = cwd.parent.parent # Where we're going to save the output. output_file = install_path + "/project_state.repos" # Now call vcs. vcs_command = "vcs export --exact-with-tags {} > {}".format(project_directory, output_file) subprocess.run(vcs_command, shell=True) if __name__ == "__main__": main()