use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class HaskellDescriptionUtils method createCompileRule.
/**
* Create a Haskell compile rule that compiles all the given haskell sources in one step and
* pulls interface files from all transitive haskell dependencies.
*/
private static HaskellCompileRule createCompileRule(BuildTarget target, final BuildRuleParams baseParams, final BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, ImmutableSet<BuildRule> deps, final CxxPlatform cxxPlatform, HaskellConfig haskellConfig, final Linker.LinkableDepType depType, Optional<String> main, Optional<HaskellPackageInfo> packageInfo, ImmutableList<String> flags, HaskellSources sources) throws NoSuchBuildTargetException {
final Map<BuildTarget, ImmutableList<String>> depFlags = new TreeMap<>();
final Map<BuildTarget, ImmutableList<SourcePath>> depIncludes = new TreeMap<>();
final ImmutableSortedMap.Builder<String, HaskellPackage> exposedPackagesBuilder = ImmutableSortedMap.naturalOrder();
final ImmutableSortedMap.Builder<String, HaskellPackage> packagesBuilder = ImmutableSortedMap.naturalOrder();
new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(deps) {
private final ImmutableSet<BuildRule> empty = ImmutableSet.of();
@Override
public Iterable<BuildRule> visit(BuildRule rule) throws NoSuchBuildTargetException {
ImmutableSet<BuildRule> ruleDeps = empty;
if (rule instanceof HaskellCompileDep) {
ruleDeps = rule.getDeps();
HaskellCompileInput compileInput = ((HaskellCompileDep) rule).getCompileInput(cxxPlatform, depType);
depFlags.put(rule.getBuildTarget(), compileInput.getFlags());
depIncludes.put(rule.getBuildTarget(), compileInput.getIncludes());
// We add packages from first-order deps as expose modules, and transitively included
// packages as hidden ones.
boolean firstOrderDep = deps.contains(rule);
for (HaskellPackage pkg : compileInput.getPackages()) {
if (firstOrderDep) {
exposedPackagesBuilder.put(pkg.getInfo().getIdentifier(), pkg);
} else {
packagesBuilder.put(pkg.getInfo().getIdentifier(), pkg);
}
}
}
return ruleDeps;
}
}.start();
Collection<CxxPreprocessorInput> cxxPreprocessorInputs = CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, deps);
ExplicitCxxToolFlags.Builder toolFlagsBuilder = CxxToolFlags.explicitBuilder();
PreprocessorFlags.Builder ppFlagsBuilder = PreprocessorFlags.builder();
toolFlagsBuilder.setPlatformFlags(CxxSourceTypes.getPlatformPreprocessFlags(cxxPlatform, CxxSource.Type.C));
for (CxxPreprocessorInput input : cxxPreprocessorInputs) {
ppFlagsBuilder.addAllIncludes(input.getIncludes());
ppFlagsBuilder.addAllFrameworkPaths(input.getFrameworks());
toolFlagsBuilder.addAllRuleFlags(input.getPreprocessorFlags().get(CxxSource.Type.C));
}
ppFlagsBuilder.setOtherFlags(toolFlagsBuilder.build());
PreprocessorFlags ppFlags = ppFlagsBuilder.build();
ImmutableList<String> compileFlags = ImmutableList.<String>builder().addAll(haskellConfig.getCompilerFlags()).addAll(flags).addAll(Iterables.concat(depFlags.values())).build();
ImmutableList<SourcePath> includes = ImmutableList.copyOf(Iterables.concat(depIncludes.values()));
ImmutableSortedMap<String, HaskellPackage> exposedPackages = exposedPackagesBuilder.build();
ImmutableSortedMap<String, HaskellPackage> packages = packagesBuilder.build();
return HaskellCompileRule.from(target, baseParams, ruleFinder, haskellConfig.getCompiler().resolve(resolver), haskellConfig.getHaskellVersion(), compileFlags, ppFlags, cxxPlatform, depType == Linker.LinkableDepType.STATIC ? CxxSourceRuleFactory.PicType.PDC : CxxSourceRuleFactory.PicType.PIC, main, packageInfo, includes, exposedPackages, packages, sources, CxxSourceTypes.getPreprocessor(cxxPlatform, CxxSource.Type.C).resolve(resolver));
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class GoLinkStep method getShellCommandInternal.
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
ImmutableList.Builder<String> command = ImmutableList.<String>builder().addAll(linkCommandPrefix).addAll(flags).add("-o", output.toString()).add("-buildmode", linkMode.getBuildMode());
for (Path libraryPath : libraryPaths) {
command.add("-L", libraryPath.toString());
}
if (cxxLinkCommandPrefix.size() > 0) {
command.add("-extld", cxxLinkCommandPrefix.get(0));
if (cxxLinkCommandPrefix.size() > 1) {
command.add("-extldflags", FluentIterable.from(cxxLinkCommandPrefix).skip(1).transform(Escaper.BASH_ESCAPER).join(Joiner.on(" ")));
}
} else {
command.add("-linkmode", "internal");
}
command.add(mainArchive.toString());
return command.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class GoTest method parseTestResults.
private ImmutableList<TestResultSummary> parseTestResults() throws IOException {
ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
try (BufferedReader reader = Files.newBufferedReader(getProjectFilesystem().resolve(getPathToTestResults()), Charsets.UTF_8)) {
Optional<String> currentTest = Optional.empty();
List<String> stdout = Lists.newArrayList();
String line;
while ((line = reader.readLine()) != null) {
Matcher matcher;
if ((matcher = TEST_START_PATTERN.matcher(line)).matches()) {
currentTest = Optional.of(matcher.group("name"));
} else if ((matcher = TEST_FINISHED_PATTERN.matcher(line)).matches()) {
if (!currentTest.orElse("").equals(matcher.group("name"))) {
throw new RuntimeException(String.format("Error parsing test output: test case end '%s' does not match start '%s'", matcher.group("name"), currentTest.orElse("")));
}
ResultType result = ResultType.FAILURE;
if ("PASS".equals(matcher.group("status"))) {
result = ResultType.SUCCESS;
} else if ("SKIP".equals(matcher.group("status"))) {
result = ResultType.ASSUMPTION_VIOLATION;
}
double timeTaken = 0.0;
try {
timeTaken = Float.parseFloat(matcher.group("duration"));
} catch (NumberFormatException ex) {
Throwables.throwIfUnchecked(ex);
}
summariesBuilder.add(new TestResultSummary("go_test", matcher.group("name"), result, (long) (timeTaken * 1000), "", "", Joiner.on(System.lineSeparator()).join(stdout), ""));
currentTest = Optional.empty();
stdout.clear();
} else {
stdout.add(line);
}
}
if (currentTest.isPresent()) {
// This can happen in case of e.g. a panic.
summariesBuilder.add(new TestResultSummary("go_test", currentTest.get(), ResultType.FAILURE, 0, "incomplete", "", Joiner.on(System.lineSeparator()).join(stdout), ""));
}
}
return summariesBuilder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class GoTest method runTests.
@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
Optional<Long> processTimeoutMs = testRuleTimeoutMs.isPresent() ? Optional.of(testRuleTimeoutMs.get() + PROCESS_TIMEOUT_EXTRA_MS) : Optional.empty();
ImmutableList.Builder<String> args = ImmutableList.builder();
args.addAll(testMain.getExecutableCommand().getCommandPrefix(pathResolver));
args.add("-test.v");
if (testRuleTimeoutMs.isPresent()) {
args.add("-test.timeout", testRuleTimeoutMs.get() + "ms");
}
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToTestOutputDirectory()), new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToTestWorkingDirectory()), new SymlinkTreeStep(getProjectFilesystem(), getPathToTestWorkingDirectory(), ImmutableMap.copyOf(FluentIterable.from(resources).transform(input -> Maps.immutableEntry(getProjectFilesystem().getPath(pathResolver.getSourcePathName(getBuildTarget(), input)), pathResolver.getAbsolutePath(input))))), new GoTestStep(getProjectFilesystem(), getPathToTestWorkingDirectory(), args.build(), testMain.getExecutableCommand().getEnvironment(pathResolver), getPathToTestExitCode(), processTimeoutMs, getPathToTestResults()));
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.
the class GoTestMainStep method getShellCommandInternal.
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
ImmutableList.Builder<String> command = ImmutableList.<String>builder().addAll(generatorCommandPrefix).add("--output", output.toString()).add("--import-path", packageName.toString()).add("--cover-mode", coverageMode);
for (Map.Entry<Path, ImmutableMap<String, Path>> pkg : coverageVariables.entrySet()) {
if (pkg.getValue().isEmpty()) {
continue;
}
StringBuilder pkgFlag = new StringBuilder();
pkgFlag.append(pkg.getKey().toString());
pkgFlag.append(':');
boolean first = true;
for (Map.Entry<String, Path> pkgVars : pkg.getValue().entrySet()) {
if (!first) {
pkgFlag.append(',');
}
first = false;
pkgFlag.append(pkgVars.getKey());
pkgFlag.append('=');
pkgFlag.append(pkgVars.getValue().toString());
}
command.add("--cover-pkgs", pkgFlag.toString());
}
for (Path source : testFiles) {
command.add(source.toString());
}
return command.build();
}
Aggregations