From e567ad0c7e8979425c6fb1769336e6da92c20d33 Mon Sep 17 00:00:00 2001 From: Anthony Roussel Date: Mon, 18 Mar 2024 00:36:14 +0100 Subject: [PATCH] Add support for updating buildMavenPackage's mvnHash --- README.md | 1 + nix_update/eval.py | 2 ++ nix_update/update.py | 8 ++++++++ tests/test_maven.py | 27 +++++++++++++++++++++++++++ tests/testpkgs/default.nix | 1 + tests/testpkgs/maven.nix | 16 ++++++++++++++++ 6 files changed, 55 insertions(+) create mode 100644 tests/test_maven.py create mode 100644 tests/testpkgs/maven.nix diff --git a/README.md b/README.md index 44d0747..f186b0d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ designed to work with nixpkgs but also other package sets. - update buildGoModule's vendorHash/vendorSha256 - update buildNpmPackage's npmDepsHash and npmConfigHook's npmDeps - update buildComposerProject's vendorHash +- update buildMavenPackage's mvnHash - update fetchYarnDeps offlineCache output hash - update flake outputs (see `--flake`) - build and run the resulting package (see `--build`, diff --git a/nix_update/eval.py b/nix_update/eval.py index bb65cc1..a6ea63b 100644 --- a/nix_update/eval.py +++ b/nix_update/eval.py @@ -56,6 +56,7 @@ class Package: npm_deps: str | None yarn_deps: str | None composer_deps: str | None + maven_deps: str | None tests: list[str] has_update_script: bool @@ -162,6 +163,7 @@ in {{ composer_deps = pkg.composerRepository.outputHash or null; npm_deps = pkg.npmDeps.outputHash or null; yarn_deps = pkg.offlineCache.outputHash or null; + maven_deps = pkg.fetchedMavenDeps.outputHash or null; tests = builtins.attrNames (pkg.passthru.tests or {{}}); has_update_script = {has_update_script}; src_homepage = pkg.src.meta.homepage or null; diff --git a/nix_update/update.py b/nix_update/update.py index 278b012..901cd42 100644 --- a/nix_update/update.py +++ b/nix_update/update.py @@ -271,6 +271,11 @@ def update_yarn_deps_hash(opts: Options, filename: str, current_hash: str) -> No replace_hash(filename, current_hash, target_hash) +def update_maven_deps_hash(opts: Options, filename: str, current_hash: str) -> None: + target_hash = nix_prefetch(opts, "fetchedMavenDeps") + replace_hash(filename, current_hash, target_hash) + + def update_version( package: Package, version: str, preference: VersionPreference, version_regex: str ) -> bool: @@ -385,4 +390,7 @@ def update(opts: Options) -> Package: if package.yarn_deps: update_yarn_deps_hash(opts, package.filename, package.yarn_deps) + if package.maven_deps: + update_maven_deps_hash(opts, package.filename, package.maven_deps) + return package diff --git a/tests/test_maven.py b/tests/test_maven.py new file mode 100644 index 0000000..d997bf2 --- /dev/null +++ b/tests/test_maven.py @@ -0,0 +1,27 @@ +import subprocess + +import conftest + +from nix_update.options import Options +from nix_update.update import update + + +def test_update(helpers: conftest.Helpers) -> None: + with helpers.testpkgs() as path: + opts = Options(attribute="maven", import_path=str(path)) + update(opts) + version = subprocess.run( + [ + "nix", + "eval", + "--raw", + "--extra-experimental-features", + "nix-command", + "-f", + path, + "maven.version", + ], + text=True, + stdout=subprocess.PIPE, + ).stdout.strip() + assert tuple(map(int, version.split("."))) > (3, 3, 0) diff --git a/tests/testpkgs/default.nix b/tests/testpkgs/default.nix index 11003da..f641e8d 100644 --- a/tests/testpkgs/default.nix +++ b/tests/testpkgs/default.nix @@ -13,4 +13,5 @@ sourcehut = pkgs.python3.pkgs.callPackage ./sourcehut.nix { }; savanna = pkgs.python3.pkgs.callPackage ./savanna.nix { }; npm = pkgs.callPackage ./npm.nix { }; + maven = pkgs.callPackage ./maven.nix { }; } diff --git a/tests/testpkgs/maven.nix b/tests/testpkgs/maven.nix new file mode 100644 index 0000000..b4d7195 --- /dev/null +++ b/tests/testpkgs/maven.nix @@ -0,0 +1,16 @@ +{ maven, fetchFromGitHub }: + +maven.buildMavenPackage rec { + pname = "mariadb-connector-java"; + version = "3.3.0"; + + src = fetchFromGitHub { + owner = "mariadb-corporation"; + repo = "mariadb-connector-j"; + rev = "refs/tags/${version}"; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + }; + + mvnHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + mvnParameters = "-DskipTests"; +}