fixed: critical review findings - extra_args double emission and library dedup

extra_args from the patches module was being passed to build_game_args
(which appended it to game_args) AND emitted again via cmd.args before
game_args - a regression that doubled legacy Forge + lwjgl3ify shim
args. extra_args is now passed only once. also, merge_into now dedups
libraries by group:artifact, preferring the child's entry - without
this, Forge/NeoForge library overrides of vanilla (e.g. log4j) would
silently lose to vanilla because the JVM picks the first classpath
match.
This commit is contained in:
objz committed 2026-05-25 17:33:52 +02:00
1 parent a7b378b17d
commit 19887643bc
2 files changed
+90 -26

No files matched your search

+6 -21
View File
@@ -35,13 +35,10 @@ fn build_game_args(
profile: &crate::launch_profile::model::LaunchProfile,
rule_ctx: &crate::launch_profile::rules::RuleContext<'_>,
template_ctx: &crate::launch_profile::templates::TemplateContext<'_>,
loader_game_args: Vec<String>,
) -> Result<(Vec<String>, Vec<String>), LaunchError> {
let rendered = crate::launch_profile::render::render_args(profile, rule_ctx, template_ctx)
.map_err(|e| LaunchError::Parse(format!("Failed to render args: {e}")))?;
let mut game = rendered.game;
game.extend(loader_game_args);
Ok((rendered.jvm, game))
Ok((rendered.jvm, rendered.game))
}
// existing installs from rmcl <= 0.3.0 have meta.json files in the
@@ -428,12 +425,8 @@ pub async fn launch(
clientid: "0",
};
let (upstream_jvm_args, game_args) = build_game_args(
&merged_profile,
&rule_ctx,
&template_ctx,
extra_args.clone(),
)?;
let (upstream_jvm_args, game_args) =
build_game_args(&merged_profile, &rule_ctx, &template_ctx)?;
let mut jvm: Vec<String> = vec![
format!("-Xms{}", config.memory_min.as_deref().unwrap_or("512M")),
@@ -652,18 +645,10 @@ mod tests {
type_: None,
};
let (jvm, game_args) = build_game_args(
&profile,
&rule_ctx,
&template_ctx,
vec!["--tweakClass".into(), "foo".into()],
)
.unwrap();
let (jvm, game_args) =
build_game_args(&profile, &rule_ctx, &template_ctx).unwrap();
assert_eq!(jvm, vec!["-Djava.library.path=/m/natives"]);
assert_eq!(
game_args,
vec!["--username", "Player", "--tweakClass", "foo"]
);
assert_eq!(game_args, vec!["--username", "Player"]);
}
#[test]
+84 -5
View File
@@ -47,11 +47,7 @@ pub fn merge_into(child: LaunchProfile, parent: LaunchProfile) -> LaunchProfile
id: child.id,
inherits_from: parent.inherits_from,
main_class: child.main_class.or(parent.main_class),
libraries: {
let mut libs = parent.libraries;
libs.extend(child.libraries);
libs
},
libraries: merge_libraries(child.libraries, parent.libraries),
arguments: merge_arguments(child.arguments, parent.arguments),
minecraft_arguments: child.minecraft_arguments.or(parent.minecraft_arguments),
asset_index: child.asset_index.or(parent.asset_index),
@@ -64,6 +60,44 @@ pub fn merge_into(child: LaunchProfile, parent: LaunchProfile) -> LaunchProfile
}
}
// extracts the `group:artifact` portion of a maven coordinate, dropping
// version and any classifier. used as the dedup key when merging library
// lists from a child profile on top of its parent.
fn coord_key(name: &str) -> &str {
// mojang maven coords are `group:artifact:version[:classifier]`. take
// everything up to the second colon.
let mut count = 0;
for (i, b) in name.bytes().enumerate() {
if b == b':' {
count += 1;
if count == 2 {
return &name[..i];
}
}
}
name
}
// child entries take precedence over parent entries with the same
// group:artifact. mojang and the major third-party launchers (prism,
// multimc) all dedup this way - without it, loader overrides of vanilla
// libraries (e.g. forge bumping log4j) would lose to vanilla because the
// JVM picks the first classpath match.
fn merge_libraries(
child: Vec<crate::launch_profile::model::Library>,
parent: Vec<crate::launch_profile::model::Library>,
) -> Vec<crate::launch_profile::model::Library> {
use std::collections::HashSet;
let child_keys: HashSet<String> = child.iter().map(|l| coord_key(&l.name).to_string()).collect();
let mut out: Vec<crate::launch_profile::model::Library> = parent
.into_iter()
.filter(|l| !child_keys.contains(coord_key(&l.name)))
.collect();
out.extend(child);
out
}
fn merge_arguments(child: Option<Arguments>, parent: Option<Arguments>) -> Option<Arguments> {
match (child, parent) {
(None, None) => None,
@@ -223,6 +257,51 @@ mod tests {
assert_eq!(names, vec!["p1", "p2", "c1"]);
}
#[test]
fn child_library_supersedes_parent_with_same_group_artifact() {
// forge declares log4j 2.17.0; vanilla declared 2.0-beta9. without
// dedup, both end up on the classpath and the JVM picks the first
// (vanilla) match - defeating forge's override. dedup keeps child's.
let mut child = empty_profile("forge");
let mut parent = empty_profile("vanilla");
parent.libraries = vec![
lib("org.apache.logging.log4j:log4j-core:2.0-beta9"),
lib("org.lwjgl:lwjgl:3.3.1"),
];
child.libraries = vec![
lib("org.apache.logging.log4j:log4j-core:2.17.0"),
lib("net.minecraftforge:forge:47.2.0"),
];
let merged = merge_into(child, parent);
let names: Vec<_> = merged.libraries.iter().map(|l| l.name.as_str()).collect();
// parent's log4j-core is filtered (superseded by child); parent's
// lwjgl stays (no conflict); child's log4j and forge come last.
assert_eq!(
names,
vec![
"org.lwjgl:lwjgl:3.3.1",
"org.apache.logging.log4j:log4j-core:2.17.0",
"net.minecraftforge:forge:47.2.0",
]
);
}
#[test]
fn coord_key_extracts_group_artifact() {
assert_eq!(coord_key("org.lwjgl:lwjgl:3.3.1"), "org.lwjgl:lwjgl");
assert_eq!(
coord_key("org.apache.logging.log4j:log4j-core:2.17.0"),
"org.apache.logging.log4j:log4j-core"
);
// with classifier
assert_eq!(
coord_key("org.lwjgl:lwjgl:3.3.1:natives-linux"),
"org.lwjgl:lwjgl"
);
// malformed (no colons) - return as-is
assert_eq!(coord_key("malformed"), "malformed");
}
#[test]
fn arguments_are_concatenated_parent_first() {
let mut child = empty_profile("child");