Search in sources :

Example 86 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class AbstractOcamlBuildContext method getYaccOutput.

protected FluentIterable<SourcePath> getYaccOutput(Iterable<SourcePath> yaccInputs) {
    return FluentIterable.from(yaccInputs).transformAndConcat(yaccInput -> {
        String yaccFileName = getSourcePathResolver().getAbsolutePath(yaccInput).getFileName().toString();
        ImmutableList.Builder<SourcePath> toReturn = ImmutableList.builder();
        toReturn.add(new PathSourcePath(getProjectFilesystem(), getGeneratedSourceDir().resolve(yaccFileName.replaceFirst(OcamlCompilables.OCAML_MLY_REGEX, OcamlCompilables.OCAML_ML))));
        toReturn.add(new PathSourcePath(getProjectFilesystem(), getGeneratedSourceDir().resolve(yaccFileName.replaceFirst(OcamlCompilables.OCAML_MLY_REGEX, OcamlCompilables.OCAML_MLI))));
        return toReturn.build();
    });
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableList(com.google.common.collect.ImmutableList) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Example 87 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class AndroidResourceTest method testRuleKeyForDifferentInputFilenames.

@Test
public void testRuleKeyForDifferentInputFilenames() throws Exception {
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base:res");
    Function<Path, BuildRuleResolver> createResourceRule = (Path resourcePath) -> {
        FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
        projectFilesystem.createNewFile(resourcePath);
        projectFilesystem.createNewFile(Paths.get("java/src/com/facebook/base/assets/drawable/B.xml"));
        TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(buildTarget, projectFilesystem).setRes(new FakeSourcePath(projectFilesystem, "java/src/com/facebook/base/res")).setRDotJavaPackage("com.facebook").setAssets(new FakeSourcePath(projectFilesystem, "java/src/com/facebook/base/assets")).setManifest(new PathSourcePath(projectFilesystem, Paths.get("java/src/com/facebook/base/AndroidManifest.xml"))).build();
        TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode);
        return new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    };
    FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("java/src/com/facebook/base/AndroidManifest.xml", "bbbbbbbbbb", "java/src/com/facebook/base/assets/drawable/B.xml", "aaaaaaaaaaaa", "java/src/com/facebook/base/res/drawable/A.xml", "dddddddddd", "java/src/com/facebook/base/res/drawable/C.xml", "eeeeeeeeee"));
    BuildRuleResolver resolver1 = createResourceRule.apply(Paths.get("java/src/com/facebook/base/res/drawable/A.xml"));
    BuildRuleResolver resolver2 = createResourceRule.apply(Paths.get("java/src/com/facebook/base/res/drawable/C.xml"));
    BuildRule androidResource1 = resolver1.requireRule(buildTarget);
    SourcePathRuleFinder ruleFinder1 = new SourcePathRuleFinder(resolver1);
    SourcePathResolver pathResolver1 = new SourcePathResolver(ruleFinder1);
    BuildRule androidResource2 = resolver2.requireRule(buildTarget);
    SourcePathRuleFinder ruleFinder2 = new SourcePathRuleFinder(resolver2);
    SourcePathResolver pathResolver2 = new SourcePathResolver(ruleFinder2);
    RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashCache, pathResolver1, ruleFinder1).build(androidResource1);
    RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashCache, pathResolver2, ruleFinder2).build(androidResource2);
    assertNotEquals("The two android_resource rules should have different rule keys.", ruleKey1, ruleKey2);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 88 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class ApkGenruleTest method testCreateAndRunApkGenrule.

@Test
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public void testCreateAndRunApkGenrule() throws IOException, NoSuchBuildTargetException {
    ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    FileSystem fileSystem = projectFilesystem.getRootPath().getFileSystem();
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    createSampleAndroidBinaryRule(ruleResolver, projectFilesystem);
    // From the Python object, create a ApkGenruleBuildRuleFactory to create a ApkGenrule.Builder
    // that builds a ApkGenrule from the Python object.
    BuildTargetParser parser = EasyMock.createNiceMock(BuildTargetParser.class);
    final BuildTarget apkTarget = BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:fb4a");
    EasyMock.expect(parser.parse(EasyMock.eq(":fb4a"), EasyMock.anyObject(BuildTargetPatternParser.class), EasyMock.anyObject())).andStubReturn(apkTarget);
    EasyMock.replay(parser);
    BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//src/com/facebook:sign_fb4a");
    ApkGenruleDescription description = new ApkGenruleDescription();
    ApkGenruleDescription.Arg arg = description.createUnpopulatedConstructorArg();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    arg.apk = new FakeInstallable(apkTarget, pathResolver).getBuildTarget();
    arg.bash = Optional.of("");
    arg.cmd = Optional.of("python signer.py $APK key.properties > $OUT");
    arg.cmdExe = Optional.of("");
    arg.type = Optional.empty();
    arg.out = "signed_fb4a.apk";
    arg.srcs = ImmutableList.of(new PathSourcePath(projectFilesystem, fileSystem.getPath("src/com/facebook/signer.py")), new PathSourcePath(projectFilesystem, fileSystem.getPath("src/com/facebook/key.properties")));
    arg.tests = ImmutableSortedSet.of();
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
    ApkGenrule apkGenrule = (ApkGenrule) description.createBuildRule(TargetGraph.EMPTY, params, ruleResolver, arg);
    ruleResolver.addToIndex(apkGenrule);
    // Verify all of the observers of the Genrule.
    String expectedApkOutput = projectFilesystem.resolve(projectFilesystem.getBuckPaths().getGenDir().toString() + "/src/com/facebook/sign_fb4a/sign_fb4a.apk").toString();
    assertEquals(expectedApkOutput, apkGenrule.getAbsoluteOutputFilePath(pathResolver));
    assertEquals("The apk that this rule is modifying must have the apk in its deps.", ImmutableSet.of(apkTarget.toString()), apkGenrule.getDeps().stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
    Iterable<Path> expectedInputsToCompareToOutputs = ImmutableList.of(fileSystem.getPath("src/com/facebook/signer.py"), fileSystem.getPath("src/com/facebook/key.properties"));
    MoreAsserts.assertIterablesEquals(expectedInputsToCompareToOutputs, pathResolver.filterInputsToCompareToOutput(apkGenrule.getSrcs()));
    // Verify that the shell commands that the genrule produces are correct.
    List<Step> steps = apkGenrule.getBuildSteps(buildContext, new FakeBuildableContext());
    assertEquals(6, steps.size());
    ExecutionContext executionContext = newEmptyExecutionContext();
    Step firstStep = steps.get(0);
    assertTrue(firstStep instanceof MakeCleanDirectoryStep);
    MakeCleanDirectoryStep mkdirCommand = (MakeCleanDirectoryStep) firstStep;
    Path mkdirDir = projectFilesystem.getBuckPaths().getGenDir().resolve("src/com/facebook/sign_fb4a");
    assertEquals("First command should make sure the output directory exists and is empty.", mkdirDir, mkdirCommand.getPath());
    Step secondStep = steps.get(1);
    assertTrue(secondStep instanceof MakeCleanDirectoryStep);
    MakeCleanDirectoryStep secondMkdirCommand = (MakeCleanDirectoryStep) secondStep;
    Path relativePathToTmpDir = projectFilesystem.getBuckPaths().getGenDir().resolve("src/com/facebook/sign_fb4a__tmp");
    assertEquals("Second command should make sure the temp directory exists.", relativePathToTmpDir, secondMkdirCommand.getPath());
    Step thirdStep = steps.get(2);
    assertTrue(thirdStep instanceof MakeCleanDirectoryStep);
    MakeCleanDirectoryStep thirdMkdirCommand = (MakeCleanDirectoryStep) thirdStep;
    Path relativePathToSrcDir = projectFilesystem.getBuckPaths().getGenDir().resolve("src/com/facebook/sign_fb4a__srcs");
    assertEquals("Third command should make sure the temp directory exists.", relativePathToSrcDir, thirdMkdirCommand.getPath());
    MkdirAndSymlinkFileStep linkSource1 = (MkdirAndSymlinkFileStep) steps.get(3);
    assertEquals(fileSystem.getPath("src/com/facebook/signer.py"), linkSource1.getSource());
    assertEquals(fileSystem.getPath(relativePathToSrcDir + "/signer.py"), linkSource1.getTarget());
    MkdirAndSymlinkFileStep linkSource2 = (MkdirAndSymlinkFileStep) steps.get(4);
    assertEquals(fileSystem.getPath("src/com/facebook/key.properties"), linkSource2.getSource());
    assertEquals(fileSystem.getPath(relativePathToSrcDir + "/key.properties"), linkSource2.getTarget());
    Step sixthStep = steps.get(5);
    assertTrue(sixthStep instanceof AbstractGenruleStep);
    AbstractGenruleStep genruleCommand = (AbstractGenruleStep) sixthStep;
    assertEquals("genrule", genruleCommand.getShortName());
    ImmutableMap<String, String> environmentVariables = genruleCommand.getEnvironmentVariables(executionContext);
    assertEquals(new ImmutableMap.Builder<String, String>().put("APK", projectFilesystem.resolve(BuildTargets.getGenPath(projectFilesystem, apkTarget, "%s.apk")).toString()).put("OUT", expectedApkOutput).build(), environmentVariables);
    Path scriptFilePath = genruleCommand.getScriptFilePath(executionContext);
    String scriptFileContents = genruleCommand.getScriptFileContents(executionContext);
    assertEquals(ImmutableList.of("/bin/bash", "-e", scriptFilePath.toString()), genruleCommand.getShellCommand(executionContext));
    assertEquals("python signer.py $APK key.properties > $OUT", scriptFileContents);
    EasyMock.verify(parser);
}
Also used : KeystoreBuilder(com.facebook.buck.jvm.java.KeystoreBuilder) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Step(com.facebook.buck.step.Step) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) FileSystem(java.nio.file.FileSystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuildTargetParser(com.facebook.buck.parser.BuildTargetParser) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildTargetPatternParser(com.facebook.buck.parser.BuildTargetPatternParser) Test(org.junit.Test)

Example 89 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class AndroidResourceDescriptionTest method testResourceRulesCreateSymlinkTrees.

@Test
public void testResourceRulesCreateSymlinkTrees() throws Exception {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem(tmpFolder.getRoot().toPath());
    filesystem.mkdirs(Paths.get("res"));
    filesystem.mkdirs(Paths.get("assets"));
    filesystem.createNewFile(Paths.get("res/file1.txt"));
    filesystem.createNewFile(Paths.get("res/thumbs.db"));
    filesystem.createNewFile(Paths.get("assets/file1.txt"));
    filesystem.createNewFile(Paths.get("assets/file2.txt"));
    filesystem.createNewFile(Paths.get("assets/file3.txt"));
    filesystem.createNewFile(Paths.get("assets/ignored"));
    filesystem.createNewFile(Paths.get("assets/picasa.ini"));
    BuildTarget target = BuildTargetFactory.newInstance("//:res");
    TargetNode<?, ?> targetNode = AndroidResourceBuilder.createBuilder(target, filesystem).setRDotJavaPackage("com.example").setRes(new PathSourcePath(filesystem, Paths.get("res"))).setAssets(ImmutableSortedMap.of("file1.txt", new PathSourcePath(filesystem, Paths.get("assets/file1.txt")), "file3.txt", new PathSourcePath(filesystem, Paths.get("assets/file3.txt")), "picasa.ini", new PathSourcePath(filesystem, Paths.get("assets/ignored")), "not_ignored", new PathSourcePath(filesystem, Paths.get("assets/CVS")))).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(targetNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    AndroidResource resource = (AndroidResource) resolver.requireRule(target);
    ImmutableList<BuildRule> deps = resource.getDeps().asList();
    assertThat(deps, hasSize(2));
    assertThat(deps.get(0).getBuildTarget(), is(equalTo(target.withAppendedFlavors(AndroidResourceDescription.ASSETS_SYMLINK_TREE_FLAVOR))));
    assertThat(((SymlinkTree) deps.get(0)).getLinks(), is(equalTo(ImmutableSortedMap.of(Paths.get("file1.txt"), new PathSourcePath(filesystem, Paths.get("assets/file1.txt")), Paths.get("file3.txt"), new PathSourcePath(filesystem, Paths.get("assets/file3.txt")), Paths.get("not_ignored"), new PathSourcePath(filesystem, Paths.get("assets/CVS"))))));
    assertThat(deps.get(1).getBuildTarget(), is(equalTo(target.withAppendedFlavors(AndroidResourceDescription.RESOURCES_SYMLINK_TREE_FLAVOR))));
    assertThat(((SymlinkTree) deps.get(1)).getLinks(), is(equalTo(ImmutableSortedMap.of(Paths.get("file1.txt"), new PathSourcePath(filesystem, Paths.get("res/file1.txt"))))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 90 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class CxxLibraryDescriptionTest method locationMacroExpandedPlatformLinkerFlagPlatformMatch.

@Test
public void locationMacroExpandedPlatformLinkerFlagPlatformMatch() throws Exception {
    BuildTarget location = BuildTargetFactory.newInstance("//:loc");
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar").withFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR, CxxLibraryBuilder.createDefaultPlatform().getFlavor());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    ExportFileBuilder locBuilder = ExportFileBuilder.newExportFileBuilder(location);
    locBuilder.setOut("somewhere.over.the.rainbow");
    CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
    libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
    libBuilder.setPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile(CxxLibraryBuilder.createDefaultPlatform().getFlavor().toString()), ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location)))).build());
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build(), locBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ExportFile loc = locBuilder.build(resolver, filesystem, targetGraph);
    CxxLink lib = (CxxLink) libBuilder.build(resolver, filesystem, targetGraph);
    assertThat(lib.getDeps(), hasItem(loc));
    assertThat(Arg.stringify(lib.getArgs(), pathResolver), hasItem(String.format("-Wl,--version-script=%s", pathResolver.getAbsolutePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())))));
    assertThat(Arg.stringify(lib.getArgs(), pathResolver), not(hasItem(pathResolver.getAbsolutePath(loc.getSourcePathToOutput()).toString())));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14