use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.
the class MavenUberJar method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
Path pathToOutput = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
MkdirStep mkOutputDirStep = new MkdirStep(getProjectFilesystem(), pathToOutput.getParent());
JarDirectoryStep mergeOutputsStep = new JarDirectoryStep(getProjectFilesystem(), pathToOutput, toOutputPaths(context.getSourcePathResolver(), traversedDeps.packagedDeps), /* mainClass */
null, /* manifestFile */
null);
return ImmutableList.of(mkOutputDirStep, mergeOutputsStep);
}
use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.
the class PythonInPlaceBinary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
Path binPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
buildableContext.recordArtifact(binPath);
return ImmutableList.of(new MkdirStep(getProjectFilesystem(), binPath.getParent()), new WriteFileStep(getProjectFilesystem(), script, binPath, /* executable */
true));
}
use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.
the class PythonPackagedBinary method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path binPath = context.getSourcePathResolver().getRelativePath(getSourcePathToOutput());
// Make sure the parent directory exists.
steps.add(new MkdirStep(getProjectFilesystem(), binPath.getParent()));
// Delete any other pex that was there (when switching between pex styles).
steps.add(new RmStep(getProjectFilesystem(), binPath, RmStep.Mode.RECURSIVE));
Path workingDirectory = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__working_directory");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), workingDirectory));
SourcePathResolver resolver = context.getSourcePathResolver();
// Generate and return the PEX build step.
steps.add(new PexStep(getProjectFilesystem(), builder.getEnvironment(resolver), ImmutableList.<String>builder().addAll(builder.getCommandPrefix(resolver)).addAll(buildArgs).build(), pythonEnvironment.getPythonPath(), pythonEnvironment.getPythonVersion(), workingDirectory, binPath, mainModule, resolver.getMappedPaths(getComponents().getModules()), resolver.getMappedPaths(getComponents().getResources()), resolver.getMappedPaths(getComponents().getNativeLibraries()), ImmutableSet.copyOf(resolver.getAllAbsolutePaths(getComponents().getPrebuiltLibraries())), preloadLibraries, getComponents().isZipSafe().orElse(true)));
// Record the executable package for caching.
buildableContext.recordArtifact(binPath);
return steps.build();
}
use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.
the class CxxCompilationDatabaseTest method testCompilationDatabase.
@Test
public void testCompilationDatabase() throws Exception {
BuildTarget testBuildTarget = BuildTarget.builder(BuildTargetFactory.newInstance("//foo:baz")).addAllFlavors(ImmutableSet.of(CxxCompilationDatabase.COMPILATION_DATABASE)).build();
final String root = "/Users/user/src";
final Path fakeRoot = Paths.get(root);
ProjectFilesystem filesystem = new FakeProjectFilesystem(fakeRoot);
BuildRuleParams testBuildRuleParams = new FakeBuildRuleParamsBuilder(testBuildTarget).setProjectFilesystem(filesystem).build();
BuildRuleResolver testBuildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver testSourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(testBuildRuleResolver));
HeaderSymlinkTree privateSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PRIVATE, true);
testBuildRuleResolver.addToIndex(privateSymlinkTree);
HeaderSymlinkTree exportedSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PUBLIC, true);
testBuildRuleResolver.addToIndex(exportedSymlinkTree);
BuildTarget compileTarget = BuildTarget.builder(testBuildRuleParams.getBuildTarget().getUnflavoredBuildTarget()).addFlavors(InternalFlavor.of("compile-test.cpp")).build();
PreprocessorFlags preprocessorFlags = PreprocessorFlags.builder().addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/foo/bar")), CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/test"))).build();
ImmutableSortedSet.Builder<CxxPreprocessAndCompile> rules = ImmutableSortedSet.naturalOrder();
BuildRuleParams compileBuildRuleParams = new FakeBuildRuleParamsBuilder(compileTarget).setProjectFilesystem(filesystem).setDeclaredDeps(ImmutableSortedSet.of(privateSymlinkTree, exportedSymlinkTree)).build();
rules.add(testBuildRuleResolver.addToIndex(CxxPreprocessAndCompile.preprocessAndCompile(compileBuildRuleParams, new PreprocessorDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), filesystem.getRootPath(), new GccPreprocessor(new HashedFileTool(Paths.get("preprocessor"))), preprocessorFlags, new RuleKeyAppendableFunction<FrameworkPath, Path>() {
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
// Do nothing.
}
@Override
public Path apply(FrameworkPath input) {
throw new UnsupportedOperationException("should not be called");
}
}, Optional.empty(), /* leadingIncludePaths */
Optional.empty()), new CompilerDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(new HashedFileTool(Paths.get("compiler"))), CxxToolFlags.of()), Paths.get("test.o"), new FakeSourcePath(filesystem, "test.cpp"), CxxSource.Type.CXX, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty())));
CxxCompilationDatabase compilationDatabase = CxxCompilationDatabase.createCompilationDatabase(testBuildRuleParams, rules.build());
testBuildRuleResolver.addToIndex(compilationDatabase);
assertThat(compilationDatabase.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.contains(exportedSymlinkTree.getBuildTarget(), privateSymlinkTree.getBuildTarget()));
assertEquals("getPathToOutput() should be a function of the build target.", BuildTargets.getGenPath(filesystem, testBuildTarget, "__%s.json"), testSourcePathResolver.getRelativePath(compilationDatabase.getSourcePathToOutput()));
List<Step> buildSteps = compilationDatabase.getBuildSteps(FakeBuildContext.withSourcePathResolver(testSourcePathResolver), new FakeBuildableContext());
assertEquals(2, buildSteps.size());
assertTrue(buildSteps.get(0) instanceof MkdirStep);
assertTrue(buildSteps.get(1) instanceof CxxCompilationDatabase.GenerateCompilationCommandsJson);
CxxCompilationDatabase.GenerateCompilationCommandsJson step = (CxxCompilationDatabase.GenerateCompilationCommandsJson) buildSteps.get(1);
Iterable<CxxCompilationDatabaseEntry> observedEntries = step.createEntries();
Iterable<CxxCompilationDatabaseEntry> expectedEntries = ImmutableList.of(CxxCompilationDatabaseEntry.of(root, root + "/test.cpp", ImmutableList.of("compiler", "-isystem", "/foo/bar", "-isystem", "/test", "-x", "c++", "-c", "-MD", "-MF", "test.o.dep", "test.cpp", "-o", "test.o")));
MoreAsserts.assertIterablesEquals(expectedEntries, observedEntries);
}
use of com.facebook.buck.step.fs.MkdirStep 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();
}
Aggregations