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());
}
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());
}
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());
}
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);
}
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");
}
Aggregations