Search in sources :

Example 1 with ShellStep

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

the class SceneKitAssets 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 inputPath : sceneKitAssetsPaths) {
        final Path absoluteInputPath = context.getSourcePathResolver().getAbsolutePath(inputPath);
        if (copySceneKitAssets.isPresent()) {
            stepsBuilder.add(new ShellStep(getProjectFilesystem().getRootPath()) {

                @Override
                protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
                    ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
                    commandBuilder.addAll(copySceneKitAssets.get().getCommandPrefix(context.getSourcePathResolver()));
                    commandBuilder.add(absoluteInputPath.toString(), "-o", getProjectFilesystem().resolve(outputDir).resolve(absoluteInputPath.getFileName()).toString(), "--target-platform=" + sdkName, "--target-version=" + minOSVersion);
                    return commandBuilder.build();
                }

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

                @Override
                public String getShortName() {
                    return "copy-scenekit-assets";
                }
            });
        } else {
            stepsBuilder.add(CopyStep.forDirectory(getProjectFilesystem(), absoluteInputPath, outputDir, CopyStep.DirectoryMode.CONTENTS_ONLY));
        }
    }
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    return stepsBuilder.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) 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) CopyStep(com.facebook.buck.step.fs.CopyStep) ShellStep(com.facebook.buck.shell.ShellStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ShellStep

use of com.facebook.buck.shell.ShellStep 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)

Example 3 with ShellStep

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

the class HaskellCompileRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) {
    buildableContext.recordArtifact(getObjectDir());
    buildableContext.recordArtifact(getInterfaceDir());
    buildableContext.recordArtifact(getStubDir());
    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getObjectDir()), new MakeCleanDirectoryStep(getProjectFilesystem(), getInterfaceDir()), new MakeCleanDirectoryStep(getProjectFilesystem(), getStubDir()), new ShellStep(getProjectFilesystem().getRootPath()) {

        @Override
        public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
            return ImmutableMap.<String, String>builder().putAll(super.getEnvironmentVariables(context)).putAll(compiler.getEnvironment(buildContext.getSourcePathResolver())).build();
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
            SourcePathResolver resolver = buildContext.getSourcePathResolver();
            return ImmutableList.<String>builder().addAll(compiler.getCommandPrefix(resolver)).addAll(flags).add("-no-link").addAll(picType == CxxSourceRuleFactory.PicType.PIC ? ImmutableList.of("-dynamic", "-fPIC", "-hisuf", "dyn_hi") : ImmutableList.of()).addAll(MoreIterables.zipAndConcat(Iterables.cycle("-main-is"), OptionalCompat.asSet(main))).addAll(getPackageNameArgs()).addAll(getPreprocessorFlags(buildContext.getSourcePathResolver())).add("-odir", getProjectFilesystem().resolve(getObjectDir()).toString()).add("-hidir", getProjectFilesystem().resolve(getInterfaceDir()).toString()).add("-stubdir", getProjectFilesystem().resolve(getStubDir()).toString()).add("-i" + includes.stream().map(resolver::getAbsolutePath).map(Object::toString).collect(Collectors.joining(":"))).addAll(getPackageArgs(buildContext.getSourcePathResolver())).addAll(sources.getSourcePaths().stream().map(resolver::getAbsolutePath).map(Object::toString).iterator()).build();
        }

        @Override
        public String getShortName() {
            return "haskell-compile";
        }
    });
}
Also used : 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) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with ShellStep

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

the class GwtBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // Create a clean directory where the .zip file will be written.
    Path workingDirectory = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()).getParent();
    ProjectFilesystem projectFilesystem = getProjectFilesystem();
    steps.add(new MakeCleanDirectoryStep(projectFilesystem, workingDirectory));
    // Write the deploy files into a separate directory so that the generated .zip is smaller.
    final Path deployDirectory = workingDirectory.resolve("deploy");
    steps.add(new MkdirStep(projectFilesystem, deployDirectory));
    Step javaStep = new ShellStep(projectFilesystem.getRootPath()) {

        @Override
        public String getShortName() {
            return "gwt-compile";
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
            ImmutableList.Builder<String> javaArgsBuilder = ImmutableList.builder();
            javaArgsBuilder.add(javaRuntimeLauncher.getCommand());
            javaArgsBuilder.add("-Dgwt.normalizeTimestamps=true");
            javaArgsBuilder.addAll(vmArgs);
            javaArgsBuilder.add("-classpath", Joiner.on(File.pathSeparator).join(Iterables.transform(getClasspathEntries(context.getSourcePathResolver()), getProjectFilesystem()::resolve)), GWT_COMPILER_CLASS, "-war", context.getSourcePathResolver().getAbsolutePath(getSourcePathToOutput()).toString(), "-style", style.name(), "-optimize", String.valueOf(optimize), "-localWorkers", String.valueOf(localWorkers), "-deploy", getProjectFilesystem().resolve(deployDirectory).toString());
            if (draftCompile) {
                javaArgsBuilder.add("-draftCompile");
            }
            if (strict) {
                javaArgsBuilder.add("-strict");
            }
            javaArgsBuilder.addAll(experimentalArgs);
            javaArgsBuilder.addAll(modules);
            final ImmutableList<String> javaArgs = javaArgsBuilder.build();
            return javaArgs;
        }
    };
    steps.add(javaStep);
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 5 with ShellStep

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

the class LuaStandaloneBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    buildableContext.recordArtifact(output);
    // Make sure the parent directory exists.
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    // Delete any other pex that was there (when switching between pex styles).
    steps.add(new RmStep(getProjectFilesystem(), output, RmStep.Mode.RECURSIVE));
    SourcePathResolver resolver = context.getSourcePathResolver();
    steps.add(new ShellStep(getProjectFilesystem().getRootPath()) {

        @Override
        protected Optional<String> getStdin(ExecutionContext context) {
            try {
                return Optional.of(context.getObjectMapper().writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, resolver::getAbsolutePath)))));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
            ImmutableList.Builder<String> command = ImmutableList.builder();
            command.addAll(builder.getCommandPrefix(resolver));
            command.addAll(builderArgs);
            command.add("--entry-point", mainModule);
            command.add("--interpreter");
            if (starter.isPresent()) {
                command.add(resolver.getAbsolutePath(starter.get()).toString());
            } else {
                command.add(lua.getCommandPrefix(resolver).get(0));
            }
            command.add(getProjectFilesystem().resolve(output).toString());
            return command.build();
        }

        @Override
        public String getShortName() {
            return "lua_package";
        }
    });
    return steps.build();
}
Also used : Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ShellStep(com.facebook.buck.shell.ShellStep) IOException(java.io.IOException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) RmStep(com.facebook.buck.step.fs.RmStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ShellStep(com.facebook.buck.shell.ShellStep)

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