Search in sources :

Example 41 with ProjectFilesystem

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

the class SplitZipStepTest method testNonObfuscatedBuild.

@Test
public void testNonObfuscatedBuild() throws IOException {
    Path proguardConfigFile = Paths.get("the/configuration.txt");
    Path proguardMappingFile = Paths.get("the/mapping.txt");
    ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
    EasyMock.expect(projectFilesystem.readLines(proguardConfigFile)).andReturn(ImmutableList.of("-dontobfuscate"));
    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"), /* primaryDexClassesFile */
    Optional.empty(), /* primaryDexScenarioFile */
    Optional.empty(), /* isPrimaryDexScenarioOverflowAllowed */
    false, /* secondaryDexHeadClassesFile */
    Optional.empty(), /* secondaryDexTailClassesFile */
    Optional.empty()), Optional.empty(), Optional.empty(), 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("Primary class should be in primary.", requiredInPrimaryZipPredicate.apply("primary.class"));
    assertFalse("Secondary class should be in secondary.", requiredInPrimaryZipPredicate.apply("secondary.class"));
    EasyMock.verify(projectFilesystem);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 42 with ProjectFilesystem

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

the class MergeAndroidResourcesSourcesTest method setUp.

@Before
public void setUp() throws Exception {
    filesystem = new ProjectFilesystem(tmp.getRoot().toPath());
    context = TestExecutionContext.newInstance();
    tmp.newFolder("res_in_1");
    tmp.newFolder("res_in_1", "values");
    tmp.newFolder("res_in_1", "drawable");
    tmp.newFile("res_in_1/drawable/one.png");
    tmp.newFolder("res_in_2");
    tmp.newFolder("res_in_2", "values");
    tmp.newFolder("res_in_2", "drawable");
    tmp.newFile("res_in_2/drawable/two.png");
    filesystem.writeContentsToPath(RESOURCES_XML_HEADER + "<string name=\"override_me\">one</string>\n" + "<string name=\"only_in_first\">first</string>\n" + RESOURCES_XML_FOOTER, Paths.get("res_in_1/values/strings.xml"));
    filesystem.writeContentsToPath(RESOURCES_XML_HEADER + "<string name=\"override_me\">two</string>\n" + "<string name=\"only_in_second\">second</string>\n" + RESOURCES_XML_FOOTER, Paths.get("res_in_2/values/strings.xml"));
    filesystem.writeContentsToPath("png, trust me", Paths.get("res_in_1/drawable/one.png"));
    filesystem.writeContentsToPath("png, trust me", Paths.get("res_in_2/drawable/two.png"));
}
Also used : ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Before(org.junit.Before)

Example 43 with ProjectFilesystem

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

the class ResourceFiltersTest method testCreateDensityFilterIncludesFallbackWhenTargetNotPresent.

@Test
public void testCreateDensityFilterIncludesFallbackWhenTargetNotPresent() throws IOException {
    for (String folderName : ResourceFilters.SUPPORTED_RESOURCE_DIRECTORIES) {
        if (folderName.equals("drawable")) {
            // Drawables are special and we have a different method for them.
            continue;
        }
        ProjectFilesystem filesystem = new FakeProjectFilesystem();
        Path include = Paths.get(folderName).resolve("somefile");
        filesystem.createNewFile(include);
        Path exclude = Paths.get(String.format("%s-ldpi/somefile", folderName));
        filesystem.createNewFile(exclude);
        Predicate<Path> predicate = ResourceFilters.createDensityFilter(filesystem, ImmutableSet.of(Density.MDPI));
        assertThat(predicate.apply(exclude), Matchers.is(false));
        assertThat(predicate.apply(include), Matchers.is(true));
    }
}
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 44 with ProjectFilesystem

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

the class RobolectricTestRuleTest method runtimeDepsIncludeTransitiveResources.

@Test
public void runtimeDepsIncludeTransitiveResources() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem(temporaryFolder.getRoot());
    BuildTarget genRuleTarget = BuildTargetFactory.newInstance("//:gen");
    TargetNode<?, ?> genRuleNode = GenruleBuilder.newGenruleBuilder(genRuleTarget).setOut("out").build();
    BuildTarget res2RuleTarget = BuildTargetFactory.newInstance("//:res2");
    TargetNode<?, ?> res2Node = AndroidResourceBuilder.createBuilder(res2RuleTarget).setRes(new DefaultBuildTargetSourcePath(genRuleTarget)).setRDotJavaPackage("foo.bar").build();
    BuildTarget robolectricBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base/robolectricTest:robolectricTest");
    TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(robolectricBuildTarget, filesystem).addDep(res2RuleTarget).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genRuleNode, res2Node, robolectricTestNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule genRule = resolver.requireRule(genRuleTarget);
    RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricBuildTarget);
    assertThat(robolectricTest.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(genRule.getBuildTarget()));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 45 with ProjectFilesystem

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

the class CompilationDatabaseIntegrationTest method testCreateCompilationDatabaseForAppleBinaryWithDeps.

@Test
public void testCreateCompilationDatabaseForAppleBinaryWithDeps() throws IOException {
    // buck build the #compilation-database.
    BuildTarget target = BuildTargetFactory.newInstance("//Apps/Weather:Weather#iphonesimulator-x86_64,compilation-database");
    Path compilationDatabase = workspace.buildAndReturnOutput(target.getFullyQualifiedName());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    // Parse the compilation_database.json file.
    Map<String, CxxCompilationDatabaseEntry> fileToEntry = CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
    ImmutableSet<String> frameworks = ImmutableSet.of(Paths.get("/System/Library/Frameworks/Foundation.framework").getParent().toString(), Paths.get("/System/Library/Frameworks/UIKit.framework").getParent().toString());
    String pathToPrivateHeaders = BuildTargets.getGenPath(filesystem, target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR), "%s.hmap").toString();
    String pathToPublicHeaders = BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//Libraries/EXExample:EXExample").withAppendedFlavors(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor()), "%s.hmap").toString();
    Iterable<String> includes = ImmutableList.of(pathToPrivateHeaders, pathToPublicHeaders, filesystem.getBuckPaths().getBuckOut().toString());
    assertFlags(filesystem, "Apps/Weather/Weather/EXViewController.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-" + sanitize("Weather/EXViewController.m.o"))), Paths.get("Weather/EXViewController.m.o"), /* isLibrary */
    false, fileToEntry, frameworks, includes);
    assertFlags(filesystem, "Apps/Weather/Weather/main.m", target.withFlavors(InternalFlavor.of("iphonesimulator-x86_64"), InternalFlavor.of("compile-" + sanitize("Weather/main.m.o"))), Paths.get("Weather/main.m.o"), /* isLibrary */
    false, fileToEntry, frameworks, includes);
}
Also used : Path(java.nio.file.Path) CxxCompilationDatabaseEntry(com.facebook.buck.cxx.CxxCompilationDatabaseEntry) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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