Search in sources :

Example 1 with WriteFile

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));
                    }
                }
            }
        }
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) WriteFile(com.facebook.buck.file.WriteFile) MkdirStep(com.facebook.buck.step.fs.MkdirStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Example 2 with WriteFile

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();
}
Also used : WriteFile(com.facebook.buck.file.WriteFile) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) Tool(com.facebook.buck.rules.Tool)

Example 3 with WriteFile

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();
}
Also used : WriteFile(com.facebook.buck.file.WriteFile) BuildTarget(com.facebook.buck.model.BuildTarget) WriteStringTemplateRule(com.facebook.buck.rules.WriteStringTemplateRule) Tool(com.facebook.buck.rules.Tool)

Example 4 with WriteFile

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());
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) WriteFile(com.facebook.buck.file.WriteFile) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule)

Example 5 with WriteFile

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")));
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) WriteFile(com.facebook.buck.file.WriteFile) MkdirStep(com.facebook.buck.step.fs.MkdirStep)

Aggregations

WriteFile (com.facebook.buck.file.WriteFile)9 SourcePath (com.facebook.buck.rules.SourcePath)6 BuildTarget (com.facebook.buck.model.BuildTarget)5 BuildRule (com.facebook.buck.rules.BuildRule)5 Path (java.nio.file.Path)4 Tool (com.facebook.buck.rules.Tool)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)2 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 MkdirStep (com.facebook.buck.step.fs.MkdirStep)2 Archive (com.facebook.buck.cxx.Archive)1 CxxBinaryDescription (com.facebook.buck.cxx.CxxBinaryDescription)1 CxxDescriptionEnhancer (com.facebook.buck.cxx.CxxDescriptionEnhancer)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 CxxPlatforms (com.facebook.buck.cxx.CxxPlatforms)1 CxxPreprocessables (com.facebook.buck.cxx.CxxPreprocessables)1 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)1 CxxSource (com.facebook.buck.cxx.CxxSource)1 CxxSourceRuleFactory (com.facebook.buck.cxx.CxxSourceRuleFactory)1 CxxSourceTypes (com.facebook.buck.cxx.CxxSourceTypes)1