Search in sources :

Example 36 with FakeSourcePath

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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 37 with FakeSourcePath

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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 38 with FakeSourcePath

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"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Test(org.junit.Test)

Example 39 with FakeSourcePath

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")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) Test(org.junit.Test)

Example 40 with FakeSourcePath

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();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)318 Test (org.junit.Test)297 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)188 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)188 BuildTarget (com.facebook.buck.model.BuildTarget)182 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)116 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)104 SourcePath (com.facebook.buck.rules.SourcePath)90 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)85 TargetGraph (com.facebook.buck.rules.TargetGraph)84 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)68 Path (java.nio.file.Path)67 BuildRule (com.facebook.buck.rules.BuildRule)52 PathSourcePath (com.facebook.buck.rules.PathSourcePath)48 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)46 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)45 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)45 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)35 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)25 NSString (com.dd.plist.NSString)24