flatpak / flatpak-builder-tools

Various helper tools for flatpak-builder
197 stars 107 forks source link

flatpak-cargo-generator.py fails with https://github.com/lapce/xi-editor #324

Closed sebastian-de closed 2 years ago

sebastian-de commented 2 years ago

flatpak-builder version

1.2.2

Linux distribution and version

Fedora 36

Affected flatpak-builder tool

cargo/flatpak-cargo-generator.py

flatpak-builder tool cli args

No response

Source repository URL

https://github.com/lapce/lapce

Flatpak-builder manifest URL

https://github.com/flathub/dev.lapce.lapce

Description

@gasinvein commit b2d1373 breaks flatpak-cargo-generator.py for the following repository: https://github.com/lapce/xi-editor

INFO:root:Loading packages from https://github.com/lapce/xi-editor
Traceback (most recent call last):
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 362, in <module>
    main()
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 355, in main
    generated_sources = asyncio.run(generate_sources(load_toml(args.cargo_lock),
  File "/usr/lib64/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib64/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 309, in generate_sources
    for pkg in await asyncio.gather(*pkg_coros):
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 262, in get_package_sources
    return await get_git_package_sources(package, git_repos)
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 209, in get_git_package_sources
    git_repo['commits'][commit] = await get_git_repo_packages(repo_url, commit)
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 124, in get_git_repo_packages
    packages.update(await get_cargo_toml_packages(load_toml(toml_path),
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 168, in get_cargo_toml_packages
    await get_dep_packages(pkg_toml, subpkg)
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 150, in get_dep_packages
    dep_toml = load_toml(os.path.join(dep_dir, 'Cargo.toml'))
  File "/home/user/.cache/flatpak-cargo-updater/generator.py", line 89, in load_toml
    with open(tomlfile, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'plugin-lib/Cargo.toml'

Traceback (most recent call last):
  File "/home/user/src/dev.lapce.lapce/update.py", line 175, in <module>
    main()
  File "/home/user/src/dev.lapce.lapce/update.py", line 149, in main
    generated_sources = generate_sources(
  File "/home/user/src/dev.lapce.lapce/update.py", line 105, in generate_sources
    generated_sources = json.loads(run(generator_cmdline))
  File "/home/user/src/dev.lapce.lapce/update.py", line 21, in run
    process = subprocess.run(
  File "/usr/lib64/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/home/user/.cache/flatpak-cargo-updater/generator.py', '-o', '/dev/stdout', '/home/user/.cache/flatpak-cargo-updater/https_github.com_lapce_lapce/Cargo.lock']' returned non-zero exit status 1.

I'll have a look at the change later.

gasinvein commented 2 years ago

Can you please try this patch and tell if it fixes the problem for you?

diff --git a/cargo/flatpak-cargo-generator.py b/cargo/flatpak-cargo-generator.py
index 70ff5e8..cdbc3ff 100755
--- a/cargo/flatpak-cargo-generator.py
+++ b/cargo/flatpak-cargo-generator.py
@@ -162,7 +162,7 @@ async def get_cargo_toml_packages(root_toml, root_dir):
     if 'workspace' in root_toml:
         for member in root_toml['workspace']['members']:
             for subpkg_toml in glob.glob(os.path.join(root_dir, member, 'Cargo.toml')):
-                subpkg = os.path.relpath(os.path.dirname(subpkg_toml), root_dir)
+                subpkg = os.path.dirname(subpkg_toml)
                 logging.debug("Loading workspace member %s in %s", member, root_dir)
                 pkg_toml = load_toml(subpkg_toml)
                 await get_dep_packages(pkg_toml, subpkg)
sebastian-de commented 2 years ago

Yes, this seems to fix it. Thanks!