Search in sources :

Example 1 with FakeOnDiskBuildInfo

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

the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsSpecified.

@Test
public void testGetRDotJavaPackageWhenPackageIsSpecified() throws IOException {
    ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
    BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
    ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
    "com.example.android", /* assets */
    null, /* assetsSrcs */
    ImmutableSortedMap.of(), /* manifestFile */
    null, /* hasWhitelistedStrings */
    false);
    projectFilesystem.writeContentsToPath("com.example.android\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
    FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
    androidResource.initializeFromDisk(onDiskBuildInfo);
    assertEquals("com.example.android", androidResource.getRDotJavaPackage());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 2 with FakeOnDiskBuildInfo

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

the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsNotSpecified.

@Test
public void testGetRDotJavaPackageWhenPackageIsNotSpecified() throws IOException {
    ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
    BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
    ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
    null, /* assets */
    null, /* assetsSrcs */
    ImmutableSortedMap.of(), /* manifestFile */
    new PathSourcePath(projectFilesystem, Paths.get("foo/AndroidManifest.xml")), /* hasWhitelistedStrings */
    false);
    projectFilesystem.writeContentsToPath("com.ex.pkg\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
    FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
    androidResource.initializeFromDisk(onDiskBuildInfo);
    assertEquals("com.ex.pkg", androidResource.getRDotJavaPackage());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 3 with FakeOnDiskBuildInfo

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method getOutputDoesNotAccessWrappedJavaLibrary.

@Test
public void getOutputDoesNotAccessWrappedJavaLibrary() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    JavaLibrary javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).build(ruleResolver);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:target")).build();
    DexProducedFromJavaLibrary dexProducedFromJavaLibrary = new DexProducedFromJavaLibrary(params, javaLibrary);
    ObjectMapper mapper = ObjectMappers.newDefaultInstance();
    FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo().putMetadata(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "0").putMetadata(DexProducedFromJavaLibrary.CLASSNAMES_TO_HASHES, mapper.writeValueAsString(ImmutableMap.<String, String>of()));
    initialize(dexProducedFromJavaLibrary, onDiskBuildInfo);
    assertFalse(dexProducedFromJavaLibrary.hasOutput());
}
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) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with FakeOnDiskBuildInfo

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

the class TrimUberRDotJavaTest method doTrimingTest.

private void doTrimingTest(Optional<String> keepResourcePattern, String rDotJavaContentsAfterFiltering) throws IOException, InterruptedException {
    ProjectFilesystem filesystem = new ProjectFilesystem(tmpFolder.getRoot());
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    AaptPackageResources aaptPackageResources = new AaptPackageResources(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:aapt")).setProjectFilesystem(filesystem).build(), ruleFinder, resolver, null, new IdentityResourcesProvider(ImmutableList.of()), ImmutableList.of(), ImmutableSortedSet.of(), ImmutableSet.of(), Optional.empty(), false, false, /* includesVectorDrawables */
    false, EnumSet.noneOf(RType.class), null);
    resolver.addToIndex(aaptPackageResources);
    String rDotJavaContents = "package com.test;\n" + "\n" + "public class R {\n" + "  public static class string {\n" + "    public static final int my_first_resource=0x7f08005c;\n" + "    public static final int my_second_resource=0x7f083bc1;\n" + "    public static final int keep_resource=0x7f083bc2;\n" + "  }\n" + "}\n";
    Path rDotJavaPath = aaptPackageResources.getPathToGeneratedRDotJavaSrcFiles().resolve("com/test/R.java");
    filesystem.createParentDirs(rDotJavaPath);
    filesystem.writeContentsToPath(rDotJavaContents, rDotJavaPath);
    DexProducedFromJavaLibrary dexProducedFromJavaLibrary = new DexProducedFromJavaLibrary(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:dex")).setProjectFilesystem(filesystem).build(), new FakeJavaLibrary(BuildTargetFactory.newInstance("//:lib"), null));
    dexProducedFromJavaLibrary.getBuildOutputInitializer().setBuildOutput(dexProducedFromJavaLibrary.initializeFromDisk(new FakeOnDiskBuildInfo().putMetadata(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "1").putMetadata(DexProducedFromJavaLibrary.CLASSNAMES_TO_HASHES, "{}").putMetadata(DexProducedFromJavaLibrary.REFERENCED_RESOURCES, ImmutableList.of("com.test.my_first_resource"))));
    resolver.addToIndex(dexProducedFromJavaLibrary);
    TrimUberRDotJava trimUberRDotJava = new TrimUberRDotJava(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:trim")).setProjectFilesystem(filesystem).build(), aaptPackageResources, ImmutableList.of(dexProducedFromJavaLibrary), keepResourcePattern);
    resolver.addToIndex(trimUberRDotJava);
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
    BuildableContext buildableContext = new FakeBuildableContext();
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList<Step> steps = trimUberRDotJava.getBuildSteps(buildContext, buildableContext);
    for (Step step : steps) {
        step.execute(executionContext);
    }
    ZipInspector inspector = new ZipInspector(pathResolver.getAbsolutePath(trimUberRDotJava.getSourcePathToOutput()));
    inspector.assertFileContents("com/test/R.java", rDotJavaContentsAfterFiltering);
}
Also used : Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) Step(com.facebook.buck.step.Step) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuildableContext(com.facebook.buck.rules.BuildableContext) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)

Example 5 with FakeOnDiskBuildInfo

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

the class GenruleTest method createGenruleBuilderThatUsesWorkerMacro.

private GenruleBuilder createGenruleBuilderThatUsesWorkerMacro(BuildRuleResolver resolver) throws NoSuchBuildTargetException, IOException {
    /*
     * Produces a GenruleBuilder that when built produces a Genrule that uses a $(worker) macro
     * that corresponds to:
     *
     * genrule(
     *   name = 'genrule_with_worker',
     *   srcs = [],
     *   cmd = '$(worker :worker_rule) abc',
     *   out = 'output.txt',
     * )
     *
     * worker_tool(
     *   name = 'worker_rule',
     *   exe = ':my_exe',
     * )
     *
     * sh_binary(
     *   name = 'my_exe',
     *   main = 'bin/exe',
     * );
     */
    BuildRule shBinaryRule = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe")).setMain(new FakeSourcePath("bin/exe")).build(resolver);
    DefaultWorkerTool workerTool = WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule")).setExe(shBinaryRule.getBuildTarget()).build(resolver);
    workerTool.getBuildOutputInitializer().setBuildOutput(workerTool.initializeFromDisk(new FakeOnDiskBuildInfo().putMetadata(BuildInfo.MetadataKey.RULE_KEY, Hashing.sha1().hashLong(0).toString())));
    return GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule_with_worker")).setCmd("$(worker :worker_rule) abc").setOut("output.txt");
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo)

Aggregations

FakeOnDiskBuildInfo (com.facebook.buck.rules.FakeOnDiskBuildInfo)5 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)4 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)4 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 Test (org.junit.Test)3 FakeJavaLibrary (com.facebook.buck.jvm.java.FakeJavaLibrary)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)2 RType (com.facebook.buck.android.aapt.RDotTxtEntry.RType)1 DefaultJavaLibrary (com.facebook.buck.jvm.java.DefaultJavaLibrary)1 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)1 BuildContext (com.facebook.buck.rules.BuildContext)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildableContext (com.facebook.buck.rules.BuildableContext)1 FakeBuildContext (com.facebook.buck.rules.FakeBuildContext)1