Skip to content

Commit 76819ce

Browse files
committed
feat: allow use of remote file args in compiler arguments
1 parent 7af0ad5 commit 76819ce

File tree

7 files changed

+90
-14
lines changed

7 files changed

+90
-14
lines changed

itests/flags.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
match: ["*.*"],
4+
inline: [
5+
"+com.github.tjake.jlama.tensor.operations.PanamaTensorOperations::dotProduct*",
6+
"+com.github.tjake.jlama.tensor.operations.PanamaTensorOperations::quantize*",
7+
"+com.github.tjake.jlama.tensor.operations.PanamaTensorOperations*::mpack*",
8+
"+com.github.tjake.jlama.tensor.AbstractTensor::getOffset*",
9+
"+com.github.tjake.jlama.tensor.*::getVector*"
10+
]
11+
}
12+
]

src/main/java/dev/jbang/cli/Run.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public Integer doCall() throws IOException {
9090

9191
buildAgents(ctx);
9292

93+
// swizzle remote files after agents been added.
94+
runMixin.javaRuntimeOptions = Util.handleRemoteFiles(runMixin.javaRuntimeOptions);
95+
9396
String cmdline = updateGeneratorForRun(genb).build().generate();
9497

9598
Util.verboseMsg("run: " + cmdline);
@@ -113,7 +116,6 @@ void buildAgents(BuildContext ctx) throws IOException {
113116
if (runMixin.javaRuntimeOptions == null) {
114117
runMixin.javaRuntimeOptions = new ArrayList<>();
115118
}
116-
agents = handleRemoteFiles(agents);
117119
for (Map.Entry<String, String> agentOption : agents.entrySet()) {
118120
String javaAgent = agentOption.getKey();
119121
String javaAgentOptions = agentOption.getValue();

src/main/java/dev/jbang/source/CmdGeneratorBuilder.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.jbang.source;
22

33
import java.util.*;
4-
import java.util.stream.Collectors;
54

65
import dev.jbang.catalog.Alias;
76
import dev.jbang.source.generators.JarCmdGenerator;
@@ -145,9 +144,9 @@ private NativeCmdGenerator createNativeCmdGenerator() {
145144

146145
private void updateFromAlias(Alias alias) {
147146
if (arguments.isEmpty()) {
148-
setArguments(handleRemoteFiles(alias.arguments));
147+
setArguments(Util.handleRemoteFiles(alias.arguments));
149148
} else if (alias.arguments != null && !alias.arguments.isEmpty()) {
150-
List<String> args = new ArrayList<>(handleRemoteFiles(alias.arguments));
149+
List<String> args = new ArrayList<>(Util.handleRemoteFiles(alias.arguments));
151150
args.addAll(arguments);
152151
setArguments(args);
153152
}
@@ -184,11 +183,4 @@ private void updateFromAlias(Alias alias) {
184183
}
185184
}
186185

187-
private static List<String> handleRemoteFiles(List<String> args) {
188-
if (args != null) {
189-
return args.stream().map(Util::substituteRemote).collect(Collectors.toList());
190-
} else {
191-
return null;
192-
}
193-
}
194186
}

src/main/java/dev/jbang/source/buildsteps/CompileBuildStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected Project compile() throws IOException {
7474
optionList.add("-source");
7575
optionList.add("" + JavaUtil.javaVersion(requestedJavaVersion));
7676
}
77-
optionList.addAll(project.getMainSourceSet().getCompileOptions());
77+
optionList.addAll(Util.handleRemoteFiles(project.getMainSourceSet().getCompileOptions()));
7878
String path = ctx.resolveClassPath().getClassPath();
7979
if (!Util.isBlankString(path)) {
8080
if (project.getModuleName().isPresent()) {

src/main/java/dev/jbang/source/generators/JarCmdGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ protected List<String> generateCommandLineList() throws IOException {
159159

160160
fullArgs.add(javacmd);
161161

162-
fullArgs.addAll(project.getRuntimeOptions());
163-
fullArgs.addAll(runtimeOptions);
162+
fullArgs.addAll(Util.handleRemoteFiles(project.getRuntimeOptions()));
163+
fullArgs.addAll(Util.handleRemoteFiles(runtimeOptions));
164164
fullArgs.addAll(ctx.resolveClassPath().getAutoDectectedModuleArguments(jdk));
165165
fullArgs.addAll(optionalArgs);
166166

src/main/java/dev/jbang/util/Util.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,14 @@ public static String unkebabify(String name) {
403403
return name;
404404
}
405405

406+
public static List<String> handleRemoteFiles(List<String> args) {
407+
if (args != null) {
408+
return args.stream().map(Util::substituteRemote).collect(Collectors.toList());
409+
} else {
410+
return null;
411+
}
412+
}
413+
406414
public enum OS {
407415
linux, alpine_linux, mac, windows, aix, unknown
408416
}

src/test/java/dev/jbang/cli/TestRun.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,68 @@ void testRemoteFileJavaagentComplex() throws Exception {
24042404
assertThat(result.err, containsString("-javaagent:" + jar + "=test:" + file));
24052405
}
24062406

2407+
@Test
2408+
@SuppressWarnings("unchecked")
2409+
void testRemoteFileXXargs(@TempDir File output) throws Exception {
2410+
2411+
wms.stubFor(
2412+
WireMock.get(urlEqualTo("/flags.json"))
2413+
.willReturn(aResponse()
2414+
.withHeader("Content-Type", "text/plain")
2415+
.withBodyFile("flags.json")
2416+
.withBody(
2417+
Util.readString(
2418+
examplesTestFolder.resolve("flags.json")))));
2419+
2420+
wms.start();
2421+
2422+
String script = examplesTestFolder.resolve("helloworld.java").toString();
2423+
String arg = "http://localhost:" + wms.port() + "/flags.json";
2424+
CaptureResult<Integer> result = checkedRun(null, "run", "--verbose",
2425+
"-R=-XX:CompilerDirectivesFile=%{" + arg + "}",
2426+
script);
2427+
assertThat(result.err, containsString("Requesting HTTP GET " + arg));
2428+
Path file = Util.downloadAndCacheFile(arg);
2429+
assertThat(result.err, containsString("-XX:CompilerDirectivesFile=" + file));
2430+
}
2431+
2432+
@Test
2433+
@SuppressWarnings("unchecked")
2434+
void testRemoteFileEmbeddedXXargs(@TempDir File output) throws Exception {
2435+
2436+
wms.stubFor(
2437+
WireMock.get(urlEqualTo("/flags2.json"))
2438+
.willReturn(aResponse()
2439+
.withHeader("Content-Type", "text/plain")
2440+
.withBodyFile("flags2.json")
2441+
.withBody(
2442+
Util.readString(
2443+
examplesTestFolder.resolve("flags.json")))));
2444+
2445+
wms.start();
2446+
String arg = "http://localhost:" + wms.port() + "/flags2.json";
2447+
2448+
String directives = "//RUNTIME_OPTIONS -XX:CompilerDirectivesFile=%{" + arg + "}\n"
2449+
+ "class funky { static void main(String args[]) {} }";
2450+
2451+
Path f = output.toPath().resolve("funky.java");
2452+
2453+
Util.writeString(f, directives);
2454+
2455+
String script = f.toAbsolutePath().toString();
2456+
2457+
CaptureResult<Integer> result = checkedRun(null, "run", "--verbose",
2458+
script);
2459+
assertThat(result.err, containsString("Requesting HTTP GET " + arg));
2460+
Path file = Util.downloadAndCacheFile(arg);
2461+
assertThat(result.err, containsString("-XX:CompilerDirectivesFile=" + file));
2462+
2463+
}
2464+
2465+
void testRemoteFileEmbeddedInOptions() {
2466+
2467+
}
2468+
24072469
@Test
24082470
@SuppressWarnings("unchecked")
24092471
void testRemoteFileArgSimpleEscaped() throws Exception {

0 commit comments

Comments
 (0)