Search in sources :

Example 1 with NoopBuildRule

use of com.facebook.buck.rules.NoopBuildRule in project buck by facebook.

the class GoTestDescription method createTestMainRule.

private GoBinary createTestMainRule(BuildRuleParams params, final BuildRuleResolver resolver, Arg args, GoPlatform platform) throws NoSuchBuildTargetException {
    Path packageName = getGoPackageName(resolver, params.getBuildTarget(), args);
    BuildRuleParams testTargetParams = params.withAppendedFlavor(TEST_LIBRARY_FLAVOR);
    BuildRule testLibrary = new NoopBuildRule(testTargetParams);
    resolver.addToIndex(testLibrary);
    BuildRule generatedTestMain = requireTestMainGenRule(params, resolver, args.srcs, packageName);
    GoBinary testMain = GoDescriptors.createGoBinaryRule(params.withAppendedFlavor(InternalFlavor.of("test-main")).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of(generatedTestMain))), resolver, goBuckConfig, ImmutableSet.of(generatedTestMain.getSourcePathToOutput()), args.compilerFlags, args.assemblerFlags, args.linkerFlags, platform);
    resolver.addToIndex(testMain);
    return testMain;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule)

Example 2 with NoopBuildRule

use of com.facebook.buck.rules.NoopBuildRule in project buck by facebook.

the class HalideLibraryDescription method createHalideStaticLibrary.

private BuildRule createHalideStaticLibrary(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxPlatform platform, Arg args) throws NoSuchBuildTargetException {
    if (!isPlatformSupported(args, platform)) {
        return new NoopBuildRule(params);
    }
    BuildRule halideCompile = ruleResolver.requireRule(params.getBuildTarget().withFlavors(HALIDE_COMPILE_FLAVOR, platform.getFlavor()));
    BuildTarget buildTarget = halideCompile.getBuildTarget();
    return Archive.from(params.getBuildTarget(), params, ruleFinder, platform, cxxBuckConfig.getArchiveContents(), CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), platform.getFlavor(), CxxSourceRuleFactory.PicType.PIC, platform.getStaticLibraryExtension()), ImmutableList.of(new ExplicitBuildTargetSourcePath(buildTarget, HalideCompile.objectOutputPath(buildTarget, params.getProjectFilesystem(), args.functionName))));
}
Also used : NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 3 with NoopBuildRule

use of com.facebook.buck.rules.NoopBuildRule in project buck by facebook.

the class CxxLibraryDescription method createStaticLibraryBuildRule.

/**
   * Create all build rules needed to generate the static library.
   *
   * @return build rule that builds the static library version of this C/C++ library.
   */
private static BuildRule createStaticLibraryBuildRule(BuildRuleParams params, BuildRuleResolver resolver, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, Arg args, CxxSourceRuleFactory.PicType pic) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    // Create rules for compiling the object files.
    ImmutableMap<CxxPreprocessAndCompile, SourcePath> objects = requireObjects(params, resolver, sourcePathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, pic, args);
    // Write a build rule to create the archive for this C/C++ library.
    BuildTarget staticTarget = CxxDescriptionEnhancer.createStaticLibraryBuildTarget(params.getBuildTarget(), cxxPlatform.getFlavor(), pic);
    if (objects.isEmpty()) {
        return new NoopBuildRule(new BuildRuleParams(staticTarget, Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()), params.getProjectFilesystem(), params.getCellRoots()));
    }
    Path staticLibraryPath = CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), cxxPlatform.getFlavor(), pic, cxxPlatform.getStaticLibraryExtension());
    return Archive.from(staticTarget, params, ruleFinder, cxxPlatform, cxxBuckConfig.getArchiveContents(), staticLibraryPath, ImmutableList.copyOf(objects.values()));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 4 with NoopBuildRule

use of com.facebook.buck.rules.NoopBuildRule in project buck by facebook.

the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges.

@Test
public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    final Path output = Paths.get("output");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
    BuildRule rule = new NoopBuildRule(params) {

        @AddToRuleKey
        RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output));
    };
    // Build a rule key with a particular hash set for the output for the above rule.
    FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));
    RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
    // Now, build a rule key with a different hash for the output for the above rule.
    hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));
    RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
    assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) 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) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 5 with NoopBuildRule

use of com.facebook.buck.rules.NoopBuildRule in project buck by facebook.

the class DefaultRuleKeyFactoryTest method testFactoryReportsInputsAndDependenciesToCacheForRuleKeyAppendable.

@Test
public void testFactoryReportsInputsAndDependenciesToCacheForRuleKeyAppendable() throws IOException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    NoopRuleKeyCache<RuleKey> noopRuleKeyCache = new NoopRuleKeyCache<>();
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder, noopRuleKeyCache);
    // Create a sample input.
    PathSourcePath input = new PathSourcePath(filesystem, filesystem.getPath("input"));
    filesystem.touch(input.getRelativePath());
    // Create a sample dep rule.
    BuildRule dep = new EmptyRule(BuildTargetFactory.newInstance("//:dep"));
    // Create a sample dep appendable.
    RuleKeyAppendable depAppendable = sink -> {
    };
    // Create a sample rule key appendable.
    RuleKeyAppendable appendable = sink -> {
        sink.setReflectively("input", input);
        sink.setReflectively("dep", dep);
        sink.setReflectively("depAppendable", depAppendable);
    };
    // Create a dummy build rule that uses the input.
    BuildRule rule = new NoopBuildRule(new FakeBuildRuleParamsBuilder("//:target").setProjectFilesystem(filesystem).build()) {

        @AddToRuleKey
        private final RuleKeyAppendable appendableField = appendable;
    };
    // Build the rule key.
    factory.build(rule);
    // Verify the input was properly reported to the rule key cache.
    RuleKeyResult<RuleKey> result = noopRuleKeyCache.results.get(appendable);
    assertThat(result, Matchers.notNullValue());
    assertThat(result.inputs, Matchers.containsInAnyOrder(RuleKeyInput.of(filesystem, input.getRelativePath())));
    assertThat(result.deps, Matchers.containsInAnyOrder(dep, depAppendable));
}
Also used : Arrays(java.util.Arrays) BuildRuleType(com.facebook.buck.rules.BuildRuleType) LIBRARY(com.facebook.buck.rules.BuildableProperties.Kind.LIBRARY) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourceRoot(com.facebook.buck.rules.SourceRoot) RuleKeyAppendable(com.facebook.buck.rules.RuleKeyAppendable) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Objects(com.google.common.base.Objects) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ImmutableMap(com.google.common.collect.ImmutableMap) BuildableProperties(com.facebook.buck.rules.BuildableProperties) BuildableContext(com.facebook.buck.rules.BuildableContext) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) BuildTarget(com.facebook.buck.model.BuildTarget) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) CacheStats(com.google.common.cache.CacheStats) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) Function(java.util.function.Function) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) Suppliers(com.google.common.base.Suppliers) Nullable(javax.annotation.Nullable) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Paths(java.nio.file.Paths) FileHashCache(com.facebook.buck.util.cache.FileHashCache) BuildContext(com.facebook.buck.rules.BuildContext) Preconditions(com.google.common.base.Preconditions) MapMaker(com.google.common.collect.MapMaker) Assert.assertEquals(org.junit.Assert.assertEquals) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) 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) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) RuleKeyAppendable(com.facebook.buck.rules.RuleKeyAppendable) Test(org.junit.Test)

Aggregations

NoopBuildRule (com.facebook.buck.rules.NoopBuildRule)8 BuildRule (com.facebook.buck.rules.BuildRule)7 SourcePath (com.facebook.buck.rules.SourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 Path (java.nio.file.Path)6 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)5 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 Test (org.junit.Test)5 BuildTarget (com.facebook.buck.model.BuildTarget)4 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)4 PathSourcePath (com.facebook.buck.rules.PathSourcePath)4 RuleKey (com.facebook.buck.rules.RuleKey)4 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)3 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)3 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)3 FileHashCache (com.facebook.buck.util.cache.FileHashCache)3