From 534b990eacbfc7bf0eb1463ee267c92e9835c92a Mon Sep 17 00:00:00 2001 From: gasinvein Date: Sun, 9 Oct 2022 19:05:18 +0300 Subject: [PATCH] cargo: Handle excluded paths in workspaces --- cargo/flatpak-cargo-generator.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cargo/flatpak-cargo-generator.py b/cargo/flatpak-cargo-generator.py index c33ec9c7..5164921c 100755 --- a/cargo/flatpak-cargo-generator.py +++ b/cargo/flatpak-cargo-generator.py @@ -133,6 +133,13 @@ async def get_cargo_toml_packages(root_toml, root_dir): assert not os.path.isabs(root_dir) and os.path.isdir(root_dir) assert 'package' in root_toml or 'workspace' in root_toml packages = {} + excluded_paths = None + + def is_excluded(path): + if not excluded_paths: + return False + return any(os.path.commonpath([excluded_path, path]) == excluded_path + for excluded_path in excluded_paths) async def get_dep_packages(entry, toml_dir): assert not os.path.isabs(toml_dir) @@ -146,6 +153,9 @@ async def get_dep_packages(entry, toml_dir): if dep_name in packages: continue dep_dir = os.path.normpath(os.path.join(toml_dir, dep['path'])) + if is_excluded(dep_dir): + logging.warning("Excluded dependency at %s", dep_dir) + return logging.debug("Loading dependency %s from %s", dep_name, dep_dir) dep_toml = load_toml(os.path.join(dep_dir, 'Cargo.toml')) assert dep_toml['package']['name'] == dep_name, toml_dir @@ -160,9 +170,16 @@ async def get_dep_packages(entry, toml_dir): packages[root_toml['package']['name']] = root_dir if 'workspace' in root_toml: - for member in root_toml['workspace'].get('members', []): + workspace = root_toml['workspace'] + if 'exclude' in workspace: + excluded_paths = [os.path.normpath(os.path.join(root_dir, excluded)) + for excluded in workspace['exclude']] + for member in workspace.get('members', []): for subpkg_toml in glob.glob(os.path.join(root_dir, member, 'Cargo.toml')): subpkg = os.path.normpath(os.path.dirname(subpkg_toml)) + if is_excluded(subpkg): + logging.warning("Excluded member at %s", subpkg) + continue logging.debug("Loading workspace member %s in %s", member, root_dir) pkg_toml = load_toml(subpkg_toml) await get_dep_packages(pkg_toml, subpkg)