Search in sources :

Example 6 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class AndroidInstrumentationTest method runTests.

@Override
public ImmutableList<Step> runTests(ExecutionContext executionContext, TestRunningOptions options, SourcePathResolver pathResolver, TestReportingCallback testReportingCallback) {
    Preconditions.checkArgument(executionContext.getAdbOptions().isPresent());
    if (executionContext.getAdbOptions().get().isMultiInstallModeEnabled()) {
        throw new HumanReadableException("Running android instrumentation tests with multiple devices is not supported.");
    }
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Path pathToTestOutput = getPathToTestOutputDirectory();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
    steps.add(new ApkInstallStep(pathResolver, apk));
    if (apk instanceof AndroidInstrumentationApk) {
        steps.add(new ApkInstallStep(pathResolver, ((AndroidInstrumentationApk) apk).getApkUnderTest()));
    }
    AdbHelper adb = AdbHelper.get(executionContext, true);
    IDevice device;
    try {
        device = adb.getSingleDevice();
    } catch (InterruptedException e) {
        throw new HumanReadableException("Unable to get connected device.");
    }
    steps.add(getInstrumentationStep(pathResolver, executionContext.getPathToAdbExecutable(), Optional.of(getProjectFilesystem().resolve(pathToTestOutput)), Optional.of(device.getSerialNumber()), Optional.empty(), getFilterString(options), Optional.empty()));
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) IDevice(com.android.ddmlib.IDevice) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 7 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class IntraDexReorderStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    try {
        DefaultStepRunner stepRunner = new DefaultStepRunner();
        List<Step> dxSteps = generateReorderCommands();
        for (Step step : dxSteps) {
            stepRunner.runStepForBuildTarget(context, step, Optional.of(buildTarget));
        }
    } catch (StepFailedException | InterruptedException e) {
        context.logError(e, "There was an error in intra dex reorder step.");
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : StepFailedException(com.facebook.buck.step.StepFailedException) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CopyStep(com.facebook.buck.step.fs.CopyStep) UnzipStep(com.facebook.buck.zip.UnzipStep) ZipStep(com.facebook.buck.zip.ZipStep) DefaultShellStep(com.facebook.buck.shell.DefaultShellStep)

Example 8 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class AppleTest method getTestCommand.

public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand(ExecutionContext context, TestRunningOptions options, SourcePathResolver pathResolver, TestRule.TestReportingCallback testReportingCallback) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ExternalTestRunnerTestSpec.Builder externalSpec = ExternalTestRunnerTestSpec.builder().setTarget(getBuildTarget()).setLabels(getLabels()).setContacts(getContacts());
    Path resolvedTestBundleDirectory = pathResolver.getAbsolutePath(Preconditions.checkNotNull(testBundle.getSourcePathToOutput()));
    Path pathToTestOutput = getProjectFilesystem().resolve(getPathToTestOutputDirectory());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));
    Path resolvedTestLogsPath = getProjectFilesystem().resolve(testLogsPath);
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), resolvedTestLogsPath));
    Path resolvedTestOutputPath = getProjectFilesystem().resolve(testOutputPath);
    Optional<Path> testHostAppPath = Optional.empty();
    if (testHostApp.isPresent()) {
        Path resolvedTestHostAppDirectory = pathResolver.getAbsolutePath(Preconditions.checkNotNull(testHostApp.get().getSourcePathToOutput()));
        testHostAppPath = Optional.of(resolvedTestHostAppDirectory.resolve(testHostApp.get().getUnzippedOutputFilePathToBinary()));
    }
    if (!useXctest) {
        if (!xctool.isPresent()) {
            throw new HumanReadableException("Set xctool_path = /path/to/xctool or xctool_zip_target = //path/to:xctool-zip " + "in the [apple] section of .buckconfig to run this test");
        }
        ImmutableSet.Builder<Path> logicTestPathsBuilder = ImmutableSet.builder();
        ImmutableMap.Builder<Path, Path> appTestPathsToHostAppsBuilder = ImmutableMap.builder();
        if (testHostAppPath.isPresent()) {
            appTestPathsToHostAppsBuilder.put(resolvedTestBundleDirectory, testHostAppPath.get());
        } else {
            logicTestPathsBuilder.add(resolvedTestBundleDirectory);
        }
        xctoolStdoutReader = Optional.of(new AppleTestXctoolStdoutReader(testReportingCallback));
        Optional<String> destinationSpecifierArg;
        if (!destinationSpecifier.get().isEmpty()) {
            destinationSpecifierArg = Optional.of(Joiner.on(',').join(Iterables.transform(destinationSpecifier.get().entrySet(), input -> input.getKey() + "=" + input.getValue())));
        } else {
            destinationSpecifierArg = defaultDestinationSpecifier;
        }
        Optional<String> snapshotReferenceImagesPath = Optional.empty();
        if (this.snapshotReferenceImagesPath.isPresent()) {
            if (this.snapshotReferenceImagesPath.get().isLeft()) {
                snapshotReferenceImagesPath = Optional.of(pathResolver.getAbsolutePath(this.snapshotReferenceImagesPath.get().getLeft()).toString());
            } else if (this.snapshotReferenceImagesPath.get().isRight()) {
                snapshotReferenceImagesPath = Optional.of(getProjectFilesystem().getPathForRelativePath(this.snapshotReferenceImagesPath.get().getRight()).toString());
            }
        }
        XctoolRunTestsStep xctoolStep = new XctoolRunTestsStep(getProjectFilesystem(), pathResolver.getAbsolutePath(xctool.get()), options.getEnvironmentOverrides(), xctoolStutterTimeout, platformName, destinationSpecifierArg, logicTestPathsBuilder.build(), appTestPathsToHostAppsBuilder.build(), resolvedTestOutputPath, xctoolStdoutReader, xcodeDeveloperDirSupplier, options.getTestSelectorList(), context.isDebugEnabled(), Optional.of(testLogDirectoryEnvironmentVariable), Optional.of(resolvedTestLogsPath), Optional.of(testLogLevelEnvironmentVariable), Optional.of(testLogLevel), testRuleTimeoutMs, snapshotReferenceImagesPath);
        steps.add(xctoolStep);
        externalSpec.setType("xctool-" + (testHostApp.isPresent() ? "application" : "logic"));
        externalSpec.setCommand(xctoolStep.getCommand());
        externalSpec.setEnv(xctoolStep.getEnv(context));
    } else {
        xctestOutputReader = Optional.of(new AppleTestXctestOutputReader(testReportingCallback));
        HashMap<String, String> environment = new HashMap<>();
        environment.putAll(xctest.getEnvironment(pathResolver));
        environment.putAll(options.getEnvironmentOverrides());
        if (testHostAppPath.isPresent()) {
            environment.put("XCInjectBundleInto", testHostAppPath.get().toString());
        }
        XctestRunTestsStep xctestStep = new XctestRunTestsStep(getProjectFilesystem(), ImmutableMap.copyOf(environment), xctest.getCommandPrefix(pathResolver), resolvedTestBundleDirectory, resolvedTestOutputPath, xctestOutputReader, xcodeDeveloperDirSupplier);
        steps.add(xctestStep);
        externalSpec.setType("xctest");
        externalSpec.setCommand(xctestStep.getCommand());
        externalSpec.setEnv(xctestStep.getEnv(context));
    }
    return new Pair<>(steps.build(), externalSpec.build());
}
Also used : Path(java.nio.file.Path) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) OptionalCompat(com.facebook.buck.util.OptionalCompat) HasRuntimeDeps(com.facebook.buck.rules.HasRuntimeDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) TestResults(com.facebook.buck.test.TestResults) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Pair(com.facebook.buck.model.Pair) TestRule(com.facebook.buck.rules.TestRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) BuildableContext(com.facebook.buck.rules.BuildableContext) BuildTarget(com.facebook.buck.model.BuildTarget) StandardCharsets(java.nio.charset.StandardCharsets) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) List(java.util.List) Stream(java.util.stream.Stream) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) Supplier(com.google.common.base.Supplier) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Label(com.facebook.buck.rules.Label) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) MoreCollectors(com.facebook.buck.util.MoreCollectors) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Files(java.nio.file.Files) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) InputStreamReader(java.io.InputStreamReader) BuildContext(com.facebook.buck.rules.BuildContext) Preconditions(com.google.common.base.Preconditions) BufferedReader(java.io.BufferedReader) BuildTargets(com.facebook.buck.model.BuildTargets) Collections(java.util.Collections) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) HumanReadableException(com.facebook.buck.util.HumanReadableException) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Pair(com.facebook.buck.model.Pair)

Example 9 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class BuiltinApplePackage method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    // Remove the output .ipa file if it exists already
    commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile));
    // Create temp folder to store the files going to be zipped
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));
    Path payloadDir = temp.resolve("Payload");
    commands.add(new MkdirStep(getProjectFilesystem(), payloadDir));
    // Recursively copy the .app directory into the Payload folder
    Path bundleOutputPath = context.getSourcePathResolver().getRelativePath(Preconditions.checkNotNull(bundle.getSourcePathToOutput()));
    appendAdditionalAppleWatchSteps(commands);
    commands.add(CopyStep.forDirectory(getProjectFilesystem(), bundleOutputPath, payloadDir, CopyStep.DirectoryMode.DIRECTORY_AND_CONTENTS));
    appendAdditionalSwiftSteps(context.getSourcePathResolver(), commands);
    // do the zipping
    commands.add(new MkdirStep(getProjectFilesystem(), pathToOutputFile.getParent()));
    commands.add(new ZipStep(getProjectFilesystem(), pathToOutputFile, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, temp));
    buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
    return commands.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ZipStep(com.facebook.buck.zip.ZipStep) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 10 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class MultiarchFile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    lipoBinaries(context, steps);
    copyLinkMaps(buildableContext, steps);
    return steps.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) DefaultShellStep(com.facebook.buck.shell.DefaultShellStep)

Aggregations

Step (com.facebook.buck.step.Step)143 ImmutableList (com.google.common.collect.ImmutableList)82 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)65 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)62 Test (org.junit.Test)54 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)49 MkdirStep (com.facebook.buck.step.fs.MkdirStep)44 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)42 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)41 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)40 BuildTarget (com.facebook.buck.model.BuildTarget)39 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)36 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)35 ExecutionContext (com.facebook.buck.step.ExecutionContext)34 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)31 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)30 BuildContext (com.facebook.buck.rules.BuildContext)25 RmStep (com.facebook.buck.step.fs.RmStep)24 CopyStep (com.facebook.buck.step.fs.CopyStep)23