modify API to be able to hook extra infer options easily

Summary:
To specify a new flag to run some test using our framework, one currently has
to add a new argument to the method that runs Infer and modify existing methods
to give a default value to that argument everywhere. With this diff, it's
possible to just specify extra arguments as parameters to
`createCInferCommand()` et al.

Reviewed By: martinoluca

Differential Revision: D3522161

fbshipit-source-id: 1499fc2
master
Jules Villard 9 years ago committed by Facebook Github Bot 2
parent 8db2cf0e93
commit 959730de2f

@ -42,7 +42,10 @@ public class NPEAddedToB1Test {
@BeforeClass @BeforeClass
public static void runInfer() throws InterruptedException, IOException { public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createCPPInferCommandFilter(folder, FILE); inferCmd = InferRunner.createCPPInferCommand(
folder,
FILE,
ImmutableList.<String>of("--filtering"));
} }
@Test @Test

@ -61,9 +61,6 @@ public class InferRunner {
private static HashMap<String, InferResults> inferResultsMap = private static HashMap<String, InferResults> inferResultsMap =
new HashMap<String, InferResults>(); new HashMap<String, InferResults>();
private InferRunner() {
}
private static String getXcodeRoot() throws IOException, InterruptedException { private static String getXcodeRoot() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("xcode-select", "-p"); ProcessBuilder pb = new ProcessBuilder("xcode-select", "-p");
Process process = pb.start(); Process process = pb.start();
@ -256,58 +253,25 @@ public class InferRunner {
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile, String sourceFile,
Language lang, Language lang,
boolean analyze,
@Nullable String isysroot, @Nullable String isysroot,
@Nullable String ml_buckets,
boolean arc, boolean arc,
boolean headers, ImmutableList<String> inferOptions) {
boolean testingMode,
boolean filter) {
File resultsDir = createResultsDir(folder); File resultsDir = createResultsDir(folder);
String resultsDirName = resultsDir.getAbsolutePath(); String resultsDirName = resultsDir.getAbsolutePath();
InferRunner.bugsFile = new File(resultsDir, BUGS_FILE_NAME); InferRunner.bugsFile = new File(resultsDir, BUGS_FILE_NAME);
ImmutableList.Builder<String> analyzeOption = return new ImmutableList.Builder<String>()
new ImmutableList.Builder<>(); .add("infer")
if (!analyze) { .add("--cxx")
analyzeOption .add("--no-filtering")
.add("--analyzer") .add("--out")
.add("capture"); .add(resultsDirName)
} .add("--no-progress-bar")
if (headers) { .add("--testing-mode")
analyzeOption .addAll(inferOptions)
.add("--headers"); .add("--")
} .addAll(createClangCommand(sourceFile, lang, isysroot, arc))
ImmutableList.Builder<String> ml_bucketsOption = .build();
new ImmutableList.Builder<>();
ml_bucketsOption
.add("--ml_buckets")
.add(ml_buckets == null ? "all" : ml_buckets);
ImmutableList.Builder<String> testingModeOption =
new ImmutableList.Builder<>();
if (testingMode) {
testingModeOption.add("--testing_mode");
}
ImmutableList.Builder<String> doNotFilterOption =
new ImmutableList.Builder<>();
if (!filter) {
doNotFilterOption.add("--no-filtering");
}
ImmutableList<String> inferCmd = new ImmutableList.Builder<String>()
.add("infer")
.add("--no-progress-bar")
.addAll(doNotFilterOption.build())
.add("--out")
.add(resultsDirName)
.addAll(testingModeOption.build())
.add("--cxx")
.addAll(analyzeOption.build())
.addAll(ml_bucketsOption.build())
.add("--")
.addAll(createClangCommand(sourceFile, lang, isysroot, arc))
.build();
return inferCmd;
} }
public static ImmutableList<String> createClangInferCommand( public static ImmutableList<String> createClangInferCommand(
@ -318,57 +282,52 @@ public class InferRunner {
@Nullable String isysroot, @Nullable String isysroot,
@Nullable String ml_buckets, @Nullable String ml_buckets,
boolean arc, boolean arc,
boolean headers, ImmutableList<String> extraInferOptions) {
boolean testingMode) { ImmutableList.Builder<String> inferOptionsBuilder = new ImmutableList.Builder<String>()
.addAll(extraInferOptions);
if (!analyze) {
inferOptionsBuilder.add("--analyzer").add("capture");
}
inferOptionsBuilder
.add("--ml_buckets")
.add(ml_buckets == null ? "all" : ml_buckets);
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
lang, lang,
analyze,
isysroot, isysroot,
ml_buckets,
arc, arc,
headers, inferOptionsBuilder.build());
testingMode,
false);
} }
public static ImmutableList<String> createClangInferCommand( public static ImmutableList<String> createCInferCommandFrontend(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile, String sourceFile,
Language lang, ImmutableList<String> extraInferOptions) {
boolean analyze,
@Nullable String isysroot,
@Nullable String ml_buckets,
boolean arc) {
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
lang, Language.C,
analyze, false,
isysroot, null,
ml_buckets, null,
arc,
false, false,
true); extraInferOptions);
} }
public static ImmutableList<String> createCInferCommandFrontend( public static ImmutableList<String> createCInferCommandFrontend(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) { String sourceFile) {
return createClangInferCommand( return createCInferCommandFrontend(folder, sourceFile, ImmutableList.<String>of());
folder,
sourceFile,
Language.C,
false,
null,
null,
false);
} }
public static ImmutableList<String> createCPPInferCommandFrontend( public static ImmutableList<String> createCPPInferCommandFrontend(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) { String sourceFile,
ImmutableList<String> extraInferOptions) {
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
@ -376,12 +335,20 @@ public class InferRunner {
false, false,
null, null,
null, null,
false); false,
extraInferOptions);
}
public static ImmutableList<String> createCPPInferCommandFrontend(
TemporaryFolder folder,
String sourceFile) {
return createCPPInferCommandFrontend(folder, sourceFile, ImmutableList.<String>of());
} }
public static ImmutableList<String> createObjCInferCommandFrontend( public static ImmutableList<String> createObjCInferCommandFrontend(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException { String sourceFile,
ImmutableList<String> extraInferOptions) throws IOException, InterruptedException {
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
@ -389,12 +356,20 @@ public class InferRunner {
false, false,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
false); false,
extraInferOptions);
} }
public static ImmutableList<String> createObjCInferCommandFrontendArc( public static ImmutableList<String> createObjCInferCommandFrontend(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException { String sourceFile) throws IOException, InterruptedException {
return createObjCInferCommandFrontend(folder, sourceFile, ImmutableList.<String>of());
}
public static ImmutableList<String> createObjCInferCommandFrontendArc(
TemporaryFolder folder,
String sourceFile,
ImmutableList<String> extraInferOptions) throws IOException, InterruptedException {
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
@ -402,12 +377,20 @@ public class InferRunner {
false, false,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
true); true,
extraInferOptions);
} }
public static ImmutableList<String> createObjCPPInferCommandFrontend( public static ImmutableList<String> createObjCInferCommandFrontendArc(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException { String sourceFile) throws IOException, InterruptedException {
return createObjCInferCommandFrontendArc(folder, sourceFile, ImmutableList.<String>of());
}
public static ImmutableList<String> createObjCPPInferCommandFrontend(
TemporaryFolder folder,
String sourceFile,
ImmutableList<String> extraInferOptions) throws IOException, InterruptedException {
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
@ -415,12 +398,20 @@ public class InferRunner {
false, false,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
false); false,
extraInferOptions);
}
public static ImmutableList<String> createObjCPPInferCommandFrontend(
TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException {
return createObjCPPInferCommandFrontend(folder, sourceFile, ImmutableList.<String>of());
} }
public static ImmutableList<String> createCInferCommand( public static ImmutableList<String> createCInferCommand(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) { String sourceFile,
ImmutableList<String> extraInferOptions) {
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
@ -428,12 +419,24 @@ public class InferRunner {
true, true,
null, null,
null, null,
false); false,
extraInferOptions);
} }
public static ImmutableList<String> createCPPInferCommand( public static ImmutableList<String> createCInferCommand(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) { String sourceFile) {
return createCInferCommand(folder, sourceFile, ImmutableList.<String>of());
}
public static ImmutableList<String> createCPPInferCommand(
TemporaryFolder folder,
String sourceFile,
ImmutableList<String> extraInferOptions) {
ImmutableList<String> args = new ImmutableList.Builder<String> ()
.add("--no-testing-mode")
.addAll(extraInferOptions)
.build();
return createClangInferCommand( return createClangInferCommand(
folder, folder,
sourceFile, sourceFile,
@ -442,23 +445,22 @@ public class InferRunner {
null, null,
null, null,
false, false,
false, args);
false); }
public static ImmutableList<String> createCPPInferCommand(
TemporaryFolder folder,
String sourceFile) {
return createCPPInferCommand(folder, sourceFile, ImmutableList.<String>of());
} }
public static ImmutableList<String> createCPPInferCommandIncludeHeaders( public static ImmutableList<String> createCPPInferCommandIncludeHeaders(
TemporaryFolder folder, TemporaryFolder folder,
String sourceFile) { String sourceFile) {
return createClangInferCommand( return createCPPInferCommand(
folder, folder,
sourceFile, sourceFile,
Language.CPP, ImmutableList.<String>of("--testing-mode", "--headers"));
true,
null,
null,
false,
true,
true);
} }
public static ImmutableList<String> createCPPInferCommandWithMLBuckets( public static ImmutableList<String> createCPPInferCommandWithMLBuckets(
@ -472,23 +474,8 @@ public class InferRunner {
true, true,
null, null,
ml_bucket, ml_bucket,
false);
}
public static ImmutableList<String> createCPPInferCommandFilter(
TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException {
return createClangInferCommand(
folder,
sourceFile,
Language.CPP,
true,
null,
null,
false,
false,
false, false,
true); ImmutableList.<String>of());
} }
public static ImmutableList<String> createObjCInferCommand( public static ImmutableList<String> createObjCInferCommand(
@ -501,7 +488,8 @@ public class InferRunner {
true, true,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
false); false,
ImmutableList.<String>of());
} }
public static ImmutableList<String> createObjCInferCommandSimple( public static ImmutableList<String> createObjCInferCommandSimple(
@ -515,7 +503,8 @@ public class InferRunner {
true, true,
null, null,
ml_bucket, ml_bucket,
false); false,
ImmutableList.<String>of());
} }
public static ImmutableList<String> createObjCInferCommandWithMLBuckets( public static ImmutableList<String> createObjCInferCommandWithMLBuckets(
@ -530,7 +519,8 @@ public class InferRunner {
true, true,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
ml_bucket, ml_bucket,
arc); arc,
ImmutableList.<String>of());
} }
public static ImmutableList<String> createObjCPPInferCommand( public static ImmutableList<String> createObjCPPInferCommand(
@ -543,7 +533,8 @@ public class InferRunner {
true, true,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
false); false,
ImmutableList.<String>of());
} }
public static ImmutableList<String> createiOSInferCommandFrontend( public static ImmutableList<String> createiOSInferCommandFrontend(
@ -556,7 +547,8 @@ public class InferRunner {
false, false,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
false); false,
ImmutableList.<String>of());
} }
public static ImmutableList<String> createiOSInferCommand( public static ImmutableList<String> createiOSInferCommand(
@ -569,7 +561,8 @@ public class InferRunner {
true, true,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null, null,
false); false,
ImmutableList.<String>of());
} }
public static ImmutableList<String> createiOSInferCommandWithMLBuckets( public static ImmutableList<String> createiOSInferCommandWithMLBuckets(
@ -584,7 +577,8 @@ public class InferRunner {
true, true,
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX, getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
bucket, bucket,
arc); arc,
ImmutableList.<String>of());
} }
@Nullable @Nullable

Loading…
Cancel
Save