Skip to content

Commit 1e534ef

Browse files
committed
Merge branch 'jaunch-config-replication' into main
Avoids various causes of duplication within JaunchConfigs. Closes #63
2 parents 155b12f + 9ee3bbb commit 1e534ef

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/commonMain/kotlin/config.kt

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -149,43 +149,49 @@ data class JaunchConfig (
149149
throw IllegalArgumentException("Config versions are incompatible: ${config.jaunchVersion} != $jaunchVersion")
150150
}
151151
return JaunchConfig(
152+
// NB: when relevant, prefer values in the new config
152153
jaunchVersion = config.jaunchVersion ?: jaunchVersion,
153154
programName = config.programName ?: programName,
154-
includes = config.includes + includes,
155-
supportedOptions = config.supportedOptions + supportedOptions,
156-
osAliases = config.osAliases + osAliases,
157-
archAliases = config.archAliases + archAliases,
158-
modes = config.modes + modes,
159-
directives = config.directives + directives,
155+
includes = merge(config.includes, includes),
156+
supportedOptions = merge(config.supportedOptions, supportedOptions),
157+
osAliases = merge(config.osAliases, osAliases),
158+
archAliases = merge(config.archAliases, archAliases),
159+
modes = merge(config.modes, modes),
160+
directives = merge(config.directives, directives),
160161
allowUnrecognizedArgs = config.allowUnrecognizedArgs ?: allowUnrecognizedArgs,
161162

162163
pythonEnabled = config.pythonEnabled ?: pythonEnabled,
163-
pythonRecognizedArgs = config.pythonRecognizedArgs + pythonRecognizedArgs,
164-
pythonRootPaths = config.pythonRootPaths + pythonRootPaths,
165-
pythonLibSuffixes = config.pythonLibSuffixes + pythonLibSuffixes,
164+
pythonRecognizedArgs = merge(config.pythonRecognizedArgs, pythonRecognizedArgs),
165+
pythonRootPaths = merge(config.pythonRootPaths, pythonRootPaths),
166+
pythonLibSuffixes = merge(config.pythonLibSuffixes, pythonLibSuffixes),
166167
pythonVersionMin = config.pythonVersionMin ?: pythonVersionMin,
167168
pythonVersionMax = config.pythonVersionMax ?: pythonVersionMax,
168-
pythonPackages = config.pythonPackages + pythonPackages,
169-
pythonRuntimeArgs = config.pythonRuntimeArgs + pythonRuntimeArgs,
170-
pythonScriptPath = config.pythonScriptPath + pythonScriptPath,
171-
pythonMainArgs = config.pythonMainArgs + pythonMainArgs,
169+
pythonPackages = merge(config.pythonPackages, pythonPackages),
170+
pythonRuntimeArgs = merge(config.pythonRuntimeArgs, pythonRuntimeArgs),
171+
pythonScriptPath = merge(config.pythonScriptPath, pythonScriptPath),
172+
pythonMainArgs = merge(config.pythonMainArgs, pythonMainArgs),
172173

173174
jvmEnabled = config.jvmEnabled ?: jvmEnabled,
174-
jvmRecognizedArgs = config.jvmRecognizedArgs + jvmRecognizedArgs,
175+
jvmRecognizedArgs = merge(config.jvmRecognizedArgs, jvmRecognizedArgs),
175176
jvmAllowWeirdRuntimes = config.jvmAllowWeirdRuntimes ?: jvmAllowWeirdRuntimes,
176177
jvmVersionMin = config.jvmVersionMin ?: jvmVersionMin,
177178
jvmVersionMax = config.jvmVersionMax ?: jvmVersionMax,
178-
jvmDistrosAllowed = config.jvmDistrosAllowed + jvmDistrosAllowed,
179-
jvmDistrosBlocked = config.jvmDistrosBlocked + jvmDistrosBlocked,
180-
jvmRootPaths = config.jvmRootPaths + jvmRootPaths,
181-
jvmLibSuffixes = config.jvmLibSuffixes + jvmLibSuffixes,
182-
jvmClasspath = config.jvmClasspath + jvmClasspath,
179+
jvmDistrosAllowed = merge(config.jvmDistrosAllowed, jvmDistrosAllowed),
180+
jvmDistrosBlocked = merge(config.jvmDistrosBlocked, jvmDistrosBlocked),
181+
jvmRootPaths = merge(config.jvmRootPaths, jvmRootPaths),
182+
jvmLibSuffixes = merge(config.jvmLibSuffixes, jvmLibSuffixes),
183+
jvmClasspath = merge(config.jvmClasspath, jvmClasspath),
183184
jvmMaxHeap = config.jvmMaxHeap ?: jvmMaxHeap,
184-
jvmRuntimeArgs = config.jvmRuntimeArgs + jvmRuntimeArgs,
185-
jvmMainClass = config.jvmMainClass + jvmMainClass,
186-
jvmMainArgs = config.jvmMainArgs + jvmMainArgs,
185+
jvmRuntimeArgs = merge(config.jvmRuntimeArgs, jvmRuntimeArgs),
186+
jvmMainClass = merge(config.jvmMainClass, jvmMainClass),
187+
jvmMainArgs = merge(config.jvmMainArgs, jvmMainArgs),
187188
)
188189
}
190+
191+
/** Helper method to combine arrays without duplication */
192+
private fun merge(base: Array<String>, toMerge: Array<String>): Array<String> {
193+
return (base + toMerge).distinct().toTypedArray()
194+
}
189195
}
190196

191197
// NB: Previously, the TOML config reader was implemented simply using ktoml.
@@ -302,7 +308,7 @@ fun readConfig(
302308

303309
// Recursively read config file includes.
304310
for (path in includes ?: emptyList()) {
305-
theConfig += readConfig(tomlFile.dir / path, theConfig, theVisited)
311+
theConfig = readConfig(tomlFile.dir / path, theConfig, theVisited)
306312
}
307313

308314
// Return the final result.

0 commit comments

Comments
 (0)