Search in sources :

Example 76 with FakeBuildRuleParamsBuilder

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

the class InputBasedRuleKeyFactoryTest method nestedSizeLimitExceptionHandled.

@Test
public void nestedSizeLimitExceptionHandled() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    Path inputFile = filesystem.getPath("input");
    filesystem.writeBytesToPath(new byte[1024], inputFile);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
    BuildRule rule = new NoopBuildRule(params) {

        @AddToRuleKey
        NestedRuleKeyAppendableWithInput input = new NestedRuleKeyAppendableWithInput(new PathSourcePath(filesystem, inputFile));
    };
    // Verify rule key isn't calculated.
    expectedException.expect(SizeLimiter.SizeLimitException.class);
    new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, 200).build(rule);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) 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) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) 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 77 with FakeBuildRuleParamsBuilder

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

the class WorkerToolDescriptionTest method createWorkerTool.

private static WorkerTool createWorkerTool(Integer maxWorkers) throws NoSuchBuildTargetException {
    TargetGraph targetGraph = TargetGraph.EMPTY;
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule shBinaryRule = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe")).setMain(new FakeSourcePath("bin/exe")).build(resolver);
    WorkerToolDescription.Arg args = new WorkerToolDescription.Arg();
    args.env = ImmutableMap.of();
    args.exe = shBinaryRule.getBuildTarget();
    args.args = Either.ofRight(ImmutableList.of());
    args.maxWorkers = Optional.of(maxWorkers);
    args.persistent = Optional.empty();
    Description<WorkerToolDescription.Arg> workerToolDescription = new WorkerToolDescription(FakeBuckConfig.builder().build());
    return (WorkerTool) workerToolDescription.createBuildRule(targetGraph, new FakeBuildRuleParamsBuilder("//arbitrary:target").build(), resolver, args);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 78 with FakeBuildRuleParamsBuilder

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testGetBuildStepsWhenThereAreClassesToDex.

@Test
public void testGetBuildStepsWhenThereAreClassesToDex() throws IOException, InterruptedException {
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeJavaLibrary javaLibraryRule = new FakeJavaLibrary(BuildTargetFactory.newInstance(filesystem.getRootPath(), "//foo:bar"), pathResolver, filesystem, ImmutableSortedSet.of()) {

        @Override
        public ImmutableSortedMap<String, HashCode> getClassNamesToHashes() {
            return ImmutableSortedMap.of("com/example/Foo", HashCode.fromString("cafebabe"));
        }
    };
    resolver.addToIndex(javaLibraryRule);
    Path jarOutput = BuildTargets.getGenPath(filesystem, javaLibraryRule.getBuildTarget(), "%s.jar");
    javaLibraryRule.setOutputFile(jarOutput.toString());
    BuildContext context = FakeBuildContext.withSourcePathResolver(pathResolver);
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    Path dexOutput = BuildTargets.getGenPath(filesystem, javaLibraryRule.getBuildTarget().withFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR), "%s.dex.jar");
    createFiles(filesystem, dexOutput.toString(), jarOutput.toString());
    BuildTarget buildTarget = BuildTargetFactory.newInstance(filesystem.getRootPath(), "//foo:bar#dex");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(filesystem).build();
    DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(params, javaLibraryRule);
    List<Step> steps = preDex.getBuildSteps(context, buildableContext);
    AndroidPlatformTarget androidPlatformTarget = createMock(AndroidPlatformTarget.class);
    expect(androidPlatformTarget.getDxExecutable()).andStubReturn(Paths.get("/usr/bin/dx"));
    EasyMock.replay(androidPlatformTarget);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
    String expectedDxCommand = String.format("%s --dex --no-optimize --force-jumbo --output %s %s", Paths.get("/usr/bin/dx"), filesystem.resolve(dexOutput), filesystem.resolve(jarOutput));
    MoreAsserts.assertSteps("Generate bar.dex.jar.", ImmutableList.of(String.format("rm -f %s", filesystem.resolve(dexOutput)), String.format("mkdir -p %s", filesystem.resolve(dexOutput).getParent()), "estimate_dex_weight", "(cd " + filesystem.getRootPath() + " && " + expectedDxCommand + ")", String.format("zip-scrub %s", dexOutput), "record_dx_success"), steps, executionContext);
    ((EstimateDexWeightStep) steps.get(2)).setWeightEstimateForTesting(250);
    Step recordArtifactAndMetadataStep = steps.get(5);
    int exitCode = recordArtifactAndMetadataStep.execute(executionContext).getExitCode();
    assertEquals(0, exitCode);
    assertEquals("The generated .dex.jar file should be in the set of recorded artifacts.", ImmutableSet.of(BuildTargets.getGenPath(filesystem, buildTarget, "%s.dex.jar")), buildableContext.getRecordedArtifacts());
    buildableContext.assertContainsMetadataMapping(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "250");
}
Also used : Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) EstimateDexWeightStep(com.facebook.buck.dalvik.EstimateDexWeightStep) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) HashCode(com.google.common.hash.HashCode) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) EstimateDexWeightStep(com.facebook.buck.dalvik.EstimateDexWeightStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 79 with FakeBuildRuleParamsBuilder

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testObserverMethods.

@Test
public void testObserverMethods() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    DefaultJavaLibrary accumulateClassNames = JavaLibraryBuilder.createBuilder("//foo:bar").build(resolver);
    accumulateClassNames.getBuildOutputInitializer().setBuildOutput(new JavaLibrary.Data(ImmutableSortedMap.of("com/example/Foo", HashCode.fromString("cafebabe"))));
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).build();
    DexProducedFromJavaLibrary preDexWithClasses = new DexProducedFromJavaLibrary(params, accumulateClassNames);
    assertNull(preDexWithClasses.getSourcePathToOutput());
    assertEquals(BuildTargets.getGenPath(params.getProjectFilesystem(), buildTarget, "%s.dex.jar"), preDexWithClasses.getPathToDex());
}
Also used : JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) Test(org.junit.Test)

Example 80 with FakeBuildRuleParamsBuilder

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method testGetBuildStepsWhenThereAreNoClassesToDex.

@Test
public void testGetBuildStepsWhenThereAreNoClassesToDex() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    DefaultJavaLibrary javaLibrary = JavaLibraryBuilder.createBuilder("//foo:bar").build(resolver);
    javaLibrary.getBuildOutputInitializer().setBuildOutput(new JavaLibrary.Data(ImmutableSortedMap.of()));
    BuildContext context = FakeBuildContext.NOOP_CONTEXT;
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#dex");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
    DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(params, javaLibrary);
    List<Step> steps = preDex.getBuildSteps(context, buildableContext);
    Path dexOutput = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s.dex.jar");
    ExecutionContext executionContext = TestExecutionContext.newBuilder().build();
    MoreAsserts.assertSteps("Do not generate a .dex.jar file.", ImmutableList.of(String.format("rm -f %s", projectFilesystem.resolve(dexOutput)), String.format("mkdir -p %s", projectFilesystem.resolve(dexOutput.getParent())), "record_empty_dx"), steps, executionContext);
    Step recordArtifactAndMetadataStep = steps.get(2);
    assertThat(recordArtifactAndMetadataStep.getShortName(), startsWith("record_"));
    int exitCode = recordArtifactAndMetadataStep.execute(executionContext).getExitCode();
    assertEquals(0, exitCode);
}
Also used : Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) EstimateDexWeightStep(com.facebook.buck.dalvik.EstimateDexWeightStep) Step(com.facebook.buck.step.Step) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)108 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)102 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)102 Test (org.junit.Test)94 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)87 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)78 BuildTarget (com.facebook.buck.model.BuildTarget)77 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)74 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)50 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)32 SourcePath (com.facebook.buck.rules.SourcePath)30 BuildRule (com.facebook.buck.rules.BuildRule)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)25 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)22 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 Step (com.facebook.buck.step.Step)17 RuleKey (com.facebook.buck.rules.RuleKey)16 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)15 ExecutionContext (com.facebook.buck.step.ExecutionContext)14