Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions rtxremix-java/src/com/nvidia/rtxremix/CommandLineRedaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,31 @@ final class CommandLineRedaction {
static final char BLANK = '*';

/** The blanked command line, and how many option values it blanked. */
record Result(String commandLine, int blankedValues) {}
static final class Result {
private final String commandLine;
private final int blankedValues;

Result(String commandLine, int blankedValues) {
this.commandLine = commandLine;
this.blankedValues = blankedValues;
}

String commandLine() { return commandLine; }
int blankedValues() { return blankedValues; }
}

/** One argument: its text after unquoting, and its span in the raw command line. */
private record Argument(String text, int start, int end) {}
private static final class Argument {
private final String text;
private final int start;
private final int end;

Argument(String text, int start, int end) {
this.text = text;
this.start = start;
this.end = end;
}
}

private CommandLineRedaction() {}

Expand All @@ -44,18 +65,18 @@ static Result redact(String commandLine, Collection<String> options) {
int blankedValues = 0;
for (int i = 1; i < arguments.size(); i++) {
Argument argument = arguments.get(i);
if (options.contains(argument.text())) {
if (options.contains(argument.text)) {
if (i + 1 < arguments.size()) {
Argument value = arguments.get(i + 1);
blank(chars, value.start(), value.end());
blank(chars, value.start, value.end);
blankedValues++;
}
continue;
}
int separator = argument.text().indexOf('=');
if (separator > 0 && options.contains(argument.text().substring(0, separator))) {
int separator = argument.text.indexOf('=');
if (separator > 0 && options.contains(argument.text.substring(0, separator))) {
// Option names hold no quotes, so the first raw '=' is the separator.
blank(chars, commandLine.indexOf('=', argument.start()) + 1, argument.end());
blank(chars, commandLine.indexOf('=', argument.start) + 1, argument.end);
blankedValues++;
}
}
Expand Down Expand Up @@ -115,7 +136,9 @@ private static List<Argument> split(String line) {
}
backslashes /= 2;
}
text.repeat('\\', backslashes);
for (int i = 0; i < backslashes; i++) {
text.append('\\');
}
if (pos == length || (!inQuotes && isBlank(line.charAt(pos)))) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package com.nvidia.rtxremix;

import org.joml.Quaternionf;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import javax.tools.JavaCompiler;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class Java8FacadeCompatibilityTest {
@Test
void sharedFacadeCompilesAgainstJava8(@TempDir Path output) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
assertNotNull(compiler, "The facade compatibility test requires a JDK compiler");
List<Path> sources;
try (var paths = Files.walk(Path.of("rtxremix-java", "src"))) {
sources = paths.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".java"))
.sorted().toList();
}
assertFalse(sources.isEmpty(), "No shared facade sources were found");
Path joml = Path.of(Quaternionf.class.getProtectionDomain().getCodeSource().getLocation().toURI());
var compilerOutput = new StringWriter();
try (var files = compiler.getStandardFileManager(null, Locale.ROOT, StandardCharsets.UTF_8)) {
// Exclude the current-JDK facade and game classes from this independent compilation.
files.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(joml));
files.setLocationFromPaths(StandardLocation.SOURCE_PATH, List.of());
files.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, List.of(output));
boolean compiled = compiler.getTask(compilerOutput, files, null,
List.of("--release", "8", "-proc:none"), null,
files.getJavaFileObjectsFromPaths(sources)).call();
assertTrue(compiled, () -> "Shared facade must compile against Java 8 with only JOML on its classpath:\n"
+ compilerOutput);
}
}
}