use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class BuiltinApplePackage method appendAdditionalAppleWatchSteps.
private void appendAdditionalAppleWatchSteps(ImmutableList.Builder<Step> commands) {
// 2. WatchKitSupport instead of WatchKitSupport2.
for (BuildRule rule : bundle.getDeps()) {
if (rule instanceof AppleBundle) {
AppleBundle appleBundle = (AppleBundle) rule;
if (appleBundle.getBinary().isPresent()) {
BuildRule binary = appleBundle.getBinary().get();
if (binary instanceof WriteFile && appleBundle.getPlatformName().startsWith("watch")) {
commands.add(new MkdirStep(getProjectFilesystem(), temp.resolve("Symbols")));
Path watchKitSupportDir = temp.resolve("WatchKitSupport2");
commands.add(new MkdirStep(getProjectFilesystem(), watchKitSupportDir));
commands.add(new WriteFileStep(getProjectFilesystem(), ByteSource.wrap(((WriteFile) binary).getFileContents()), watchKitSupportDir.resolve("WK"), true));
} else {
Optional<WriteFile> legacyWatchStub = getLegacyWatchStubFromDeps(appleBundle);
if (legacyWatchStub.isPresent()) {
Path watchKitSupportDir = temp.resolve("WatchKitSupport");
commands.add(new MkdirStep(getProjectFilesystem(), watchKitSupportDir));
commands.add(new WriteFileStep(getProjectFilesystem(), ByteSource.wrap(legacyWatchStub.get().getFileContents()), watchKitSupportDir.resolve("WK"), true));
}
}
}
}
}
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class GoDescriptors method getTestMainGenerator.
static Tool getTestMainGenerator(GoBuckConfig goBuckConfig, BuildRuleParams sourceParams, BuildRuleResolver resolver) throws NoSuchBuildTargetException {
Optional<Tool> configTool = goBuckConfig.getGoTestMainGenerator(resolver);
if (configTool.isPresent()) {
return configTool.get();
}
// TODO(mikekap): Make a single test main gen, rather than one per test. The generator itself
// doesn't vary per test.
BuildTarget generatorTarget = sourceParams.getBuildTarget().withFlavors(InternalFlavor.of("make-test-main-gen"));
Optional<BuildRule> generator = resolver.getRuleOptional(generatorTarget);
if (generator.isPresent()) {
return ((BinaryBuildRule) generator.get()).getExecutableCommand();
}
BuildTarget generatorSourceTarget = sourceParams.getBuildTarget().withAppendedFlavors(InternalFlavor.of("test-main-gen-source"));
WriteFile writeFile = resolver.addToIndex(new WriteFile(sourceParams.withBuildTarget(generatorSourceTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), extractTestMainGenerator(), BuildTargets.getGenPath(sourceParams.getProjectFilesystem(), generatorSourceTarget, "%s/main.go"), /* executable */
false));
GoBinary binary = resolver.addToIndex(createGoBinaryRule(sourceParams.withBuildTarget(generatorTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of(writeFile))), resolver, goBuckConfig, ImmutableSet.of(writeFile.getSourcePathToOutput()), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), goBuckConfig.getDefaultPlatform()));
return binary.getExecutableCommand();
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class AbstractLuaScriptStarter method build.
@Override
public SourcePath build() {
BuildTarget templateTarget = BuildTarget.builder(getBaseParams().getBuildTarget()).addFlavors(InternalFlavor.of("starter-template")).build();
WriteFile templateRule = getRuleResolver().addToIndex(new WriteFile(getBaseParams().withBuildTarget(templateTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), getPureStarterTemplate(), BuildTargets.getGenPath(getBaseParams().getProjectFilesystem(), templateTarget, "%s/starter.lua.in"), /* executable */
false));
final Tool lua = getLuaConfig().getLua(getRuleResolver());
WriteStringTemplateRule writeStringTemplateRule = getRuleResolver().addToIndex(WriteStringTemplateRule.from(getBaseParams(), getRuleFinder(), getTarget(), getOutput(), templateRule.getSourcePathToOutput(), ImmutableMap.of("SHEBANG", lua.getCommandPrefix(getPathResolver()).get(0), "MAIN_MODULE", Escaper.escapeAsPythonString(getMainModule()), "MODULES_DIR", getRelativeModulesDir().isPresent() ? Escaper.escapeAsPythonString(getRelativeModulesDir().get().toString()) : "nil", "PY_MODULES_DIR", getRelativePythonModulesDir().isPresent() ? Escaper.escapeAsPythonString(getRelativePythonModulesDir().get().toString()) : "nil", "EXT_SUFFIX", Escaper.escapeAsPythonString(getCxxPlatform().getSharedLibraryExtension())), /* executable */
true));
return writeStringTemplateRule.getSourcePathToOutput();
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class AbstractNativeExecutableStarter method getNativeStarterCxxSource.
private CxxSource getNativeStarterCxxSource() {
BuildTarget target = BuildTarget.builder(getBaseParams().getBuildTarget()).addFlavors(InternalFlavor.of("native-starter-cxx-source")).build();
BuildRule rule;
Optional<BuildRule> maybeRule = getRuleResolver().getRuleOptional(target);
if (maybeRule.isPresent()) {
rule = maybeRule.get();
} else {
BuildTarget templateTarget = BuildTarget.builder(getBaseParams().getBuildTarget()).addFlavors(InternalFlavor.of("native-starter-cxx-source-template")).build();
WriteFile templateRule = getRuleResolver().addToIndex(new WriteFile(getBaseParams().withBuildTarget(templateTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), getNativeStarterCxxSourceTemplate(), BuildTargets.getGenPath(getBaseParams().getProjectFilesystem(), templateTarget, "%s/native-starter.cpp.in"), /* executable */
false));
Path output = BuildTargets.getGenPath(getBaseParams().getProjectFilesystem(), target, "%s/native-starter.cpp");
rule = getRuleResolver().addToIndex(WriteStringTemplateRule.from(getBaseParams(), getRuleFinder(), target, output, templateRule.getSourcePathToOutput(), ImmutableMap.of("MAIN_MODULE", Escaper.escapeAsPythonString(getMainModule()), "MODULES_DIR", getRelativeModulesDir().isPresent() ? Escaper.escapeAsPythonString(getRelativeModulesDir().get().toString()) : "NULL", "PY_MODULES_DIR", getRelativePythonModulesDir().isPresent() ? Escaper.escapeAsPythonString(getRelativePythonModulesDir().get().toString()) : "NULL", "EXT_SUFFIX", Escaper.escapeAsPythonString(getCxxPlatform().getSharedLibraryExtension())), /* executable */
false));
}
return CxxSource.of(CxxSource.Type.CXX, Preconditions.checkNotNull(rule.getSourcePathToOutput()), ImmutableList.of());
}
use of com.facebook.buck.file.WriteFile in project buck by facebook.
the class AppleBundle method copyAnotherCopyOfWatchKitStub.
private void copyAnotherCopyOfWatchKitStub(ImmutableList.Builder<Step> stepsBuilder, Path binaryOutputPath) {
if ((isLegacyWatchApp() || (platform.getName().contains("watch") && minOSVersion.equals("2.0"))) && binary.get() instanceof WriteFile) {
final Path watchKitStubDir = bundleRoot.resolve("_WatchKitStub");
stepsBuilder.add(new MkdirStep(getProjectFilesystem(), watchKitStubDir), CopyStep.forFile(getProjectFilesystem(), binaryOutputPath, watchKitStubDir.resolve("WK")));
}
}
Aggregations