Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement injection of a forkserver into the compiler process #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -38,6 +39,7 @@ private static final class ExitException extends Exception { }
private final MinimizationStrategy strategy;
private final List<ASTCutter> cutters;
private List<Node> currentRoots;
private List<SCMConfiguration.FileMapping> fileMappings;

public SourceCodeMinimizer(SCMConfiguration configuration) throws IOException {
MessageDigest md = null;
Expand All @@ -56,7 +58,8 @@ public SourceCodeMinimizer(SCMConfiguration configuration) throws IOException {

Charset sourceCharset = configuration.getSourceCharset();
cutters = new ArrayList<>();
for (SCMConfiguration.FileMapping mapping: configuration.getFileMappings()) {
fileMappings = configuration.getFileMappings();
for (SCMConfiguration.FileMapping mapping: fileMappings) {
Files.copy(mapping.input, mapping.output, StandardCopyOption.REPLACE_EXISTING);
ASTCutter cutter = new ASTCutter(parser, sourceCharset, mapping.output);
cutters.add(cutter);
Expand Down Expand Up @@ -85,6 +88,15 @@ public boolean allInputsAreParseable() throws IOException {
return true;
}

@Override
public List<Path> getScratchFileNames() {
List<Path> result = new ArrayList<>();
for (SCMConfiguration.FileMapping mapping: fileMappings) {
result.add(mapping.output);
}
return result;
}

@Override
public NodeInformationProvider getNodeInformationProvider() {
return language.getNodeInformationProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.beust.jcommander.Parameter;

import java.io.IOException;
import java.io.PrintStream;

/**
Expand All @@ -34,30 +35,40 @@ public String getName() {
}
}

private InvariantOperations ops;
private String[] commandArgs;
private final String compilerCommandLine;
protected InvariantOperations ops;
private int spawnCount;
private int fruitfulTests;

private static String[] createCommandLine(AbstractConfiguration configuration) {
if (SystemUtils.IS_OS_WINDOWS) {
return new String[] { "cmd.exe", "/C", configuration.compilerCommandLine };
} else {
return new String[] { "/bin/sh", "-c", configuration.compilerCommandLine };
}
}

protected AbstractExternalProcessInvariant(AbstractConfiguration configuration) {
commandArgs = createCommandLine(configuration);
compilerCommandLine = configuration.compilerCommandLine;
}

@Override
public void initialize(InvariantOperations ops) {
public void initialize(InvariantOperations ops) throws IOException {
this.ops = ops;
}

protected abstract boolean testSatisfied(ProcessBuilder pb) throws Exception;

protected String getCompilerCommandLine() {
return compilerCommandLine;
}

protected ProcessBuilder createProcessBuilder() {
ProcessBuilder pb = new ProcessBuilder();
if (SystemUtils.IS_OS_WINDOWS) {
pb.command("cmd.exe", "/C", compilerCommandLine);
} else {
pb.command("/bin/sh", "-c", compilerCommandLine);
}
return pb;
}

protected boolean testSatisfied() throws Exception {
return testSatisfied(createProcessBuilder());
}

@Override
public boolean checkIsSatisfied() throws Exception {
// First, make a fast check that the source can be parsed at all
Expand All @@ -67,7 +78,7 @@ public boolean checkIsSatisfied() throws Exception {

// then proceed to spawning subprocess
spawnCount += 1;
boolean result = testSatisfied(new ProcessBuilder().command(commandArgs));
boolean result = testSatisfied();
fruitfulTests += result ? 1 : 0;

return result;
Expand Down
Loading