Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo: Handle excluded paths in workspaces #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cargo/flatpak-cargo-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that an excluded member of a workspace is just excluded from the list of members of the workspace. If a package is listed as a dependency, it will be needed during compilation so it must be resolved somehow so it doesn't make sense to not try to load it.

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
Expand All @@ -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)
Expand Down