Search in sources :

Example 71 with Step

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

the class GenruleTest method testGenruleWithWorkerMacroUsesSpecialShellStep.

@Test
public void testGenruleWithWorkerMacroUsesSpecialShellStep() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    BuildRule genrule = createGenruleBuilderThatUsesWorkerMacro(ruleResolver).build(ruleResolver);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    List<Step> steps = genrule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    ExecutionContext executionContext = newEmptyExecutionContext(Platform.LINUX);
    assertEquals(4, steps.size());
    Step step = steps.get(3);
    assertTrue(step instanceof WorkerShellStep);
    WorkerShellStep workerShellStep = (WorkerShellStep) step;
    assertThat(workerShellStep.getShortName(), Matchers.equalTo("worker"));
    assertThat(workerShellStep.getEnvironmentVariables(executionContext), Matchers.hasEntry("OUT", filesystem.resolve(filesystem.getBuckPaths().getGenDir()).resolve("genrule_with_worker/output.txt").toString()));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 72 with Step

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

the class SrcZipAwareFileBundlerTest method bundleFiles.

public void bundleFiles(ImmutableSortedSet<SourcePath> immutableSortedSet) throws IOException {
    ImmutableList.Builder<Step> immutableStepList = ImmutableList.builder();
    new File(subDirectoryFile1.toString()).getParentFile().mkdirs();
    new File(subDirectoryFile2.toString()).getParentFile().mkdirs();
    new File(subDirectoryFile3.toString()).getParentFile().mkdirs();
    Files.createFile(subDirectoryFile1);
    Files.createFile(subDirectoryFile2);
    Files.createFile(subDirectoryFile3);
    SrcZipAwareFileBundler bundler = new SrcZipAwareFileBundler(basePath);
    bundler.copy(filesystem, new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), immutableStepList, dest, immutableSortedSet);
    ImmutableList<Step> builtStepList = immutableStepList.build();
    for (Step step : builtStepList) {
        try {
            step.execute(TestExecutionContext.newInstance());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) File(java.io.File) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 73 with Step

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

the class MoreAsserts method assertShellCommands.

/**
   * Asserts that every {@link com.facebook.buck.step.Step} in the observed list is a
   * {@link com.facebook.buck.shell.ShellStep} whose shell
   * command arguments match those of the corresponding entry in the expected list.
   */
public static void assertShellCommands(String userMessage, List<String> expected, List<Step> observed, ExecutionContext context) {
    Iterator<String> expectedIter = expected.iterator();
    Iterator<Step> observedIter = observed.iterator();
    Joiner joiner = Joiner.on(" ");
    while (expectedIter.hasNext() && observedIter.hasNext()) {
        String expectedShellCommand = expectedIter.next();
        Step observedStep = observedIter.next();
        if (!(observedStep instanceof ShellStep)) {
            failWith(userMessage, "Observed command must be a shell command: " + observedStep);
        }
        ShellStep shellCommand = (ShellStep) observedStep;
        String observedShellCommand = joiner.join(shellCommand.getShellCommand(context));
        assertEquals(userMessage, expectedShellCommand, observedShellCommand);
    }
    if (expectedIter.hasNext()) {
        failWith(userMessage, "Extra expected command: " + expectedIter.next());
    }
    if (observedIter.hasNext()) {
        failWith(userMessage, "Extra observed command: " + observedIter.next());
    }
}
Also used : Joiner(com.google.common.base.Joiner) ShellStep(com.facebook.buck.shell.ShellStep) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep)

Example 74 with Step

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

the class AaptPackageResources method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    // Copy manifest to a path named AndroidManifest.xml after replacing the manifest placeholders
    // if needed. Do this before running any other commands to ensure that it is available at the
    // desired path.
    steps.add(new MkdirStep(getProjectFilesystem(), getAndroidManifestXml().getParent()));
    Optional<ImmutableMap<String, String>> placeholders = manifestEntries.getPlaceholders();
    if (placeholders.isPresent() && !placeholders.get().isEmpty()) {
        steps.add(new ReplaceManifestPlaceholdersStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(manifest), getAndroidManifestXml(), placeholders.get()));
    } else {
        steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(manifest), getAndroidManifestXml()));
    }
    steps.add(new MkdirStep(getProjectFilesystem(), getResourceApkPath().getParent()));
    Path rDotTxtDir = getPathToRDotTxtDir();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), rDotTxtDir));
    Path pathToGeneratedProguardConfig = getPathToGeneratedProguardConfigFile();
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToGeneratedProguardConfig.getParent()));
    buildableContext.recordArtifact(pathToGeneratedProguardConfig);
    steps.add(new AaptStep(getProjectFilesystem().getRootPath(), getAndroidManifestXml(), filteredResourcesProvider.getResDirectories(), context.getSourcePathResolver().getAllAbsolutePaths(assetsDirectories), getResourceApkPath(), rDotTxtDir, pathToGeneratedProguardConfig, /*
             * In practice, it appears that if --no-crunch is used, resources will occasionally
             * appear distorted in the APK produced by this command (and what's worse, a clean
             * reinstall does not make the problem go away). This is not reliably reproducible, so
             * for now, we categorically outlaw the use of --no-crunch so that developers do not get
             * stuck in the distorted image state. One would expect the use of --no-crunch to allow
             * for faster build times, so it would be nice to figure out a way to leverage it in
             * debug mode that never results in distorted images.
             */
    !skipCrunchPngs, /* && packageType.isCrunchPngFiles() */
    includesVectorDrawables, manifestEntries), new ZipScrubberStep(getProjectFilesystem(), getResourceApkPath()));
    // If we had an empty res directory, we won't generate an R.txt file.  This ensures that it
    // always exists.
    steps.add(new TouchStep(getProjectFilesystem(), getPathToRDotTxtFile()));
    if (hasRDotJava()) {
        generateRDotJavaFiles(steps, buildableContext, context);
    }
    // Record the filtered resources dirs, since when we initialize ourselves from disk, we'll
    // need to test whether this is empty or not without requiring the `ResourcesFilter` rule to
    // be available.
    buildableContext.addMetadata(FILTERED_RESOURCE_DIRS_KEY, FluentIterable.from(filteredResourcesProvider.getResDirectories()).transform(Object::toString).toSortedList(Ordering.natural()));
    buildableContext.recordArtifact(getAndroidManifestXml());
    buildableContext.recordArtifact(getResourceApkPath());
    steps.add(new RecordFileSha1Step(getProjectFilesystem(), getResourceApkPath(), RESOURCE_PACKAGE_HASH_KEY, buildableContext));
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) 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) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) TouchStep(com.facebook.buck.step.fs.TouchStep) TouchStep(com.facebook.buck.step.fs.TouchStep) ImmutableMap(com.google.common.collect.ImmutableMap) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) RecordFileSha1Step(com.facebook.buck.rules.RecordFileSha1Step) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep)

Example 75 with Step

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

the class AndroidBinary method addProguardCommands.

/**
   * @return the resulting set of ProGuarded classpath entries to dex.
   */
@VisibleForTesting
ImmutableSet<Path> addProguardCommands(Set<Path> classpathEntriesToDex, Set<Path> depsProguardConfigs, boolean skipProguard, ImmutableList.Builder<Step> steps, BuildableContext buildableContext, SourcePathResolver resolver) {
    ImmutableSet.Builder<Path> additionalLibraryJarsForProguardBuilder = ImmutableSet.builder();
    for (JavaLibrary buildRule : rulesToExcludeFromDex) {
        additionalLibraryJarsForProguardBuilder.addAll(buildRule.getImmediateClasspaths().stream().map(resolver::getAbsolutePath).collect(MoreCollectors.toImmutableSet()));
    }
    // Create list of proguard Configs for the app project and its dependencies
    ImmutableSet.Builder<Path> proguardConfigsBuilder = ImmutableSet.builder();
    proguardConfigsBuilder.addAll(depsProguardConfigs);
    if (proguardConfig.isPresent()) {
        proguardConfigsBuilder.add(resolver.getAbsolutePath(proguardConfig.get()));
    }
    Path proguardConfigDir = getProguardTextFilesPath();
    // Transform our input classpath to a set of output locations for each input classpath.
    // TODO(jasta): the output path we choose is the result of a slicing function against
    // input classpath. This is fragile and should be replaced with knowledge of the BuildTarget.
    final ImmutableMap<Path, Path> inputOutputEntries = classpathEntriesToDex.stream().collect(MoreCollectors.toImmutableMap(java.util.function.Function.identity(), (path) -> getProguardOutputFromInputClasspath(proguardConfigDir, path)));
    // Run ProGuard on the classpath entries.
    ProGuardObfuscateStep.create(javaRuntimeLauncher, getProjectFilesystem(), proguardJarOverride.isPresent() ? Optional.of(resolver.getAbsolutePath(proguardJarOverride.get())) : Optional.empty(), proguardMaxHeapSize, proguardAgentPath, resolver.getRelativePath(aaptGeneratedProguardConfigFile), proguardConfigsBuilder.build(), sdkProguardConfig, optimizationPasses, proguardJvmArgs, inputOutputEntries, additionalLibraryJarsForProguardBuilder.build(), proguardConfigDir, buildableContext, skipProguard, steps);
    // ProGuard then return the input classes to dex.
    if (skipProguard) {
        return ImmutableSet.copyOf(inputOutputEntries.keySet());
    } else {
        return ImmutableSet.copyOf(inputOutputEntries.values());
    }
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) OptionalCompat(com.facebook.buck.util.OptionalCompat) ExopackageInfo(com.facebook.buck.rules.ExopackageInfo) HasRuntimeDeps(com.facebook.buck.rules.HasRuntimeDeps) CopyStep(com.facebook.buck.step.fs.CopyStep) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ImmutableCollection(com.google.common.collect.ImmutableCollection) RichStream(com.facebook.buck.util.RichStream) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SymlinkFilesIntoDirectoryStep(com.facebook.buck.shell.SymlinkFilesIntoDirectoryStep) Keystore(com.facebook.buck.jvm.java.Keystore) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ImmutableMap(com.google.common.collect.ImmutableMap) BuildableProperties(com.facebook.buck.rules.BuildableProperties) BuildableContext(com.facebook.buck.rules.BuildableContext) Set(java.util.Set) BuildTarget(com.facebook.buck.model.BuildTarget) HasClasspathEntries(com.facebook.buck.jvm.java.HasClasspathEntries) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) PACKAGING(com.facebook.buck.rules.BuildableProperties.Kind.PACKAGING) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) JavaRuntimeLauncher(com.facebook.buck.jvm.java.JavaRuntimeLauncher) AccumulateClassNamesStep(com.facebook.buck.jvm.java.AccumulateClassNamesStep) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) ResourceCompressionMode(com.facebook.buck.android.ResourcesFilter.ResourceCompressionMode) Supplier(com.google.common.base.Supplier) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) SourcePath(com.facebook.buck.rules.SourcePath) Multimap(com.google.common.collect.Multimap) BuildRule(com.facebook.buck.rules.BuildRule) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) Suppliers(com.google.common.base.Suppliers) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RedexOptions(com.facebook.buck.android.redex.RedexOptions) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Nullable(javax.annotation.Nullable) SupportsInputBasedRuleKey(com.facebook.buck.rules.keys.SupportsInputBasedRuleKey) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) JavaLibraryClasspathProvider(com.facebook.buck.jvm.java.JavaLibraryClasspathProvider) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) HashCode(com.google.common.hash.HashCode) ManifestEntries(com.facebook.buck.rules.coercer.ManifestEntries) ReDexStep(com.facebook.buck.android.redex.ReDexStep) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ANDROID(com.facebook.buck.rules.BuildableProperties.Kind.ANDROID) AbstractMap(java.util.AbstractMap) XzStep(com.facebook.buck.step.fs.XzStep) Paths(java.nio.file.Paths) ResourceFilter(com.facebook.buck.android.FilterResourcesStep.ResourceFilter) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) BuildContext(com.facebook.buck.rules.BuildContext) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) ImmutableSet(com.google.common.collect.ImmutableSet) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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