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()));
}
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();
}
}
}
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());
}
}
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();
}
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());
}
}
Aggregations