Skip to content

Commit

Permalink
ebuild: Include crate tarball filename in default SRC_URI
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny committed Nov 29, 2023
1 parent 1b2ff77 commit 4348ece
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pycargoebuild/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def repack_crates(tar_out: tarfile.TarFile,
crates,
distdir=args.distdir,
crate_license=not args.no_license,
crate_tarball=args.crate_tarball,
crate_tarball=crate_tarball if args.crate_tarball else None,
license_overrides=config_toml.get("license-overrides", {}),
)
logging.warning(
Expand All @@ -320,7 +320,7 @@ def repack_crates(tar_out: tarfile.TarFile,
crates,
distdir=args.distdir,
crate_license=not args.no_license,
crate_tarball=args.crate_tarball,
crate_tarball=crate_tarball if args.crate_tarball else None,
license_overrides=config_toml.get("license-overrides", {}),
)

Expand Down
12 changes: 7 additions & 5 deletions pycargoebuild/ebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
DESCRIPTION="{description}"
HOMEPAGE="{homepage}"
SRC_URI="
\t${{CARGO_CRATE_URIS}}
\t${{CARGO_CRATE_URIS}}{opt_crate_tarball}
"
LICENSE="{pkg_license}"
Expand Down Expand Up @@ -186,7 +186,7 @@ def get_ebuild(pkg_meta: PackageMetadata,
distdir: Path,
*,
crate_license: bool = True,
crate_tarball: bool = False,
crate_tarball: typing.Optional[Path] = None,
license_overrides: typing.Dict[str, str] = {},
) -> str:
"""
Expand All @@ -199,11 +199,13 @@ def get_ebuild(pkg_meta: PackageMetadata,
template += EBUILD_TEMPLATE_END

return template.format(
crates=get_CRATES(crates if not crate_tarball else ()),
crates=get_CRATES(crates if crate_tarball is None else ()),
crate_licenses=get_crate_LICENSE(crates, distdir, license_overrides),
description=bash_dquote_escape(collapse_whitespace(
pkg_meta.description or "")),
homepage=url_dquote_escape(pkg_meta.homepage or ""),
opt_crate_tarball=f"\n\t{crate_tarball.name}"
if crate_tarball is not None else "",
opt_git_crates=get_GIT_CRATES(crates, distdir),
pkg_license=get_package_LICENSE(pkg_meta.license),
prog_version=__version__,
Expand Down Expand Up @@ -258,15 +260,15 @@ def update_ebuild(ebuild: str,
distdir: Path,
*,
crate_license: bool = True,
crate_tarball: bool = False,
crate_tarball: typing.Optional[Path] = None,
license_overrides: typing.Dict[str, str] = {},
) -> str:
"""
Update the CRATES, GIT_CRATES and LICENSE in an existing ebuild
"""

crates_repl = CountingSubst(
partial(get_CRATES, crates if not crate_tarball else ()))
partial(get_CRATES, crates if crate_tarball is None else ()))
git_crates_repl = GitCratesSubst(partial(get_GIT_CRATES, crates, distdir))
crate_license_repl = (
CountingSubst(partial(get_crate_LICENSE, crates, distdir,
Expand Down
7 changes: 5 additions & 2 deletions test/test_ebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def test_get_ebuild_no_crate_license(real_license_mapping, pkg_meta, crate_dir,
def test_get_ebuild_crate_tarball(real_license_mapping, pkg_meta, crate_dir,
crates):
assert get_ebuild(pkg_meta, crates, crate_dir,
crate_tarball=True) == textwrap.dedent(f"""\
crate_tarball=Path("test-0-crates.tar.xz"),
) == textwrap.dedent(f"""\
# Copyright {datetime.date.today().year} Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
Expand All @@ -248,6 +249,7 @@ def test_get_ebuild_crate_tarball(real_license_mapping, pkg_meta, crate_dir,
HOMEPAGE="https://example.com"
SRC_URI="
\t${{CARGO_CRATE_URIS}}
\ttest-0-crates.tar.xz
"
LICENSE="|| ( Apache-2.0 MIT )"
Expand Down Expand Up @@ -412,7 +414,8 @@ def test_update_ebuild_crate_tarball(real_license_mapping, pkg_meta, crate_dir,
""")

assert update_ebuild(old_ebuild, pkg_meta, crates, crate_dir,
crate_tarball=True) == textwrap.dedent("""\
crate_tarball=Path("test-0-crates.tar.xz"),
) == textwrap.dedent("""\
EAPI=8
CRATES="
Expand Down

0 comments on commit 4348ece

Please sign in to comment.