Unverified Commit e5ea2e22 authored by Ivan Mincik's avatar Ivan Mincik Committed by GitHub
Browse files

graphhopper: init at 10.2 (#394116)

parents 0ef295ba d79dde0c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2677,6 +2677,12 @@
    githubId = 31864305;
    name = "William Hai";
  };
  baileylu = {
    name = "Luke Bailey";
    email = "baileylu@tcd.ie";
    github = "baileyluTCD";
    githubId = 156000062;
  };
  baitinq = {
    email = "manuelpalenzuelamerino@gmail.com";
    name = "Baitinq";
+152 −0
Original line number Diff line number Diff line
{
  fetchFromGitHub,
  fetchurl,
  lib,
  stdenv,
  testers,

  jre,
  makeWrapper,
  maven,
  ...
}:
let
  version = builtins.fromTOML (builtins.readFile ./version.toml);

  src = fetchFromGitHub {
    owner = "graphhopper";
    repo = "graphhopper";
    tag = version.patch;
    hash = version.hash.src;
  };

  # Patch graphhopper to remove the npm download
  patches = [ ./remove-npm-dependency.patch ];

  # Graphhopper also relies on a maps bundle downloaded from npm
  # By default it installs nodejs and npm during the build,
  # But we patch that out so we much fetch it ourselves
  mapsBundle = fetchurl {
    name = "@graphhopper/graphhopper-maps-bundle-${version.mapsBundle}";
    url = "https://registry.npmjs.org/@graphhopper/graphhopper-maps-bundle/-/graphhopper-maps-bundle-${version.mapsBundle}.tgz";
    hash = version.hash.mapsBundle;
  };

  # We cannot use `buildMavenPackage` as we need to load in the
  # mapsBundle before doing anything
  mvnDeps = stdenv.mkDerivation {
    name = "graphhopper-dependencies";

    inherit src patches;

    buildInputs = [ maven ];

    buildPhase = ''
      # Fetching deps with mvn dependency:go-offline does not quite catch everything, so we use this plugin instead
      mvn de.qaware.maven:go-offline-maven-plugin:resolve-dependencies \
        -Dmaven.repo.local=$out/.m2 \
        -Dmaven.wagon.rto=5000
    '';

    installPhase = ''
      # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
      find $out -type f \( \
        -name \*.lastUpdated \
        -o -name resolver-status.properties \
        -o -name _remote.repositories \) \
        -delete
    '';

    outputHashMode = "recursive";
    outputHash = version.hash.mvnDeps;
  };
in
stdenv.mkDerivation (finalAttrs: {
  pname = "graphhopper";

  inherit src patches;

  version = version.patch;

  buildInputs = [
    makeWrapper
    maven
  ];

  configurePhase = ''
    runHook preConfigure

    mkdir -p ./web-bundle/target/
    ln -s ${mapsBundle} ./web-bundle/target/graphhopper-graphhopper-maps-bundle-${version.mapsBundle}.tgz

    runHook postConfigure
  '';

  # Build and skip tests because downloading of
  # test deps seems to not work with the go-offline plugin
  buildPhase = ''
    runHook preBuild

    mvn package --offline \
      -Dmaven.repo.local=${mvnDeps}/.m2 \
      -DskipTests

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin

    ln -s ${mvnDeps}/.m2 $out/lib

    # Grapphopper versions are seemingly compiled under the major release name,
    # not the patch name, which is the version we want for our package
    cp ./web/target/graphhopper-web-${version.major}-SNAPSHOT.jar $out/bin/graphhopper-web-${version.major}-SNAPSHOT.jar

    makeWrapper ${jre}/bin/java $out/bin/graphhopper \
      --add-flags "-jar $out/bin/graphhopper-web-${version.major}-SNAPSHOT.jar" \
      --chdir $out

    runHook postInstall
  '';

  fixupPhase = ''
    runHook preFixup

    # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
    find $out -type f \( \
      -name \*.lastUpdated \
      -o -name resolver-status.properties \
      -o -name _remote.repositories \) \
      -delete

    runHook postFixup
  '';

  meta = {
    description = "Fast and memory-efficient routing engine for OpenStreetMap";
    homepage = "https://www.graphhopper.com/";
    changelog = "https://github.com/graphhopper/graphhopper/releases/tag/${version.patch}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ baileylu ];
    teams = [ lib.teams.geospatial ];
    platforms = lib.platforms.all;
    mainProgram = "graphhopper";
    sourceProvenance = with lib.sourceTypes; [
      fromSource
      binaryBytecode
    ];
  };

  passthru = {
    updateScript = ./update.nu;
    tests.version = testers.testVersion {
      package = finalAttrs.finalPackage;
      # `graphhopper --version` does not work as the source does not specify `Implementation-Version`
      command = "graphhopper --help";
      version = "graphhopper-web-${version.major}-SNAPSHOT.jar";
    };
  };
})
+55 −0
Original line number Diff line number Diff line
From ad687709cfca51603264ff565f296cfb5dceb15a Mon Sep 17 00:00:00 2001
From: Luke Bailey <baileylu@tcd.ie>
Date: Wed, 19 Mar 2025 22:25:44 +0000
Subject: [PATCH] Swap out frontend maven plugin which downloads npm
 for fetching it through nix instead

---
 web-bundle/pom.xml | 31 -------------------------------
 1 file changed, 31 deletions(-)

diff --git a/web-bundle/pom.xml b/web-bundle/pom.xml
index 9a4d83b62..1d995cbaf 100644
--- a/web-bundle/pom.xml
+++ b/web-bundle/pom.xml
@@ -129,37 +129,6 @@
 
     <build>
         <plugins>
-            <plugin>
-                <groupId>com.github.eirslett</groupId>
-                <artifactId>frontend-maven-plugin</artifactId>
-                <version>1.12.1</version>
-                <executions>
-                    <execution>
-                        <id>install node and npm</id>
-                        <goals>
-                            <goal>install-node-and-npm</goal>
-                        </goals>
-                        <configuration>
-                            <nodeVersion>v20.14.0</nodeVersion>
-                            <npmVersion>10.7.0</npmVersion>
-                        </configuration>
-                    </execution>
-                    <execution>
-                        <id>download graphhopper maps</id>
-                        <phase>generate-resources</phase>
-                        <goals>
-                            <goal>npm</goal>
-                        </goals>
-                        <configuration>
-                            <!--suppress UnresolvedMavenProperty (IntelliJ shows an error otherwise...)-->
-                            <arguments>
-                                pack --pack-destination=${basedir}/target
-                                @graphhopper/graphhopper-maps-bundle@${graphhopper-maps.version}
-                            </arguments>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
             <plugin>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>
-- 
2.48.1
+102 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#! nix-shell -i nu -p nushell nix-prefetch-github common-updater-scripts

use std/log

let version_info = "./pkgs/by-name/gr/graphhopper/version.toml"

let current_version = open $version_info

let latest_tag = list-git-tags --url=https://github.com/graphhopper/graphhopper
    | lines
    | sort --natural
    | where ($it =~ '^[\d.]+$')
    | last

if $current_version.patch == $latest_tag {
    log debug "Current graphhopper version matched latest version of graphhopper, no update is needed, exiting..."
    exit 0
}

let major = $latest_tag
    | str replace -ar '(\d+)\.\d+' '$1.0'

log debug $"Fetching source for graphhopper patch ($latest_tag) on version ($major)"
let source = nix-prefetch-github graphhopper graphhopper --rev $latest_tag
    | from json

log debug $"Reading maps bundle version for ($latest_tag)"
let web_bundle_pom = http get $"https://api.github.com/repos/graphhopper/graphhopper/contents/web-bundle/pom.xml?ref=($latest_tag)"
    | $in.content
    | base64 --decode
    | into string
    | from xml

let maps_bundle_properties = $web_bundle_pom.content
    | where ($it.tag =~ "properties")
    | first

let maps_bundle_version = $maps_bundle_properties.content
    | where ($it.tag =~ "graphhopper-maps.version")
    | first
    | $in.content
    | first
    | $in.content

log debug $"Fetching maps bundle ($maps_bundle_version)"
let maps_bundle_hash = nix-prefetch-url $"https://registry.npmjs.org/@graphhopper/graphhopper-maps-bundle/-/graphhopper-maps-bundle-($maps_bundle_version).tgz"
    | nix-hash --type sha256 --to-base64 $in
    | ["sha256-", $in]
    | str join

log debug $"Writing to ($version_info) without mvnDeps hash..."

{
    major: $major,
    patch: $latest_tag,
    mapsBundle: $maps_bundle_version,

    hash: {
        src: $source.hash
        mapsBundle: $maps_bundle_hash
        mvnDeps: "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
    }
}
    | to toml
    | save $version_info -f

log debug "Calculating mvnDeps hash..."
let graphhopper_build_logs = nix-build -A graphhopper o+e>| cat

let mvn_hash_lines = $graphhopper_build_logs
    | lines
    | find "got:"

if ($mvn_hash_lines | length) == 0 {
    log error $"Could not find any maven hash in the graphhopper build logs - maybe a different error occurred: \n$($graphhopper_build_logs)"
    exit 1
}

log debug $"Found relevant hash lines: ($mvn_hash_lines)"
let mvn_hash = $mvn_hash_lines
    | first
    | ansi strip
    | str replace 'got:' ''
    | str trim

log debug $"Writing to ($version_info) with mvnDeps hash ($mvn_hash).."
{
    major: $major,
    patch: $latest_tag,
    mapsBundle: $maps_bundle_version,

    hash: {
        src: $source.hash
        mapsBundle: $maps_bundle_hash
        mvnDeps: $mvn_hash
    }
}
    | to toml
    | save $version_info -f

log debug $"Successfully updated graphhopper package!"
+8 −0
Original line number Diff line number Diff line
major = "10.0"
patch = "10.2"
mapsBundle = "0.0.0-4718098d1db1798841a4d12f1727e8e8f7eab202"

[hash]
src = "sha256-E6G9JR1lrXhNJ4YgMM0n0RsQcMZQM2QldGc74f5FALo="
mapsBundle = "sha256-jZTNJfmMWJQHpJ8um3yTBx/KtIfdr0EwKJ9kSFalWJQ="
mvnDeps = "sha256-KidbIBnW//IiKPFy3plFWOED8gP/ZCg4buwMgzttaY8="