use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class SplitZipStepTest method testRequiredInPrimaryZipPredicateWithProguard.
@Test
public void testRequiredInPrimaryZipPredicateWithProguard() throws IOException {
List<String> linesInMappingFile = ImmutableList.of("foo.bar.MappedPrimary -> foo.bar.a:", "foo.bar.MappedSecondary -> foo.bar.b:", "foo.bar.UnmappedPrimary -> foo.bar.UnmappedPrimary:", "foo.bar.UnmappedSecondary -> foo.bar.UnmappedSecondary:", "foo.primary.MappedPackage -> x.a:", "foo.secondary.MappedPackage -> x.b:", "foo.primary.UnmappedPackage -> foo.primary.UnmappedPackage:");
List<String> linesInManifestFile = ImmutableList.of(// Actual primary dex classes.
"foo/bar/MappedPrimary", "foo/bar/UnmappedPrimary", // Red herrings!
"foo/bar/b", "x/b");
Path proguardConfigFile = Paths.get("the/configuration.txt");
Path proguardMappingFile = Paths.get("the/mapping.txt");
Path primaryDexClassesFile = Paths.get("the/manifest.txt");
ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
EasyMock.expect(projectFilesystem.readLines(primaryDexClassesFile)).andReturn(linesInManifestFile);
EasyMock.expect(projectFilesystem.readLines(proguardConfigFile)).andReturn(ImmutableList.of());
EasyMock.expect(projectFilesystem.readLines(proguardMappingFile)).andReturn(linesInMappingFile);
EasyMock.replay(projectFilesystem);
SplitZipStep splitZipStep = new SplitZipStep(projectFilesystem, /* inputPathsToSplit */
ImmutableSet.of(), /* secondaryJarMetaPath */
Paths.get(""), /* primaryJarPath */
Paths.get(""), /* secondaryJarDir */
Paths.get(""), /* secondaryJarPattern */
"", /* additionalDexStoreJarMetaPath */
Paths.get(""), /* additionalDexStoreJarDir */
Paths.get(""), /* proguardFullConfigFile */
Optional.of(proguardConfigFile), /* proguardMappingFile */
Optional.of(proguardMappingFile), false, new DexSplitMode(/* shouldSplitDex */
true, ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE, DexStore.JAR, /* linearAllocHardLimit */
4 * 1024 * 1024, /* primaryDexPatterns */
ImmutableSet.of("/primary/", "x/"), Optional.of(new FakeSourcePath("the/manifest.txt")), /* primaryDexScenarioFile */
Optional.empty(), /* isPrimaryDexScenarioOverflowAllowed */
false, /* secondaryDexHeadClassesFile */
Optional.empty(), /* secondaryDexTailClassesFile */
Optional.empty()), Optional.empty(), Optional.of(Paths.get("the/manifest.txt")), Optional.empty(), Optional.empty(), /* additionalDexStoreToJarPathMap */
ImmutableMultimap.of(), new APKModuleGraph(null, null, null), /* pathToReportDir */
Paths.get(""));
ProguardTranslatorFactory translatorFactory = ProguardTranslatorFactory.create(projectFilesystem, Optional.of(proguardConfigFile), Optional.of(proguardMappingFile), false);
Predicate<String> requiredInPrimaryZipPredicate = splitZipStep.createRequiredInPrimaryZipPredicate(translatorFactory, Suppliers.ofInstance(ImmutableList.of()));
assertTrue("Mapped class from primary list should be in primary.", requiredInPrimaryZipPredicate.apply("foo/bar/a.class"));
assertTrue("Unmapped class from primary list should be in primary.", requiredInPrimaryZipPredicate.apply("foo/bar/UnmappedPrimary.class"));
assertTrue("Mapped class from substring should be in primary.", requiredInPrimaryZipPredicate.apply("x/a.class"));
assertTrue("Unmapped class from substring should be in primary.", requiredInPrimaryZipPredicate.apply("foo/primary/UnmappedPackage.class"));
assertFalse("Mapped class with obfuscated name match should not be in primary.", requiredInPrimaryZipPredicate.apply("foo/bar/b.class"));
assertFalse("Unmapped class name should not randomly be in primary.", requiredInPrimaryZipPredicate.apply("foo/bar/UnmappedSecondary.class"));
assertFalse("Map class with obfuscated name substring should not be in primary.", requiredInPrimaryZipPredicate.apply("x/b.class"));
EasyMock.verify(projectFilesystem);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class SplitZipStepTest method testRequiredInPrimaryZipPredicate.
@Test
public void testRequiredInPrimaryZipPredicate() throws IOException {
Path primaryDexClassesFile = Paths.get("the/manifest.txt");
List<String> linesInManifestFile = ImmutableList.of("com/google/common/collect/ImmutableSortedSet", " com/google/common/collect/ImmutableSet", "# com/google/common/collect/ImmutableMap");
ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
EasyMock.expect(projectFilesystem.readLines(primaryDexClassesFile)).andReturn(linesInManifestFile);
EasyMock.replay(projectFilesystem);
SplitZipStep splitZipStep = new SplitZipStep(projectFilesystem, /* inputPathsToSplit */
ImmutableSet.of(), /* secondaryJarMetaPath */
Paths.get(""), /* primaryJarPath */
Paths.get(""), /* secondaryJarDir */
Paths.get(""), /* secondaryJarPattern */
"", /* additionalDexStoreJarMetaPath */
Paths.get(""), /* additionalDexStoreJarDir */
Paths.get(""), /* proguardFullConfigFile */
Optional.empty(), /* proguardMappingFile */
Optional.empty(), false, new DexSplitMode(/* shouldSplitDex */
true, ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE, DexStore.JAR, /* linearAllocHardLimit */
4 * 1024 * 1024, /* primaryDexPatterns */
ImmutableSet.of("List"), Optional.of(new FakeSourcePath("the/manifest.txt")), /* primaryDexScenarioFile */
Optional.empty(), /* isPrimaryDexScenarioOverflowAllowed */
false, /* secondaryDexHeadClassesFile */
Optional.empty(), /* secondaryDexTailClassesFile */
Optional.empty()), Optional.empty(), Optional.of(Paths.get("the/manifest.txt")), Optional.empty(), Optional.empty(), /* additionalDexStoreToJarPathMap */
ImmutableMultimap.of(), new APKModuleGraph(null, null, null), /* pathToReportDir */
Paths.get(""));
Predicate<String> requiredInPrimaryZipPredicate = splitZipStep.createRequiredInPrimaryZipPredicate(ProguardTranslatorFactory.createForTest(Optional.empty()), Suppliers.ofInstance(ImmutableList.of()));
assertTrue("com/google/common/collect/ImmutableSortedSet.class is listed in the manifest verbatim.", requiredInPrimaryZipPredicate.apply("com/google/common/collect/ImmutableSortedSet.class"));
assertTrue("com/google/common/collect/ImmutableSet.class is in the manifest with whitespace.", requiredInPrimaryZipPredicate.apply("com/google/common/collect/ImmutableSet.class"));
assertFalse("com/google/common/collect/ImmutableSet.class cannot have whitespace as param.", requiredInPrimaryZipPredicate.apply(" com/google/common/collect/ImmutableSet.class"));
assertFalse("com/google/common/collect/ImmutableMap.class is commented out.", requiredInPrimaryZipPredicate.apply("com/google/common/collect/ImmutableMap.class"));
assertFalse("com/google/common/collect/Iterables.class is not even mentioned.", requiredInPrimaryZipPredicate.apply("com/google/common/collect/Iterables.class"));
assertTrue("java/awt/List.class matches the substring 'List'.", requiredInPrimaryZipPredicate.apply("java/awt/List.class"));
assertFalse("Substring matching is case-sensitive.", requiredInPrimaryZipPredicate.apply("shiny/Glistener.class"));
EasyMock.verify(projectFilesystem);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ExternallyBuiltApplePackageTest method outputContainsCorrectExtension.
@Test
public void outputContainsCorrectExtension() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(this.resolver));
ExternallyBuiltApplePackage rule = new ExternallyBuiltApplePackage(params, config, new FakeSourcePath("Fake/Bundle/Location"), true);
resolver.addToIndex(rule);
assertThat(pathResolver.getRelativePath(Preconditions.checkNotNull(rule.getSourcePathToOutput())).toString(), endsWith(".api"));
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ExternallyBuiltApplePackageTest method commandContainsCorrectCommand.
@Test
public void commandContainsCorrectCommand() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(this.resolver));
ExternallyBuiltApplePackage rule = new ExternallyBuiltApplePackage(params, config, new FakeSourcePath("Fake/Bundle/Location"), true);
resolver.addToIndex(rule);
AbstractGenruleStep step = Iterables.getOnlyElement(Iterables.filter(rule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext()), AbstractGenruleStep.class));
assertThat(step.getScriptFileContents(TestExecutionContext.newInstance()), is(equalTo("echo $SDKROOT $OUT")));
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class AppleCxxPlatformsTest method constructCompileRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
String source = "source.cpp";
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
CxxPreprocessAndCompile rule;
switch(operation) {
case PREPROCESS_AND_COMPILE:
rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
break;
case COMPILE:
rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
break;
default:
throw new IllegalStateException();
}
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
Aggregations