Skip to content

Commit

Permalink
Add support for updating buildMavenPackage's mvnHash
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyroussel authored and Mic92 committed Mar 18, 2024
1 parent ce6fd41 commit e567ad0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
2 changes: 2 additions & 0 deletions nix_update/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -162,6 +163,7 @@ def eval_expression(
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;
Expand Down
8 changes: 8 additions & 0 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
27 changes: 27 additions & 0 deletions tests/test_maven.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
}
16 changes: 16 additions & 0 deletions tests/testpkgs/maven.nix
Original file line number Diff line number Diff line change
@@ -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";
}

0 comments on commit e567ad0

Please sign in to comment.