Search in sources :

Example 36 with DefaultTargetNodeToBuildRuleTransformer

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

the class MergeAndroidResourcesStepTest method testGenerateRDotJavaForCustomDrawables.

@Test
public void testGenerateRDotJavaForCustomDrawables() throws IOException {
    BuildTarget target = BuildTargetFactory.newInstance("//android_res/com/facebook/http:res");
    RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
    String symbolsFile = BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), target, "__%s_text_symbols__/R.txt").toString();
    String rDotJavaPackage = "com.facebook";
    final ImmutableList<String> outputTextSymbols = ImmutableList.<String>builder().add("int drawable android_drawable 0x7f010000").add("int drawable fb_drawable 0x7f010001 #").build();
    entriesBuilder.add(new RDotTxtFile(rDotJavaPackage, symbolsFile, outputTextSymbols));
    FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
    Path uberRDotTxt = filesystem.resolve("R.txt").toAbsolutePath();
    filesystem.writeLinesToPath(outputTextSymbols, uberRDotTxt);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    HasAndroidResourceDeps resource = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(target).setRes(new FakeSourcePath("res")).setRDotJavaPackage("com.facebook").build();
    MergeAndroidResourcesStep mergeStep = new MergeAndroidResourcesStep(filesystem, resolver, ImmutableList.of(resource), Optional.of(uberRDotTxt), Paths.get("output"), /* forceFinalResourceIds */
    true, /* bannedDuplicateResourceTypes */
    EnumSet.noneOf(RType.class), /* unionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), /* useOldStyleableFormat */
    false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertEquals(0, mergeStep.execute(executionContext).getExitCode());
    // Verify that the correct Java code is generated.
    assertEquals("package com.facebook;\n" + "\n" + "public class R {\n" + "  public static class drawable {\n" + "    public static final int android_drawable=0x7f010000;\n" + "    public static final int fb_drawable=0x7f010001;\n" + "  }\n" + "\n" + "  public static final int[] custom_drawables = { 0x7f010001 };\n" + "\n" + "}\n", filesystem.readFileIfItExists(Paths.get("output/com/facebook/R.java")).get().replace("\r", ""));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 37 with DefaultTargetNodeToBuildRuleTransformer

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

the class ReDexStepTest method constructorArgsAreUsedToCreateShellCommand.

@Test
public void constructorArgsAreUsedToCreateShellCommand() {
    Path workingDirectory = Paths.get("/where/the/code/is");
    List<String> redexBinaryArgs = ImmutableList.of("/usr/bin/redex");
    Map<String, String> redexEnvironmentVariables = ImmutableMap.of("REDEX_DEBUG", "1");
    Path inputApkPath = Paths.get("buck-out/gen/app.apk.zipalign");
    Path outputApkPath = Paths.get("buck-out/gen/app.apk");
    Path keystorePath = Paths.get("keystores/debug.keystore");
    KeystoreProperties keystoreProperties = new KeystoreProperties(keystorePath, "storepass", "keypass", "alias");
    Supplier<KeystoreProperties> keystorePropertiesSupplier = Suppliers.ofInstance(keystoreProperties);
    Path redexConfigPath = Paths.get("redex/redex-config.json");
    Optional<Path> redexConfig = Optional.of(redexConfigPath);
    ImmutableList<Arg> redexExtraArgs = ImmutableList.of(StringArg.of("foo"), StringArg.of("bar"));
    Path proguardMap = Paths.get("buck-out/gen/app/__proguard__/mapping.txt");
    Path proguardConfig = Paths.get("app.proguard.config");
    Path seeds = Paths.get("buck-out/gen/app/__proguard__/seeds.txt");
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    ReDexStep redex = new ReDexStep(workingDirectory, redexBinaryArgs, redexEnvironmentVariables, inputApkPath, outputApkPath, keystorePropertiesSupplier, redexConfig, redexExtraArgs, proguardMap, proguardConfig, seeds, pathResolver);
    assertEquals("redex", redex.getShortName());
    AndroidPlatformTarget androidPlatform = EasyMock.createMock(AndroidPlatformTarget.class);
    Path sdkDirectory = Paths.get("/Users/user/android-sdk-macosx");
    EasyMock.expect(androidPlatform.getSdkDirectory()).andReturn(Optional.of(sdkDirectory));
    EasyMock.replay(androidPlatform);
    ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatform)).build();
    assertEquals(ImmutableMap.of("ANDROID_SDK", sdkDirectory.toString(), "REDEX_DEBUG", "1"), redex.getEnvironmentVariables(context));
    EasyMock.verify(androidPlatform);
    assertEquals(ImmutableList.of("/usr/bin/redex", "--config", redexConfigPath.toString(), "--sign", "--keystore", keystorePath.toString(), "--keyalias", "alias", "--keypass", "keypass", "--proguard-map", proguardMap.toString(), "-P", proguardConfig.toString(), "--keep", seeds.toString(), "--out", outputApkPath.toString(), "foo", "bar", inputApkPath.toString()), redex.getShellCommandInternal(context));
}
Also used : Path(java.nio.file.Path) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) KeystoreProperties(com.facebook.buck.android.KeystoreProperties) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 38 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer 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 39 with DefaultTargetNodeToBuildRuleTransformer

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

the class MultiarchFileTest method descriptionWithMultipleDifferentSdksShouldFail.

@Test
public void descriptionWithMultipleDifferentSdksShouldFail() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    HumanReadableException exception = null;
    try {
        nodeBuilderFactory.getNodeBuilder(BuildTargetFactory.newInstance("//foo:xctest#iphoneos-i386,macosx-x86_64")).build(resolver);
    } catch (HumanReadableException e) {
        exception = e;
    }
    assertThat(exception, notNullValue());
    assertThat("Should throw exception about different architectures", exception.getHumanReadableErrorMessage(), endsWith("Fat binaries can only be generated from binaries compiled for the same SDK."));
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 40 with DefaultTargetNodeToBuildRuleTransformer

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

the class MultiarchFileTest method descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile.

@SuppressWarnings({ "unchecked" })
@Test
public void descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64");
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64,sandbox");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleLibraryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRule multiarchRule = nodeBuilderFactory.getNodeBuilder(target).build(resolver, filesystem);
    assertThat(multiarchRule, instanceOf(MultiarchFile.class));
    ImmutableList<Step> steps = multiarchRule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    ShellStep step = Iterables.getLast(Iterables.filter(steps, ShellStep.class));
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList<String> command = step.getShellCommand(executionContext);
    assertThat(command, Matchers.contains(endsWith("lipo"), equalTo("-create"), equalTo("-output"), containsString("foo/thing#"), containsString("/thing#"), containsString("/thing#")));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) ShellStep(com.facebook.buck.shell.ShellStep) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)579 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)578 Test (org.junit.Test)527 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)375 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)352 BuildTarget (com.facebook.buck.model.BuildTarget)257 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)238 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)204 TargetGraph (com.facebook.buck.rules.TargetGraph)182 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)115 SourcePath (com.facebook.buck.rules.SourcePath)110 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 PathSourcePath (com.facebook.buck.rules.PathSourcePath)90 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)70 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)68 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)49