Search in sources :

Example 11 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class ExternallyBuiltApplePackageTest method sdkrootEnvironmentVariableIsSet.

@Test
public void sdkrootEnvironmentVariableIsSet() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(this.resolver));
    ExternallyBuiltApplePackage rule = new ExternallyBuiltApplePackage(params, config, new FakeSourcePath(bundleLocation), true);
    resolver.addToIndex(rule);
    ShellStep step = Iterables.getOnlyElement(Iterables.filter(rule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext()), AbstractGenruleStep.class));
    assertThat(step.getEnvironmentVariables(TestExecutionContext.newInstance()), hasEntry("SDKROOT", DEFAULT_IPHONEOS_I386_PLATFORM.getAppleSdkPaths().getSdkPath().toString()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ShellStep(com.facebook.buck.shell.ShellStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) Test(org.junit.Test)

Example 12 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class CoreDataModel method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
    stepsBuilder.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));
    for (SourcePath dataModelPath : dataModelPaths) {
        stepsBuilder.add(new ShellStep(getProjectFilesystem().getRootPath()) {

            @Override
            protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
                ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
                commandBuilder.addAll(momc.getCommandPrefix(context.getSourcePathResolver()));
                commandBuilder.add("--sdkroot", sdkRoot.toString(), "--" + sdkName + "-deployment-target", minOSVersion, "--module", moduleName, context.getSourcePathResolver().getAbsolutePath(dataModelPath).toString(), getProjectFilesystem().resolve(outputDir).toString());
                return commandBuilder.build();
            }

            @Override
            public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext executionContext) {
                return momc.getEnvironment(context.getSourcePathResolver());
            }

            @Override
            public String getShortName() {
                return "momc";
            }
        });
    }
    buildableContext.recordArtifact(outputDir);
    return stepsBuilder.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 13 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class GenAidlTest method testSimpleGenAidlRule.

@Test
public void testSimpleGenAidlRule() throws IOException {
    ProjectFilesystem stubFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    Files.createDirectories(stubFilesystem.getRootPath().resolve("java/com/example/base"));
    FakeSourcePath pathToAidl = new FakeSourcePath(stubFilesystem, "java/com/example/base/IWhateverService.aidl");
    String importPath = Paths.get("java/com/example/base").toString();
    BuildTarget target = BuildTargetFactory.newInstance(stubFilesystem.getRootPath(), "//java/com/example/base:IWhateverService");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(stubFilesystem).build();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    GenAidl genAidlRule = new GenAidl(params, pathToAidl, importPath);
    GenAidlDescription description = new GenAidlDescription();
    assertEquals(Description.getBuildRuleType(GenAidlDescription.class), Description.getBuildRuleType(description));
    assertTrue(genAidlRule.getProperties().is(ANDROID));
    List<Step> steps = genAidlRule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    final String pathToAidlExecutable = Paths.get("/usr/local/bin/aidl").toString();
    final String pathToFrameworkAidl = Paths.get("/home/root/android/platforms/android-16/framework.aidl").toString();
    final AndroidPlatformTarget androidPlatformTarget = createMock(AndroidPlatformTarget.class);
    expect(androidPlatformTarget.getAidlExecutable()).andReturn(Paths.get(pathToAidlExecutable));
    expect(androidPlatformTarget.getAndroidFrameworkIdlFile()).andReturn(Paths.get(pathToFrameworkAidl));
    replay(androidPlatformTarget);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
    assertEquals(executionContext.getAndroidPlatformTarget(), androidPlatformTarget);
    Path outputDirectory = BuildTargets.getScratchPath(stubFilesystem, target, "__%s.aidl");
    MakeCleanDirectoryStep mkdirStep = (MakeCleanDirectoryStep) steps.get(1);
    assertEquals("gen_aidl() should make a directory at " + outputDirectory, outputDirectory, mkdirStep.getPath());
    ShellStep aidlStep = (ShellStep) steps.get(2);
    assertEquals("gen_aidl() should use the aidl binary to write .java files.", String.format("(cd %s && %s -p%s -I%s -o%s %s)", stubFilesystem.getRootPath(), pathToAidlExecutable, pathToFrameworkAidl, stubFilesystem.resolve(importPath), stubFilesystem.resolve(outputDirectory), pathToAidl.getRelativePath()), aidlStep.getDescription(executionContext));
    assertEquals(5, steps.size());
    verify(androidPlatformTarget);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) 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) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

ShellStep (com.facebook.buck.shell.ShellStep)13 ExecutionContext (com.facebook.buck.step.ExecutionContext)11 Step (com.facebook.buck.step.Step)9 ImmutableList (com.google.common.collect.ImmutableList)9 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 Path (java.nio.file.Path)6 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)5 SourcePath (com.facebook.buck.rules.SourcePath)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Test (org.junit.Test)4 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 MkdirStep (com.facebook.buck.step.fs.MkdirStep)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2