Search in sources :

Example 1 with BuildRuleResolver

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

the class ProjectGenerator method resolveSourcePath.

private Path resolveSourcePath(SourcePath sourcePath) {
    if (sourcePath instanceof PathSourcePath) {
        return ((PathSourcePath) sourcePath).getRelativePath();
    }
    Preconditions.checkArgument(sourcePath instanceof BuildTargetSourcePath);
    BuildTargetSourcePath<?> buildTargetSourcePath = (BuildTargetSourcePath<?>) sourcePath;
    BuildTarget buildTarget = buildTargetSourcePath.getTarget();
    TargetNode<?, ?> node = targetGraph.get(buildTarget);
    Optional<TargetNode<ExportFileDescription.Arg, ?>> exportFileNode = node.castArg(ExportFileDescription.Arg.class);
    if (!exportFileNode.isPresent()) {
        BuildRuleResolver resolver = buildRuleResolverForNode.apply(node);
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
        SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
        Path output = pathResolver.getRelativePath(sourcePath);
        if (output == null) {
            throw new HumanReadableException("The target '%s' does not have an output.", node.getBuildTarget());
        }
        requiredBuildTargetsBuilder.add(buildTarget);
        return output;
    }
    Optional<SourcePath> src = exportFileNode.get().getConstructorArg().src;
    if (!src.isPresent()) {
        return buildTarget.getBasePath().resolve(buildTarget.getShortNameAndFlavorPostfix());
    }
    return resolveSourcePath(src.get());
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) TargetNode(com.facebook.buck.rules.TargetNode) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExportFileDescription(com.facebook.buck.shell.ExportFileDescription)

Example 2 with BuildRuleResolver

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

the class ProjectGenerator method getPublicCxxHeaders.

private ImmutableSortedMap<Path, SourcePath> getPublicCxxHeaders(TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode) {
    CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
    if (arg instanceof AppleNativeTargetDescriptionArg) {
        Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg, targetNode.getBuildTarget());
        ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions.convertAppleHeadersToPublicCxxHeaders(this::resolveSourcePath, headerPathPrefix, arg);
        return convertMapKeysToPaths(cxxHeaders);
    } else {
        BuildRuleResolver resolver = buildRuleResolverForNode.apply(targetNode);
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
        SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
        try {
            return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer.parseExportedHeaders(targetNode.getBuildTarget(), resolver, ruleFinder, pathResolver, Optional.empty(), arg));
        } catch (NoSuchBuildTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) NSString(com.dd.plist.NSString) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 3 with BuildRuleResolver

use of com.facebook.buck.rules.BuildRuleResolver 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)

Example 4 with BuildRuleResolver

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

the class ProjectCommand method writeProjectAndGetRequiredBuildTargets.

private ImmutableSet<BuildTarget> writeProjectAndGetRequiredBuildTargets(CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets) throws IOException {
    ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
    BuckConfig buckConfig = params.getBuckConfig();
    BuildRuleResolver ruleResolver = result.getResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    JavacOptions javacOptions = buckConfig.getView(JavaBuckConfig.class).getDefaultJavacOptions();
    IjProject project = new IjProject(targetGraphAndTargets, getJavaPackageFinder(buckConfig), JavaFileParser.createJavaFileParser(javacOptions), ruleResolver, sourcePathResolver, ruleFinder, params.getCell().getFilesystem(), getIntellijAggregationMode(buckConfig), buckConfig);
    return project.write(runIjCleaner, getRemoveUnusedLibraries(buckConfig), excludeArtifacts || getExcludeArtifactsFromConfig(buckConfig));
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) IjProject(com.facebook.buck.jvm.java.intellij.IjProject) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 5 with BuildRuleResolver

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

the class VerifyCachesCommand method verifyRuleKeyCache.

private boolean verifyRuleKeyCache(PrintStream stdOut, int ruleKeySeed, FileHashCache fileHashCache, RuleKeyCacheRecycler<RuleKey> recycler) {
    ImmutableList<Map.Entry<BuildRule, RuleKey>> contents = recycler.getCachedBuildRules();
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(ruleKeySeed);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    contents.forEach(e -> resolver.addToIndex(e.getKey()));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(fieldLoader, fileHashCache, pathResolver, ruleFinder);
    stdOut.println(String.format("Examining %d build rule keys.", contents.size()));
    ImmutableList<BuildRule> mismatches = RichStream.from(contents).filter(entry -> !defaultRuleKeyFactory.build(entry.getKey()).equals(entry.getValue())).map(Map.Entry::getKey).toImmutableList();
    if (mismatches.isEmpty()) {
        stdOut.println("No rule key cache errors found.");
    } else {
        stdOut.println("Found rule key cache errors:");
        for (BuildRule rule : mismatches) {
            stdOut.println(String.format("  %s", rule));
        }
    }
    return true;
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Aggregations

BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)622 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)578 Test (org.junit.Test)540 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)402 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)376 BuildTarget (com.facebook.buck.model.BuildTarget)287 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)240 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)211 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 TargetGraph (com.facebook.buck.rules.TargetGraph)196 BuildRule (com.facebook.buck.rules.BuildRule)185 Path (java.nio.file.Path)136 SourcePath (com.facebook.buck.rules.SourcePath)133 PathSourcePath (com.facebook.buck.rules.PathSourcePath)104 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)83 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)75 RuleKey (com.facebook.buck.rules.RuleKey)71 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)54