Search in sources :

Example 96 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class DCompileBuildRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    Path output = context.getSourcePathResolver().getRelativePath(Preconditions.checkNotNull(getSourcePathToOutput()));
    buildableContext.recordArtifact(output);
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    ImmutableList.Builder<String> flagsBuilder = ImmutableList.builder();
    flagsBuilder.addAll(compilerFlags);
    for (DIncludes include : includes) {
        flagsBuilder.add("-I" + context.getSourcePathResolver().getAbsolutePath(include.getLinkTree()));
    }
    ImmutableList<String> flags = flagsBuilder.build();
    steps.add(new DCompileStep(getProjectFilesystem().getRootPath(), compiler.getEnvironment(context.getSourcePathResolver()), compiler.getCommandPrefix(context.getSourcePathResolver()), flags, context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()), context.getSourcePathResolver().getAllAbsolutePaths(sources)));
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Example 97 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class JavaSymbolFinder method possibleBuckFilesForSourceFile.

/**
   * Look at all the directories above a given source file, up to the project root, and return the
   * paths to any BUCK files that exist at those locations. These files are the only ones that could
   * define a rule that includes the given source file.
   */
private ImmutableList<Path> possibleBuckFilesForSourceFile(Path sourceFilePath) {
    ImmutableList.Builder<Path> possibleBuckFiles = ImmutableList.builder();
    Path dir = sourceFilePath.getParent();
    ParserConfig parserConfig = config.getView(ParserConfig.class);
    // For a source file like foo/bar/example.java, add paths like foo/bar/BUCK and foo/BUCK.
    while (dir != null) {
        Path buckFile = dir.resolve(parserConfig.getBuildFileName());
        if (projectFilesystem.isFile(buckFile)) {
            possibleBuckFiles.add(buckFile);
        }
        dir = dir.getParent();
    }
    // Finally, add ./BUCK in the root directory.
    Path rootBuckFile = Paths.get(parserConfig.getBuildFileName());
    if (projectFilesystem.exists(rootBuckFile)) {
        possibleBuckFiles.add(rootBuckFile);
    }
    return possibleBuckFiles.build();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) ParserConfig(com.facebook.buck.parser.ParserConfig)

Example 98 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class JavaTest method runTests.

/**
   * Runs the tests specified by the "srcs" of this class. If this rule transitively depends on
   * other {@code java_test()} rules, then they will be run separately.
   */
@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
    // If no classes were generated, then this is probably a java_test() that declares a number of
    // other java_test() rules as deps, functioning as a test suite. In this case, simply return an
    // empty list of commands.
    Set<String> testClassNames = getClassNamesForSources(pathResolver);
    LOG.debug("Testing these classes: %s", testClassNames.toString());
    if (testClassNames.isEmpty()) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Path pathToTestOutput = getPathToTestOutputDirectory();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
    if (forkMode() == ForkMode.PER_TEST) {
        ImmutableList.Builder<JUnitStep> junitsBuilder = ImmutableList.builder();
        for (String testClass : testClassNames) {
            junitsBuilder.add(getJUnitStep(executionContext, pathResolver, options, Optional.of(pathToTestOutput), Optional.of(pathToTestLogs), Collections.singleton(testClass)));
        }
        junits = junitsBuilder.build();
    } else {
        junits = ImmutableList.of(getJUnitStep(executionContext, pathResolver, options, Optional.of(pathToTestOutput), Optional.of(pathToTestLogs), testClassNames));
    }
    steps.addAll(junits);
    return steps.build();
}
Also used : Path(java.nio.file.Path) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 99 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class PythonPackagedBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Path binPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
    // Make sure the parent directory exists.
    steps.add(new MkdirStep(getProjectFilesystem(), binPath.getParent()));
    // Delete any other pex that was there (when switching between pex styles).
    steps.add(new RmStep(getProjectFilesystem(), binPath, RmStep.Mode.RECURSIVE));
    Path workingDirectory = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__working_directory");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), workingDirectory));
    SourcePathResolver resolver = context.getSourcePathResolver();
    // Generate and return the PEX build step.
    steps.add(new PexStep(getProjectFilesystem(), builder.getEnvironment(resolver), ImmutableList.<String>builder().addAll(builder.getCommandPrefix(resolver)).addAll(buildArgs).build(), pythonEnvironment.getPythonPath(), pythonEnvironment.getPythonVersion(), workingDirectory, binPath, mainModule, resolver.getMappedPaths(getComponents().getModules()), resolver.getMappedPaths(getComponents().getResources()), resolver.getMappedPaths(getComponents().getNativeLibraries()), ImmutableSet.copyOf(resolver.getAllAbsolutePaths(getComponents().getPrebuiltLibraries())), preloadLibraries, getComponents().isZipSafe().orElse(true)));
    // Record the executable package for caching.
    buildableContext.recordArtifact(binPath);
    return steps.build();
}
Also used : Path(java.nio.file.Path) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 100 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class PythonUtil method getAllComponents.

static PythonPackageComponents getAllComponents(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, final PythonPackageComponents packageComponents, final PythonPlatform pythonPlatform, CxxBuckConfig cxxBuckConfig, final CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, final NativeLinkStrategy nativeLinkStrategy, final ImmutableSet<BuildTarget> preloadDeps) throws NoSuchBuildTargetException {
    final PythonPackageComponents.Builder allComponents = new PythonPackageComponents.Builder(params.getBuildTarget());
    final Map<BuildTarget, CxxPythonExtension> extensions = new LinkedHashMap<>();
    final Map<BuildTarget, NativeLinkable> nativeLinkableRoots = new LinkedHashMap<>();
    final OmnibusRoots.Builder omnibusRoots = OmnibusRoots.builder(cxxPlatform, preloadDeps);
    // Add the top-level components.
    allComponents.addComponent(packageComponents, params.getBuildTarget());
    // Walk all our transitive deps to build our complete package that we'll
    // turn into an executable.
    new AbstractBreadthFirstThrowingTraversal<BuildRule, NoSuchBuildTargetException>(params.getDeps()) {

        private final ImmutableList<BuildRule> empty = ImmutableList.of();

        @Override
        public Iterable<BuildRule> visit(BuildRule rule) throws NoSuchBuildTargetException {
            Iterable<BuildRule> deps = empty;
            if (rule instanceof CxxPythonExtension) {
                CxxPythonExtension extension = (CxxPythonExtension) rule;
                NativeLinkTarget target = ((CxxPythonExtension) rule).getNativeLinkTarget(pythonPlatform);
                extensions.put(target.getBuildTarget(), extension);
                omnibusRoots.addIncludedRoot(target);
                List<BuildRule> cxxpydeps = new ArrayList<>();
                for (BuildRule dep : rule.getDeps()) {
                    if (dep instanceof CxxPythonExtension) {
                        cxxpydeps.add(dep);
                    }
                }
                deps = cxxpydeps;
            } else if (rule instanceof PythonPackagable) {
                PythonPackagable packagable = (PythonPackagable) rule;
                PythonPackageComponents comps = packagable.getPythonPackageComponents(pythonPlatform, cxxPlatform);
                allComponents.addComponent(comps, rule.getBuildTarget());
                if (comps.hasNativeCode(cxxPlatform)) {
                    for (BuildRule dep : rule.getDeps()) {
                        if (dep instanceof NativeLinkable) {
                            NativeLinkable linkable = (NativeLinkable) dep;
                            nativeLinkableRoots.put(linkable.getBuildTarget(), linkable);
                            omnibusRoots.addExcludedRoot(linkable);
                        }
                    }
                }
                deps = rule.getDeps();
            } else if (rule instanceof NativeLinkable) {
                NativeLinkable linkable = (NativeLinkable) rule;
                nativeLinkableRoots.put(linkable.getBuildTarget(), linkable);
                omnibusRoots.addPotentialRoot(linkable);
            }
            return deps;
        }
    }.start();
    // excluded native linkable roots.
    if (nativeLinkStrategy == NativeLinkStrategy.MERGED) {
        OmnibusRoots roots = omnibusRoots.build();
        OmnibusLibraries libraries = Omnibus.getSharedLibraries(params, ruleResolver, ruleFinder, cxxBuckConfig, cxxPlatform, extraLdflags, roots.getIncludedRoots().values(), roots.getExcludedRoots().values());
        // Otherwise, add it as a native library.
        for (Map.Entry<BuildTarget, OmnibusRoot> root : libraries.getRoots().entrySet()) {
            CxxPythonExtension extension = extensions.get(root.getKey());
            if (extension != null) {
                allComponents.addModule(extension.getModule(), root.getValue().getPath(), root.getKey());
            } else {
                NativeLinkTarget target = Preconditions.checkNotNull(roots.getIncludedRoots().get(root.getKey()), "%s: linked unexpected omnibus root: %s", params.getBuildTarget(), root.getKey());
                NativeLinkTargetMode mode = target.getNativeLinkTargetMode(cxxPlatform);
                String soname = Preconditions.checkNotNull(mode.getLibraryName().orElse(null), "%s: omnibus library for %s was built without soname", params.getBuildTarget(), root.getKey());
                allComponents.addNativeLibraries(Paths.get(soname), root.getValue().getPath(), root.getKey());
            }
        }
        // Add all remaining libraries as native libraries.
        for (OmnibusLibrary library : libraries.getLibraries()) {
            allComponents.addNativeLibraries(Paths.get(library.getSoname()), library.getPath(), params.getBuildTarget());
        }
    } else {
        // For regular linking, add all extensions via the package components interface.
        Map<BuildTarget, NativeLinkable> extensionNativeDeps = new LinkedHashMap<>();
        for (Map.Entry<BuildTarget, CxxPythonExtension> entry : extensions.entrySet()) {
            allComponents.addComponent(entry.getValue().getPythonPackageComponents(pythonPlatform, cxxPlatform), entry.getValue().getBuildTarget());
            extensionNativeDeps.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform).getNativeLinkTargetDeps(cxxPlatform), NativeLinkable::getBuildTarget));
        }
        // Add all the native libraries.
        ImmutableMap<BuildTarget, NativeLinkable> nativeLinkables = NativeLinkables.getTransitiveNativeLinkables(cxxPlatform, Iterables.concat(nativeLinkableRoots.values(), extensionNativeDeps.values()));
        for (NativeLinkable nativeLinkable : nativeLinkables.values()) {
            NativeLinkable.Linkage linkage = nativeLinkable.getPreferredLinkage(cxxPlatform);
            if (nativeLinkableRoots.containsKey(nativeLinkable.getBuildTarget()) || linkage != NativeLinkable.Linkage.STATIC) {
                ImmutableMap<String, SourcePath> libs = nativeLinkable.getSharedLibraries(cxxPlatform);
                for (Map.Entry<String, SourcePath> ent : libs.entrySet()) {
                    allComponents.addNativeLibraries(Paths.get(ent.getKey()), ent.getValue(), nativeLinkable.getBuildTarget());
                }
            }
        }
    }
    return allComponents.build();
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) NativeLinkTargetMode(com.facebook.buck.cxx.NativeLinkTargetMode) OmnibusRoot(com.facebook.buck.cxx.OmnibusRoot) LinkedHashMap(java.util.LinkedHashMap) OmnibusLibraries(com.facebook.buck.cxx.OmnibusLibraries) SourcePath(com.facebook.buck.rules.SourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) OmnibusRoots(com.facebook.buck.cxx.OmnibusRoots) BuildRule(com.facebook.buck.rules.BuildRule) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) SourceList(com.facebook.buck.rules.coercer.SourceList) List(java.util.List) OmnibusLibrary(com.facebook.buck.cxx.OmnibusLibrary) NativeLinkTarget(com.facebook.buck.cxx.NativeLinkTarget) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) LinkedHashMap(java.util.LinkedHashMap) 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