Search in sources :

Example 81 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class CompilationSupport method frameworkNames.

/**
   * Returns all framework names to pass to the linker using {@code -framework} flags. For a
   * framework in the directory foo/bar.framework, the name is "bar". Each framework is found
   * without using the full path by means of the framework search paths. Search paths are added by
   * {@link#commonLinkAndCompileFlagsForClang(ObjcProvider, ObjcConfiguration, AppleConfiguration)})
   *
   * <p>It's awful that we can't pass the full path to the framework and avoid framework search
   * paths, but this is imposed on us by clang. clang does not support passing the full path to the
   * framework, so Bazel cannot do it either.
   */
protected Set<String> frameworkNames(ObjcProvider provider) {
    Set<String> names = new LinkedHashSet<>();
    Iterables.addAll(names, SdkFramework.names(provider.get(SDK_FRAMEWORK)));
    for (PathFragment frameworkDir : Iterables.concat(provider.get(STATIC_FRAMEWORK_DIR), provider.get(DYNAMIC_FRAMEWORK_DIR))) {
        String segment = frameworkDir.getBaseName();
        Preconditions.checkState(segment.endsWith(FRAMEWORK_SUFFIX), "expect %s to end with %s, but it does not", segment, FRAMEWORK_SUFFIX);
        names.add(segment.substring(0, segment.length() - FRAMEWORK_SUFFIX.length()));
    }
    return names;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 82 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class CompilationSupport method validateAttributes.

/**
   * Validates compilation-related attributes on this rule.
   *
   * @return this compilation support
   * @throws RuleErrorException if there are attribute errors
   */
CompilationSupport validateAttributes() throws RuleErrorException {
    for (PathFragment absoluteInclude : Iterables.filter(attributes.includes(), PathFragment.IS_ABSOLUTE)) {
        ruleContext.attributeError("includes", String.format(ABSOLUTE_INCLUDES_PATH_FORMAT, absoluteInclude));
    }
    if (ruleContext.attributes().has("srcs", BuildType.LABEL_LIST)) {
        ImmutableSet<Artifact> hdrsSet = ImmutableSet.copyOf(attributes.hdrs());
        ImmutableSet<Artifact> srcsSet = ImmutableSet.copyOf(ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list());
        // Check for overlap between srcs and hdrs.
        for (Artifact header : Sets.intersection(hdrsSet, srcsSet)) {
            String path = header.getRootRelativePath().toString();
            ruleContext.attributeWarning("srcs", String.format(FILE_IN_SRCS_AND_HDRS_WARNING_FORMAT, path));
        }
        // Check for overlap between srcs and non_arc_srcs.
        ImmutableSet<Artifact> nonArcSrcsSet = ImmutableSet.copyOf(ruleContext.getPrerequisiteArtifacts("non_arc_srcs", Mode.TARGET).list());
        for (Artifact conflict : Sets.intersection(nonArcSrcsSet, srcsSet)) {
            String path = conflict.getRootRelativePath().toString();
            ruleContext.attributeError("srcs", String.format(FILE_IN_SRCS_AND_NON_ARC_SRCS_ERROR_FORMAT, path));
        }
    }
    ruleContext.assertNoErrors();
    return this;
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 83 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class IntermediateArtifacts method inUniqueObjsDir.

private Artifact inUniqueObjsDir(Artifact source, String extension) {
    PathFragment uniqueDir = new PathFragment("_objs").getRelative(ruleContext.getLabel().getName());
    PathFragment sourceFile = uniqueDir.getRelative(source.getRootRelativePath());
    PathFragment scopeRelativePath = FileSystemUtils.replaceExtension(sourceFile, extension);
    return scopedArtifact(scopeRelativePath);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 84 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class IosFramework method getExtraArtifacts.

/**
   * Returns a map of original {@code Artifact} to symlinked {@code Artifact} inside framework
   * bundle.
   */
private ImmutableMap<Artifact, Artifact> getExtraArtifacts(RuleContext ruleContext) {
    IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext);
    ImmutableList<Pair<Artifact, Label>> headers = ImmutableList.copyOf(CcCommon.getHeaders(ruleContext));
    ImmutableMap.Builder<Artifact, Artifact> builder = new ImmutableMap.Builder<>();
    // Create framework binary
    Artifact frameworkBinary = outputArtifact(ruleContext, new PathFragment(bundleName(ruleContext)));
    builder.put(intermediateArtifacts.combinedArchitectureBinary(), frameworkBinary);
    // Create framework headers
    for (Pair<Artifact, Label> header : headers) {
        Artifact frameworkHeader = outputArtifact(ruleContext, new PathFragment("Headers/" + header.first.getFilename()));
        builder.put(header.first, frameworkHeader);
    }
    return builder.build();
}
Also used : RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Label(com.google.devtools.build.lib.cmdline.Label) ImmutableMap(com.google.common.collect.ImmutableMap) Artifact(com.google.devtools.build.lib.actions.Artifact) Pair(com.google.devtools.build.lib.util.Pair)

Example 85 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class BundleSupport method registerConvertStringsActions.

private void registerConvertStringsActions(ObjcProvider objcProvider) {
    for (Artifact strings : objcProvider.get(ObjcProvider.STRINGS)) {
        Artifact bundled = bundling.getIntermediateArtifacts().convertedStringsFile(strings);
        ruleContext.registerAction(ObjcRuleClasses.spawnAppleEnvActionBuilder(appleConfiguration, platform).setMnemonic("ConvertStringsPlist").setExecutable(new PathFragment("/usr/bin/plutil")).setCommandLine(CustomCommandLine.builder().add("-convert").add("binary1").addExecPath("-o", bundled).add("--").addPath(strings.getExecPath()).build()).addInput(strings).addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()).addOutput(bundled).build(ruleContext));
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

PathFragment (com.google.devtools.build.lib.vfs.PathFragment)512 Test (org.junit.Test)208 Artifact (com.google.devtools.build.lib.actions.Artifact)184 Path (com.google.devtools.build.lib.vfs.Path)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)65 SkyKey (com.google.devtools.build.skyframe.SkyKey)56 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)35 ImmutableList (com.google.common.collect.ImmutableList)32 Root (com.google.devtools.build.lib.actions.Root)32 HashMap (java.util.HashMap)27 Label (com.google.devtools.build.lib.cmdline.Label)26 LinkedHashMap (java.util.LinkedHashMap)26 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)23 ImmutableMap (com.google.common.collect.ImmutableMap)22 Map (java.util.Map)21 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)20 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)16 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)16 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)16