-
-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gradle: auto-detect native version and patch file-events #277721
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
rec { | ||
gen = | ||
|
||
{ version, nativeVersion, hash, | ||
{ version, hash, | ||
|
||
# The default JDK/JRE that will be used for derived Gradle packages. | ||
# A current LTS version of a JDK is a good choice. | ||
|
@@ -36,6 +36,7 @@ rec { | |
, testers | ||
, runCommand | ||
, writeText | ||
, autoPatchelfHook | ||
|
||
# The JDK/JRE used for running Gradle. | ||
, java ? defaultJava | ||
|
@@ -57,8 +58,22 @@ rec { | |
|
||
dontBuild = true; | ||
|
||
nativeBuildInputs = [ makeWrapper unzip ]; | ||
buildInputs = [ java ]; | ||
nativeBuildInputs = [ | ||
makeWrapper | ||
unzip | ||
] ++ lib.optionals stdenv.isLinux [ | ||
autoPatchelfHook | ||
]; | ||
|
||
buildInputs = [ | ||
java | ||
stdenv.cc.cc | ||
ncurses5 | ||
ncurses6 | ||
]; | ||
|
||
# We only need to patchelf some libs embedded in JARs. | ||
dontAutoPatchelf = true; | ||
|
||
installPhase = with builtins; | ||
let | ||
|
@@ -87,18 +102,22 @@ rec { | |
|
||
fixupPhase = let arch = if stdenv.is64bit then "amd64" else "i386"; | ||
in '' | ||
. ${./patching.sh} | ||
|
||
nativeVersion="$(extractVersion native-platform $out/lib/gradle/lib/native-platform-*.jar)" | ||
for variant in "" "-ncurses5" "-ncurses6"; do | ||
mkdir "patching$variant" | ||
pushd "patching$variant" | ||
jar xf $out/lib/gradle/lib/native-platform-linux-${arch}$variant-${nativeVersion}.jar | ||
patchelf \ | ||
--set-rpath "${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}" \ | ||
net/rubygrapefruit/platform/linux-${arch}$variant/libnative-platform*.so | ||
jar cf native-platform-linux-${arch}$variant-${nativeVersion}.jar . | ||
mv native-platform-linux-${arch}$variant-${nativeVersion}.jar $out/lib/gradle/lib/ | ||
popd | ||
autoPatchelfInJar \ | ||
$out/lib/gradle/lib/native-platform-linux-${arch}$variant-''${nativeVersion}.jar \ | ||
"${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ncurses5 ncurses6 ]}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know too much about elf patching - but this looks reasonable to me🤷 |
||
done | ||
|
||
# The file-events library _seems_ to follow the native-platform version, but | ||
# we won’t assume that. | ||
fileEventsVersion="$(extractVersion file-events $out/lib/gradle/lib/file-events-*.jar)" | ||
autoPatchelfInJar \ | ||
$out/lib/gradle/lib/file-events-linux-${arch}-''${fileEventsVersion}.jar \ | ||
"${stdenv.cc.cc.lib}/lib64:${lib.makeLibraryPath [ stdenv.cc.cc ]}" | ||
|
||
# The scanner doesn't pick up the runtime dependency in the jar. | ||
# Manually add a reference where it will be found. | ||
mkdir $out/nix-support | ||
|
@@ -162,21 +181,18 @@ rec { | |
|
||
gradle_8 = gen { | ||
version = "8.10"; | ||
nativeVersion = "0.22-milestone-26"; | ||
hash = "sha256-W5xes/n8LJSrrqV9kL14dHyhF927+WyFnTdBGBoSvyo="; | ||
defaultJava = jdk21; | ||
}; | ||
|
||
gradle_7 = gen { | ||
version = "7.6.4"; | ||
nativeVersion = "0.22-milestone-25"; | ||
hash = "sha256-vtHaM8yg9VerE2kcd/OLtnOIEZ5HlNET4FEDm4Cvm7E="; | ||
defaultJava = jdk17; | ||
}; | ||
|
||
gradle_6 = gen { | ||
version = "6.9.4"; | ||
nativeVersion = "0.22-milestone-20"; | ||
hash = "sha256-PiQCKFON6fGHcqV06ZoLqVnoPW7zUQFDgazZYxeBOJo="; | ||
defaultJava = jdk11; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
extractVersion() { | ||
local jar version | ||
local prefix="$1" | ||
shift | ||
local candidates="$@" | ||
|
||
jar="$(basename -a $candidates | sort | head -n1)" | ||
|
||
version="${jar#$prefix-}" | ||
|
||
echo "${version%.jar}" | ||
} | ||
|
||
autoPatchelfInJar() { | ||
local file="$1" rpath="$2" | ||
local work | ||
|
||
work="$(mktemp -dt patching.XXXXXXXXXX)" | ||
pushd "$work" | ||
|
||
jar xf "$file" | ||
rm "$file" | ||
|
||
autoPatchelf -- . | ||
|
||
jar cf "$file" . | ||
|
||
popd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for the record - this is "just" patching the linux version (as it was done before).
As others told me, the resulting nix package works on macOS too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, patchelf is a Linux-only thing, AFAIK.