Search in sources :

Example 36 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class FilterResourcesStepTest method fallsBackToDefaultWhenAllTargetsNotPresent.

@Test
public void fallsBackToDefaultWhenAllTargetsNotPresent() throws IOException, InterruptedException {
    final ResourceFilters.Density targetDensity = ResourceFilters.Density.MDPI;
    final ResourceFilters.Density providedDensity = ResourceFilters.Density.TVDPI;
    final String file = "somefile";
    final Path resDir = Paths.get("res/foo/bar");
    final Path resOutDir = Paths.get("res-out");
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    filesystem.mkdirs(resDir);
    for (String folderName : ResourceFilters.SUPPORTED_RESOURCE_DIRECTORIES) {
        if (folderName.equals("drawable") || folderName.equals("values")) {
            continue;
        }
        filesystem.createNewFile(resDir.resolve(folderName).resolve(file));
        filesystem.createNewFile(resDir.resolve(String.format("%s-%s", folderName, providedDensity)).resolve(file));
    }
    FilterResourcesStep command = new FilterResourcesStep(filesystem, ImmutableBiMap.of(resDir, resOutDir), /* filterByDPI */
    true, /* enableStringWhitelisting */
    false, /* whitelistedStringDirs */
    ImmutableSet.of(), /* locales */
    ImmutableSet.of(), DefaultFilteredDirectoryCopier.getInstance(), ImmutableSet.of(targetDensity), FilterResourcesStep.DefaultDrawableFinder.getInstance(), /* imageScaler */
    null);
    command.execute(null);
    for (String folderName : ResourceFilters.SUPPORTED_RESOURCE_DIRECTORIES) {
        if (folderName.equals("drawable") || folderName.equals("values")) {
            continue;
        }
        assertThat(filesystem, ProjectFilesystemMatchers.pathExists(resOutDir.resolve(folderName).resolve(file)));
        assertThat(filesystem, ProjectFilesystemMatchers.pathDoesNotExist(resOutDir.resolve(String.format("%s-%s", folderName, targetDensity))));
        assertThat(filesystem, ProjectFilesystemMatchers.pathDoesNotExist(resOutDir.resolve(String.format("%s-%s", folderName, providedDensity)).resolve(file)));
    }
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 37 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class NdkCxxPlatformIntegrationTest method testWorkingDirectoryAndNdkHeaderPathsAreSanitized.

@Test
public void testWorkingDirectoryAndNdkHeaderPathsAreSanitized() throws IOException {
    ProjectWorkspace workspace = setupWorkspace("ndk_debug_paths");
    workspace.writeContentsToPath("[ndk]\n" + "  cpu_abis = arm, armv7, arm64, x86, x86_64\n" + "  gcc_version = 4.9\n" + "  app_platform = android-21\n", ".buckconfig");
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
    BuildTarget target = BuildTargetFactory.newInstance(String.format("//:lib#android-%s,static", arch));
    workspace.runBuckBuild(target.getFullyQualifiedName()).assertSuccess();
    Path lib = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "%s/lib" + target.getShortName() + ".a"));
    String contents = MorePaths.asByteSource(lib).asCharSource(Charsets.ISO_8859_1).read();
    // Verify that the working directory is sanitized.
    assertFalse(contents.contains(tmp.getRoot().toString()));
    // Verify that we don't have any references to the build toolchain in the debug info.
    for (NdkCxxPlatforms.Host host : NdkCxxPlatforms.Host.values()) {
        assertFalse(contents.contains(host.toString()));
    }
    // Verify that the NDK path is sanitized.
    assertFalse(contents.contains(getNdkRoot().toString()));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 38 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.

the class SmartDexingStepTest method testCreateDxStepForDxPseudoRuleWithDexOutput.

@Test
public void testCreateDxStepForDxPseudoRuleWithDexOutput() throws IOException {
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    ImmutableList<Path> filesToDex = ImmutableList.of(Paths.get("foo.dex.jar"), Paths.get("bar.dex.jar"));
    Path outputPath = Paths.get("classes.dex");
    EnumSet<DxStep.Option> dxOptions = EnumSet.noneOf(DxStep.Option.class);
    Step dxStep = SmartDexingStep.createDxStepForDxPseudoRule(filesystem, filesToDex, outputPath, dxOptions, Optional.empty(), Optional.empty());
    assertEquals(Joiner.on(" ").join("(cd", filesystem.getRootPath(), "&&", Paths.get("/usr/bin/dx"), "--dex --output", filesystem.resolve("classes.dex"), filesystem.resolve("foo.dex.jar"), filesystem.resolve("bar.dex.jar") + ")"), dxStep.getDescription(createMockedExecutionContext()));
    verifyAll();
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) CompositeStep(com.facebook.buck.step.CompositeStep) Test(org.junit.Test)

Example 39 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem 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 40 with ProjectFilesystem

use of com.facebook.buck.io.ProjectFilesystem 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)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42