Search in sources :

Example 46 with ImmutableList

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));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) PreprocessorFlags(com.facebook.buck.cxx.PreprocessorFlags) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) ExplicitCxxToolFlags(com.facebook.buck.cxx.ExplicitCxxToolFlags)

Example 47 with ImmutableList

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();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList)

Example 48 with ImmutableList

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();
}
Also used : Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) BufferedReader(java.io.BufferedReader) ResultType(com.facebook.buck.test.result.type.ResultType) TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 49 with ImmutableList

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()));
}
Also used : BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Step(com.facebook.buck.step.Step) HasRuntimeDeps(com.facebook.buck.rules.HasRuntimeDeps) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ResultType(com.facebook.buck.test.result.type.ResultType) SourcePath(com.facebook.buck.rules.SourcePath) Callable(java.util.concurrent.Callable) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) Lists(com.google.common.collect.Lists) Matcher(java.util.regex.Matcher) Label(com.facebook.buck.rules.Label) Tool(com.facebook.buck.rules.Tool) TestResults(com.facebook.buck.test.TestResults) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) TestResultSummary(com.facebook.buck.test.TestResultSummary) TestRule(com.facebook.buck.rules.TestRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) List(java.util.List) Stream(java.util.stream.Stream) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) BuildTargets(com.facebook.buck.model.BuildTargets) Joiner(com.google.common.base.Joiner) ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep)

Example 50 with ImmutableList

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();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1079 List (java.util.List)293 ArrayList (java.util.ArrayList)169 Test (org.junit.Test)161 Map (java.util.Map)152 Path (java.nio.file.Path)149 ImmutableMap (com.google.common.collect.ImmutableMap)127 IOException (java.io.IOException)112 Set (java.util.Set)99 ImmutableSet (com.google.common.collect.ImmutableSet)98 SourcePath (com.facebook.buck.rules.SourcePath)91 Optional (java.util.Optional)89 HashMap (java.util.HashMap)85 Step (com.facebook.buck.step.Step)76 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)71 Collectors (java.util.stream.Collectors)62 File (java.io.File)58 HashSet (java.util.HashSet)58 Nullable (javax.annotation.Nullable)54 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52