Search in sources :

Example 11 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class AppleTestDescription method createTestLibraryRule.

private <A extends Arg> BuildRule createTestLibraryRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args, Optional<SourcePath> testHostAppBinarySourcePath, ImmutableSet<BuildTarget> blacklist, BuildTarget libraryTarget) throws NoSuchBuildTargetException {
    BuildTarget existingLibraryTarget = libraryTarget.withAppendedFlavors(AppleDebuggableBinary.RULE_FLAVOR, CxxStrip.RULE_FLAVOR).withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
    Optional<BuildRule> existingLibrary = resolver.getRuleOptional(existingLibraryTarget);
    BuildRule library;
    if (existingLibrary.isPresent()) {
        library = existingLibrary.get();
    } else {
        library = appleLibraryDescription.createLibraryBuildRule(targetGraph, params.withBuildTarget(libraryTarget), resolver, args, // we'll just link them statically.
        Optional.of(Linker.LinkableDepType.STATIC), testHostAppBinarySourcePath, blacklist);
        resolver.addToIndex(library);
    }
    return library;
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule)

Example 12 with BuildRule

use of com.facebook.buck.rules.BuildRule 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 13 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class MultiarchFile method copyLinkMaps.

private void copyLinkMaps(BuildableContext buildableContext, ImmutableList.Builder<Step> steps) {
    Path linkMapDir = Paths.get(output + "-LinkMap");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), linkMapDir));
    for (SourcePath thinBinary : thinBinaries) {
        Optional<BuildRule> maybeRule = ruleFinder.getRule(thinBinary);
        if (maybeRule.isPresent()) {
            BuildRule rule = maybeRule.get();
            if (rule instanceof CxxBinary) {
                rule = ((CxxBinary) rule).getLinkRule();
            }
            if (rule instanceof CxxLink && !rule.getBuildTarget().getFlavors().contains(LinkerMapMode.NO_LINKER_MAP.getFlavor())) {
                Optional<Path> maybeLinkerMapPath = ((CxxLink) rule).getLinkerMapPath();
                if (maybeLinkerMapPath.isPresent()) {
                    Path source = maybeLinkerMapPath.get();
                    Path dest = linkMapDir.resolve(source.getFileName());
                    steps.add(CopyStep.forFile(getProjectFilesystem(), source, dest));
                    buildableContext.recordArtifact(dest);
                }
            }
        }
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxBinary(com.facebook.buck.cxx.CxxBinary) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) CxxLink(com.facebook.buck.cxx.CxxLink)

Example 14 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class MultiarchFileInfos method requireMultiarchRule.

/**
   * Generate a fat rule from thin rules.
   *
   * Invariant: thinRules contain all the thin rules listed in info.getThinTargets().
   */
public static BuildRule requireMultiarchRule(BuildRuleParams params, BuildRuleResolver resolver, MultiarchFileInfo info, ImmutableSortedSet<BuildRule> thinRules) {
    Optional<BuildRule> existingRule = resolver.getRuleOptional(info.getFatTarget());
    if (existingRule.isPresent()) {
        return existingRule.get();
    }
    ImmutableSortedSet<SourcePath> inputs = FluentIterable.from(thinRules).transform(BuildRule::getSourcePathToOutput).toSortedSet(Ordering.natural());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    MultiarchFile multiarchFile = new MultiarchFile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(thinRules)), ruleFinder, info.getRepresentativePlatform().getLipo(), inputs, BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), "%s"));
    resolver.addToIndex(multiarchFile);
    return multiarchFile;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 15 with BuildRule

use of com.facebook.buck.rules.BuildRule in project buck by facebook.

the class CxxGenruleDescription method getMacroHandler.

@Override
protected <A extends Arg> MacroHandler getMacroHandler(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, TargetGraph targetGraph, A args) {
    CxxPlatform cxxPlatform = cxxPlatforms.getRequiredValue(buildTarget);
    ImmutableMap.Builder<String, MacroExpander> macros = ImmutableMap.builder();
    macros.put("exe", new ExecutableMacroExpander());
    macros.put("location", new CxxLocationMacroExpander(cxxPlatform));
    macros.put("platform-name", new StringExpander(cxxPlatform.getFlavor().toString()));
    macros.put("location-platform", new LocationMacroExpander() {

        @Override
        protected BuildRule resolve(BuildRuleResolver resolver, LocationMacro input) throws MacroException {
            try {
                return resolver.requireRule(input.getTarget().withAppendedFlavors(cxxPlatform.getFlavor()));
            } catch (NoSuchBuildTargetException e) {
                throw new MacroException(e.getHumanReadableErrorMessage());
            }
        }
    });
    macros.put("cc", new ToolExpander(cxxPlatform.getCc().resolve(resolver)));
    macros.put("cxx", new ToolExpander(cxxPlatform.getCxx().resolve(resolver)));
    ImmutableList<String> asflags = cxxPlatform.getAsflags();
    ImmutableList<String> cflags = cxxPlatform.getCflags();
    ImmutableList<String> cxxflags = cxxPlatform.getCxxflags();
    macros.put("cflags", new StringExpander(shquoteJoin(Iterables.concat(cflags, asflags))));
    macros.put("cxxflags", new StringExpander(shquoteJoin(Iterables.concat(cxxflags, asflags))));
    macros.put("cppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.C));
    macros.put("cxxppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.CXX));
    macros.put("ld", new ToolExpander(cxxPlatform.getLd().resolve(resolver)));
    for (Linker.LinkableDepType depType : Linker.LinkableDepType.values()) {
        for (Filter filter : Filter.values()) {
            macros.put(String.format("ldflags-%s%s", depType.toString().toLowerCase().replace('_', '-'), filter == Filter.PARAM ? "-filter" : ""), new CxxLinkerFlagsExpander(buildTarget, filesystem, cxxPlatform, depType, args.out, filter));
        }
    }
    return new MacroHandler(macros.build());
}
Also used : ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) AbstractMacroExpander(com.facebook.buck.rules.macros.AbstractMacroExpander) MacroExpander(com.facebook.buck.rules.macros.MacroExpander) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StringExpander(com.facebook.buck.rules.macros.StringExpander) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) LocationMacro(com.facebook.buck.rules.macros.LocationMacro) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException)

Aggregations

BuildRule (com.facebook.buck.rules.BuildRule)361 BuildTarget (com.facebook.buck.model.BuildTarget)199 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)190 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 Test (org.junit.Test)175 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)165 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)162 SourcePath (com.facebook.buck.rules.SourcePath)118 Path (java.nio.file.Path)95 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)70 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)66 TargetGraph (com.facebook.buck.rules.TargetGraph)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)61 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)61 ImmutableList (com.google.common.collect.ImmutableList)58 PathSourcePath (com.facebook.buck.rules.PathSourcePath)51 ImmutableSet (com.google.common.collect.ImmutableSet)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 RuleKey (com.facebook.buck.rules.RuleKey)43