Merge pull request #1522 from ludovic111/fix/prepare-netty-natives
🤖 Agent: merged after verify and CI parity passed, built merged with current main (launcher-ship-1). #1521: generated docs keep LF line endings on Windows, so the launcher builds there again (dry run 40035909909 green on all three OSes). #1522: Prepare no longer requires Netty's optional native transport jar, which Prism never downloads (fixes #1487; test plus a real Prism-layout prepare).
This commit is contained in:
@@ -372,6 +372,19 @@ fn client_library_artifacts(manifest: &Value) -> Result<Vec<(&str, &Value)>, Str
|
||||
Ok(artifacts)
|
||||
}
|
||||
|
||||
/// Netty's native transports (`io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-aarch_64`,
|
||||
/// the epoll ones on Linux): the game uses one when it loads and Netty NIO otherwise
|
||||
/// (`EventLoopGroupHolder.remote` asks `KQueue.isAvailable()`, then `Epoll.isAvailable()`), and
|
||||
/// Prism Launcher never downloads them (#1487). Preparing imports one when the launcher has it.
|
||||
fn runs_without(name: &str) -> bool {
|
||||
let mut parts = name.split(':');
|
||||
parts.next() == Some("io.netty")
|
||||
&& parts
|
||||
.next()
|
||||
.is_some_and(|artifact| artifact.starts_with("netty-transport-native-"))
|
||||
&& parts.nth(1).is_some()
|
||||
}
|
||||
|
||||
/// A relative path with only normal components and forward slashes, from a manifest or bundle.
|
||||
pub(crate) fn safe_relative(path: &str) -> Option<PathBuf> {
|
||||
if path.contains('\\') || path.starts_with('/') {
|
||||
@@ -547,9 +560,18 @@ pub fn import(
|
||||
for (name, artifact) in client_library_artifacts(&manifest)? {
|
||||
let (path, sha1) = artifact_fields(artifact)?;
|
||||
let relative = safe_relative(path).ok_or("Unsafe library path")?;
|
||||
let source = launcher_library(&minecraft, name, &relative);
|
||||
let destination = lock.directory.join("libraries/client").join(&relative);
|
||||
if runs_without(name) && !source.is_file() && !destination.exists() {
|
||||
log(&format!(
|
||||
"No {name} in {}: the game runs without it",
|
||||
minecraft.display()
|
||||
));
|
||||
continue;
|
||||
}
|
||||
client_libraries.push(import_copy(
|
||||
&launcher_library(&minecraft, name, &relative),
|
||||
&lock.directory.join("libraries/client").join(&relative),
|
||||
&source,
|
||||
&destination,
|
||||
sha1,
|
||||
"sha1",
|
||||
&hint(LAUNCHER_HINT, version),
|
||||
@@ -783,13 +805,17 @@ pub fn verify(lock: &Lock) -> Result<Artifacts, String> {
|
||||
}
|
||||
|
||||
/// The client libraries, checked against the version JSON (tools/test_model_baking_parity.py's
|
||||
/// `client_libraries`); the client-side exporters compile against them.
|
||||
/// `client_libraries`); the client-side exporters compile against them. A native transport the
|
||||
/// player's launcher did not have is left out.
|
||||
pub fn client_libraries(lock: &Lock, manifest: &Value) -> Result<Vec<PathBuf>, String> {
|
||||
let mut libraries = Vec::new();
|
||||
for (_, artifact) in client_library_artifacts(manifest)? {
|
||||
for (name, artifact) in client_library_artifacts(manifest)? {
|
||||
let (path, sha1) = artifact_fields(artifact)?;
|
||||
let relative = safe_relative(path).ok_or("Unsafe client library path")?;
|
||||
let library = lock.directory.join("libraries/client").join(&relative);
|
||||
if runs_without(name) && !library.exists() {
|
||||
continue;
|
||||
}
|
||||
if !library.exists() || digest(&library, "sha1")? != sha1 {
|
||||
return Err(format!("Client dependency checksum changed: {path}"));
|
||||
}
|
||||
@@ -1071,6 +1097,135 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// scanfee's Prism Launcher 26.3 install on a Mac (#1487): Prism keeps natives under its own
|
||||
/// names and never downloads Netty's native transport, which the game runs without. Preparing
|
||||
/// still checks every other library, and the transport whenever the launcher has it.
|
||||
#[test]
|
||||
fn a_prism_install_without_netty_natives_prepares() {
|
||||
let fixture = Imports::new();
|
||||
let old = fixture.imported(&fixture.source);
|
||||
let prism = fixture.directory.join("PrismLauncher");
|
||||
let put = |path: &str, data: &[u8]| {
|
||||
let path = prism.join(path);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
fs::write(path, data).unwrap();
|
||||
};
|
||||
put(
|
||||
"versions/9.9/9.9.jar",
|
||||
&fs::read(old.join("jars/client.jar")).unwrap(),
|
||||
);
|
||||
put("libraries/org/lib/lib/1/lib-1.jar", b"lib");
|
||||
put(
|
||||
"libraries/com/mojang/jtracy-natives-test/1/jtracy-natives-test-1.jar",
|
||||
b"jtracy natives",
|
||||
);
|
||||
let sha1 = |data: &[u8]| {
|
||||
let file = fixture.directory.join("sha1");
|
||||
fs::write(&file, data).unwrap();
|
||||
digest(&file, "sha1").unwrap()
|
||||
};
|
||||
let library = |name: &str, path: &str, sha1: &str, rules: &str| {
|
||||
format!(
|
||||
r#"{{"name":"{name}","downloads":{{"artifact":{{"path":"{path}","sha1":"{sha1}"}}}}{rules}}}"#
|
||||
)
|
||||
};
|
||||
let netty = |arch: &str| {
|
||||
library(
|
||||
&format!("io.netty:netty-transport-native-kqueue:1:osx-{arch}"),
|
||||
&format!("io/netty/netty-transport-native-kqueue/1/netty-transport-native-kqueue-1-osx-{arch}.jar"),
|
||||
&sha1(b"kqueue"),
|
||||
&format!(r#","rules":[{{"action":"allow","os":{{"name":"{}"}}}}]"#, rule_system()),
|
||||
)
|
||||
};
|
||||
let client_sha1 = digest(&old.join("jars/client.jar"), "sha1").unwrap();
|
||||
let server_sha1 = digest(&old.join("jars/server.jar"), "sha1").unwrap();
|
||||
let libraries = [
|
||||
library(
|
||||
"org.lib:lib:1",
|
||||
"org/lib/lib/1/lib-1.jar",
|
||||
&sha1(b"lib"),
|
||||
"",
|
||||
),
|
||||
library(
|
||||
"com.mojang:jtracy:1:natives-test",
|
||||
"com/mojang/jtracy/1/jtracy-1-natives-test.jar",
|
||||
&sha1(b"jtracy natives"),
|
||||
"",
|
||||
),
|
||||
netty("aarch_64"),
|
||||
netty("x86_64"),
|
||||
];
|
||||
put(
|
||||
"versions/9.9/9.9.json",
|
||||
format!(
|
||||
r#"{{"id":"9.9","javaVersion":{{"majorVersion":25}},"downloads":{{"client":{{"sha1":"{client_sha1}"}},"server":{{"sha1":"{server_sha1}"}}}},"libraries":[{}]}}"#,
|
||||
libraries.join(",")
|
||||
)
|
||||
.as_bytes(),
|
||||
);
|
||||
let manifest_sha1 = digest(&prism.join("versions/9.9/9.9.json"), "sha1").unwrap();
|
||||
fs::write(
|
||||
fixture.target.join("research-lock.json"),
|
||||
format!(
|
||||
r#"{{"minecraft":{{"version":"9.9","java_major":25,"manifest_sha1":"{manifest_sha1}","client_sha1":"{client_sha1}","server_sha1":"{server_sha1}"}}}}"#
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let lock = Lock::read(&fixture.target).unwrap();
|
||||
let server = old.join("jars/server.jar");
|
||||
let prepare = || import(&fixture.target, &lock, Some(&prism), Some(&server), &|_| {});
|
||||
let imported = || {
|
||||
let manifest = verify(&lock).unwrap().manifest;
|
||||
client_libraries(&lock, &manifest).unwrap().len()
|
||||
};
|
||||
|
||||
prepare().unwrap();
|
||||
assert_eq!(imported(), 2);
|
||||
let prepared = read_json(&lock.directory.join("prepared.json")).unwrap();
|
||||
let listed = prepared.get("libraries").and_then(|l| l.get("client"));
|
||||
assert_eq!(
|
||||
listed.and_then(Value::as_array).map(<[Value]>::len),
|
||||
Some(2)
|
||||
);
|
||||
assert!(reuse_imported(&fixture.target, &|_| {}).unwrap());
|
||||
|
||||
// The launcher's copy is used, and checked, when it has one.
|
||||
let manifest = read_json(&prism.join("versions/9.9/9.9.json")).unwrap();
|
||||
let (_, transport) = client_library_artifacts(&manifest)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|(name, _)| runs_without(name))
|
||||
.unwrap();
|
||||
let path = transport.get("path").and_then(Value::as_str).unwrap();
|
||||
put(&format!("libraries/{path}"), b"not kqueue");
|
||||
assert!(prepare().unwrap_err().contains("is not the pinned file"));
|
||||
put(&format!("libraries/{path}"), b"kqueue");
|
||||
prepare().unwrap();
|
||||
assert_eq!(imported(), 3);
|
||||
// Other libraries stay required.
|
||||
fs::remove_dir_all(lock.directory.join("libraries/client/org")).unwrap();
|
||||
fs::remove_file(prism.join("libraries/org/lib/lib/1/lib-1.jar")).unwrap();
|
||||
assert!(prepare().unwrap_err().starts_with("Missing "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runs_without_only_netty_native_transports() {
|
||||
assert!(runs_without(
|
||||
"io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-aarch_64"
|
||||
));
|
||||
assert!(runs_without(
|
||||
"io.netty:netty-transport-native-epoll:4.2.16.Final:linux-x86_64"
|
||||
));
|
||||
for required in [
|
||||
"io.netty:netty-transport-native-unix-common:4.2.16.Final",
|
||||
"io.netty:netty-transport-classes-kqueue:4.2.16.Final",
|
||||
"org.lwjgl:lwjgl:3.3.3:natives-macos-arm64",
|
||||
"com.mojang:jtracy:1.14.38:natives-windows",
|
||||
] {
|
||||
assert!(!runs_without(required), "{required}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn natives_follow_the_architecture() {
|
||||
let names = ["a:b:1:natives-macos", "a:b:1:natives-macos-arm64"];
|
||||
|
||||
Reference in New Issue
Block a user