Search in sources :

Example 21 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithoutDeps.

@Test
public void testInferCxxBinaryWithoutDeps() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
    workspace.setupCxxSandboxing(sandboxSources);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
    BuildTarget inputBuildTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:simple");
    String inputBuildTargetName = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get()).getFullyQualifiedName();
    /*
     * Build the given target and check that it succeeds.
     */
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    /*
     * Check that all the required build targets have been generated.
     */
    String sourceName = "simple.cpp";
    String sourceFull = "foo/" + sourceName;
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), inputBuildTarget, cxxPlatform, cxxBuckConfig);
    // this is unflavored, but bounded to the InferCapture build rule
    BuildTarget captureBuildTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget(sourceName);
    // this is unflavored, but necessary to run the compiler successfully
    BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(inputBuildTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget sandboxTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(inputBuildTarget, cxxPlatform.getFlavor());
    // this is flavored, and denotes the analysis step (generates a local report)
    BuildTarget inferAnalysisTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    // this is flavored and corresponds to the top level target (the one give in input to buck)
    BuildTarget inferReportTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
    BuildTarget aggregatedDepsTarget = cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    ImmutableSortedSet.Builder<BuildTarget> targetsBuilder = ImmutableSortedSet.<BuildTarget>naturalOrder().add(aggregatedDepsTarget, headerSymlinkTreeTarget, captureBuildTarget, inferAnalysisTarget, inferReportTarget);
    if (sandboxSources) {
        targetsBuilder.add(sandboxTreeTarget);
    }
    BuckBuildLog buildLog = workspace.getBuildLog();
    assertThat(buildLog.getAllTargets(), containsInAnyOrder(targetsBuilder.build().toArray()));
    buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
    buildLog.assertTargetBuiltLocally(headerSymlinkTreeTarget.toString());
    buildLog.assertTargetBuiltLocally(captureBuildTarget.toString());
    buildLog.assertTargetBuiltLocally(inferAnalysisTarget.toString());
    buildLog.assertTargetBuiltLocally(inferReportTarget.toString());
    /*
     * Check that running a build again results in no builds since nothing has changed.
     */
    // clear for new build
    workspace.resetBuildLogFile();
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    assertEquals(ImmutableSet.of(inferReportTarget), buildLog.getAllTargets());
    buildLog.assertTargetHadMatchingRuleKey(inferReportTarget.toString());
    /*
     * Check that changing the source file results in running the capture/analysis rules again.
     */
    workspace.resetBuildLogFile();
    workspace.replaceFileContents(sourceFull, "*s = 42;", "");
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    targetsBuilder = ImmutableSortedSet.<BuildTarget>naturalOrder().add(aggregatedDepsTarget, captureBuildTarget, inferAnalysisTarget, inferReportTarget);
    if (sandboxSources) {
        targetsBuilder.add(headerSymlinkTreeTarget, sandboxTreeTarget);
    }
    assertEquals(buildLog.getAllTargets(), targetsBuilder.build());
    buildLog.assertTargetBuiltLocally(captureBuildTarget.toString());
    buildLog.assertTargetBuiltLocally(inferAnalysisTarget.toString());
    if (sandboxSources) {
        buildLog.assertTargetHadMatchingRuleKey(headerSymlinkTreeTarget.toString());
        buildLog.assertTargetHadMatchingInputRuleKey(sandboxTreeTarget.toString());
        buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
    } else {
        buildLog.assertTargetHadMatchingRuleKey(aggregatedDepsTarget.toString());
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Test(org.junit.Test)

Example 22 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class DefaultJavaLibraryTest method createDefaultJavaLibraryRuleWithAbiKey.

private BuildRule createDefaultJavaLibraryRuleWithAbiKey(BuildTarget buildTarget, ImmutableSet<String> srcs, ImmutableSortedSet<BuildRule> deps, ImmutableSortedSet<BuildRule> exportedDeps, Optional<AbstractJavacOptions.SpoolMode> spoolMode, ImmutableList<String> postprocessClassesCommands) {
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    ImmutableSortedSet<? extends SourcePath> srcsAsPaths = FluentIterable.from(srcs).transform(Paths::get).transform(p -> new PathSourcePath(projectFilesystem, p)).toSortedSet(Ordering.natural());
    BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.copyOf(deps)).build();
    JavacOptions javacOptions = spoolMode.isPresent() ? JavacOptions.builder(DEFAULT_JAVAC_OPTIONS).setSpoolMode(spoolMode.get()).build() : DEFAULT_JAVAC_OPTIONS;
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(buildRuleParams, new SourcePathResolver(ruleFinder), ruleFinder, srcsAsPaths, /* resources */
    ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
    Optional.empty(), postprocessClassesCommands, exportedDeps, /* providedDeps */
    ImmutableSortedSet.of(), ImmutableSortedSet.of(), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
    ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), /* resourcesRoot */
    Optional.empty(), /* manifest file */
    Optional.empty(), /* mavenCoords */
    Optional.empty(), /* tests */
    ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of()) {
    };
    ruleResolver.addToIndex(defaultJavaLibrary);
    return defaultJavaLibrary;
}
Also used : FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) StepRunner(com.facebook.buck.step.StepRunner) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RichStream(com.facebook.buck.util.RichStream) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) Ansi(com.facebook.buck.util.Ansi) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ByteArrayInputStream(java.io.ByteArrayInputStream) RuleKey(com.facebook.buck.rules.RuleKey) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Assert.fail(org.junit.Assert.fail) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) Verbosity(com.facebook.buck.util.Verbosity) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidLibraryBuilder(com.facebook.buck.android.AndroidLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) DEFAULT_JAVAC_OPTIONS(com.facebook.buck.jvm.java.JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS) BuildTarget(com.facebook.buck.model.BuildTarget) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) EasyMock.createNiceMock(org.easymock.EasyMock.createNiceMock) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ZipOutputStream(java.util.zip.ZipOutputStream) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Hashing(com.google.common.hash.Hashing) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) LinkOption(java.nio.file.LinkOption) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) MoreAsserts(com.facebook.buck.testutil.MoreAsserts) ImmutableList(com.google.common.collect.ImmutableList) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) Suppliers(com.google.common.base.Suppliers) EasyMock.replay(org.easymock.EasyMock.replay) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) Assert.assertNotNull(org.junit.Assert.assertNotNull) TargetNode(com.facebook.buck.rules.TargetNode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) Console(com.facebook.buck.util.Console) EasyMock(org.easymock.EasyMock) HumanReadableException(com.facebook.buck.util.HumanReadableException) File(java.io.File) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) FileHashCache(com.facebook.buck.util.cache.FileHashCache) BuildContext(com.facebook.buck.rules.BuildContext) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Paths(java.nio.file.Paths)

Example 23 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class LuaBinaryDescriptionTest method platformDeps.

@Test
public void platformDeps() throws Exception {
    FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2, PY3);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(FakeBuckConfig.builder().build());
    CxxLibraryBuilder py2LibBuilder = new CxxLibraryBuilder(PYTHON2_DEP_TARGET);
    CxxLibraryBuilder py3LibBuilder = new CxxLibraryBuilder(PYTHON3_DEP_TARGET);
    CxxLibraryBuilder py2CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py2_library")).setSoname("libpy2.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    CxxLibraryBuilder py3CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py3_library")).setSoname("libpy3.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    CxxPythonExtensionBuilder cxxPythonExtensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:extension"), pythonPlatforms, cxxBuckConfig, CxxTestBuilder.createDefaultPlatforms()).setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(py2CxxLibraryBuilder.getTarget())).add(Pattern.compile(PY3.getFlavor().toString()), ImmutableSortedSet.of(py3CxxLibraryBuilder.getTarget())).build());
    LuaBinaryBuilder luaBinaryBuilder = new LuaBinaryBuilder(new LuaBinaryDescription(FakeLuaConfig.DEFAULT, cxxBuckConfig, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS, pythonPlatforms), BuildTargetFactory.newInstance("//:binary")).setMainModule("main").setDeps(ImmutableSortedSet.of(cxxPythonExtensionBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(py2LibBuilder.build(), py3LibBuilder.build(), py2CxxLibraryBuilder.build(), py3CxxLibraryBuilder.build(), cxxPythonExtensionBuilder.build(), luaBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    py2LibBuilder.build(resolver);
    py3LibBuilder.build(resolver);
    py2CxxLibraryBuilder.build(resolver);
    py3CxxLibraryBuilder.build(resolver);
    cxxPythonExtensionBuilder.build(resolver);
    LuaBinary luaBinary = luaBinaryBuilder.build(resolver);
    LuaPackageComponents components = luaBinary.getComponents();
    assertThat(components.getNativeLibraries().keySet(), Matchers.hasItem("libpy2.so"));
    assertThat(components.getNativeLibraries().keySet(), Matchers.not(Matchers.hasItem("libpy3.so")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) CxxPythonExtensionBuilder(com.facebook.buck.python.CxxPythonExtensionBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) PythonPlatform(com.facebook.buck.python.PythonPlatform) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 24 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class AbstractNodeBuilder method getDepsFromArg.

@SuppressWarnings("unchecked")
private ImmutableSortedSet<BuildTarget> getDepsFromArg() {
    // Grab them in the unsafest way I know.
    try {
        Field depsField = arg.getClass().getField("deps");
        Object deps = depsField.get(arg);
        if (deps == null) {
            return ImmutableSortedSet.of();
        }
        // Here's a whole series of assumptions in one lump of a Bad Idea.
        return (ImmutableSortedSet<BuildTarget>) deps;
    } catch (ReflectiveOperationException ignored) {
        // Field doesn't exist: no deps.
        return ImmutableSortedSet.of();
    }
}
Also used : Field(java.lang.reflect.Field) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet)

Example 25 with ImmutableSortedSet

use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.

the class ClasspathMacroExpanderTest method extractRuleKeyAppendables.

@Test
public void extractRuleKeyAppendables() throws Exception {
    TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:dep")).addSrc(Paths.get("Dep.java")).build();
    TargetNode<?, ?> ruleNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:target")).addSrc(Paths.get("Other.java")).addDep(depNode.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, ruleNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule rule = ruleResolver.requireRule(ruleNode.getBuildTarget());
    BuildRule dep = ruleResolver.requireRule(depNode.getBuildTarget());
    BuildTarget forTarget = BuildTargetFactory.newInstance("//:rule");
    Object ruleKeyAppendables = expander.extractRuleKeyAppendables(forTarget, createCellRoots(filesystem), ruleResolver, ImmutableList.of(rule.getBuildTarget().toString()));
    assertThat(ruleKeyAppendables, Matchers.instanceOf(ImmutableSortedSet.class));
    Set<BuildTarget> seenBuildTargets = new LinkedHashSet<>();
    for (Object appendable : ((ImmutableSortedSet<?>) ruleKeyAppendables)) {
        assertThat(appendable, Matchers.instanceOf(BuildTargetSourcePath.class));
        seenBuildTargets.add(((BuildTargetSourcePath<?>) appendable).getTarget());
    }
    assertThat(seenBuildTargets, Matchers.equalTo(ImmutableSortedSet.of(rule.getBuildTarget(), dep.getBuildTarget())));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Test(org.junit.Test)

Aggregations

ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)51 BuildTarget (com.facebook.buck.model.BuildTarget)26 BuildRule (com.facebook.buck.rules.BuildRule)26 Path (java.nio.file.Path)25 SourcePath (com.facebook.buck.rules.SourcePath)22 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 ImmutableList (com.google.common.collect.ImmutableList)21 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)19 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 Optional (java.util.Optional)17 ImmutableSet (com.google.common.collect.ImmutableSet)16 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)15 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 Map (java.util.Map)13 Flavor (com.facebook.buck.model.Flavor)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 IOException (java.io.IOException)12 Preconditions (com.google.common.base.Preconditions)11 Suppliers (com.google.common.base.Suppliers)10 TargetGraph (com.facebook.buck.rules.TargetGraph)9