Search in sources :

Example 11 with ThreadSafe

use of com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe in project bazel by bazelbuild.

the class FdoSupport method configureCompilation.

/**
   * Configures a compile action builder by setting up command line options and
   * auxiliary inputs according to the FDO configuration. This method does
   * nothing If FDO is disabled.
   */
@ThreadSafe
public void configureCompilation(CppCompileActionBuilder builder, CcToolchainFeatures.Variables.Builder buildVariables, RuleContext ruleContext, PathFragment sourceName, PathFragment sourceExecPath, boolean usePic, FeatureConfiguration featureConfiguration, FdoSupportProvider fdoSupportProvider) {
    // It is a bug if this method is called with useLipo if lipo is disabled. However, it is legal
    // if is is called with !useLipo, even though lipo is enabled.
    LipoContextProvider lipoInputProvider = CppHelper.getLipoContextProvider(ruleContext);
    Preconditions.checkArgument(lipoInputProvider == null || lipoMode != LipoMode.OFF);
    // FDO is disabled -> do nothing.
    if ((fdoInstrument == null) && (fdoRoot == null)) {
        return;
    }
    if (featureConfiguration.isEnabled(CppRuleClasses.FDO_INSTRUMENT)) {
        buildVariables.addStringVariable("fdo_instrument_path", fdoInstrument.getPathString());
    }
    // Optimization phase
    if (fdoRoot != null) {
        AnalysisEnvironment env = ruleContext.getAnalysisEnvironment();
        // Declare dependency on contents of zip file.
        if (env.getSkyframeEnv().valuesMissing()) {
            return;
        }
        Iterable<Artifact> auxiliaryInputs = getAuxiliaryInputs(ruleContext, sourceName, sourceExecPath, usePic, lipoInputProvider, fdoSupportProvider);
        builder.addMandatoryInputs(auxiliaryInputs);
        if (!Iterables.isEmpty(auxiliaryInputs)) {
            if (featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
                buildVariables.addStringVariable("fdo_profile_path", getAutoProfilePath(fdoProfile, fdoRootExecPath).getPathString());
            }
            if (featureConfiguration.isEnabled(CppRuleClasses.FDO_OPTIMIZE)) {
                if (fdoMode == FdoMode.LLVM_FDO) {
                    buildVariables.addStringVariable("fdo_profile_path", getLLVMProfilePath(fdoProfile, fdoRootExecPath).getPathString());
                } else {
                    buildVariables.addStringVariable("fdo_profile_path", fdoRootExecPath.getPathString());
                }
            }
        }
    }
}
Also used : AnalysisEnvironment(com.google.devtools.build.lib.analysis.AnalysisEnvironment) Artifact(com.google.devtools.build.lib.actions.Artifact) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 12 with ThreadSafe

use of com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe in project bazel by bazelbuild.

the class PrepareDepsOfPatternValue method keys.

/**
   * Returns an iterable of {@link PrepareDepsOfPatternSkyKeyOrException}, with {@link
   * TargetPatternKey} arguments. Negative target patterns of type other than {@link
   * Type#TARGETS_BELOW_DIRECTORY} are not permitted. If a provided pattern fails to parse or is
   * negative but not a {@link Type#TARGETS_BELOW_DIRECTORY}, an element in the returned iterable
   * will throw when its {@link PrepareDepsOfPatternSkyKeyOrException#getSkyKey} method is called
   * and will return the failing pattern when its {@link
   * PrepareDepsOfPatternSkyKeyOrException#getOriginalPattern} method is called.
   *
   * <p>There may be fewer returned elements than patterns provided as input. This function will
   * combine negative {@link Type#TARGETS_BELOW_DIRECTORY} patterns with preceding patterns to
   * return an iterable of SkyKeys that avoids loading excluded directories during evaluation.
   *
   * @param patterns The list of patterns, e.g. [//foo/..., -//foo/biz/...]. If a pattern's first
   *     character is "-", it is treated as a negative pattern.
   * @param offset The offset to apply to relative target patterns.
   */
@ThreadSafe
public static Iterable<PrepareDepsOfPatternSkyKeyOrException> keys(List<String> patterns, String offset) {
    List<TargetPatternSkyKeyOrException> keysMaybe = ImmutableList.copyOf(TargetPatternValue.keys(patterns, FilteringPolicies.NO_FILTER, offset));
    // This code path is evaluated only for query universe preloading, and the quadratic cost of
    // the code below (i.e. for each pattern, consider each later pattern as a candidate for
    // subdirectory exclusion) is only acceptable because all the use cases for query universe
    // preloading involve short (<10 items) pattern sequences.
    ImmutableList.Builder<PrepareDepsOfPatternSkyKeyOrException> builder = ImmutableList.builder();
    for (int i = 0; i < keysMaybe.size(); i++) {
        TargetPatternSkyKeyOrException keyMaybe = keysMaybe.get(i);
        SkyKey skyKey;
        try {
            skyKey = keyMaybe.getSkyKey();
        } catch (TargetParsingException e) {
            // keyMaybe.getSkyKey() may throw TargetParsingException if its corresponding pattern
            // failed to parse. If so, wrap the exception and return it, so that our caller can
            // deal with it.
            skyKey = null;
            builder.add(new PrepareDepsOfPatternSkyKeyException(e, keyMaybe.getOriginalPattern()));
        }
        if (skyKey != null) {
            TargetPatternKey targetPatternKey = (TargetPatternKey) skyKey.argument();
            if (targetPatternKey.isNegative()) {
                if (!targetPatternKey.getParsedPattern().getType().equals(Type.TARGETS_BELOW_DIRECTORY)) {
                    builder.add(new PrepareDepsOfPatternSkyKeyException(new TargetParsingException("Negative target patterns of types other than \"targets below directory\"" + " are not permitted."), targetPatternKey.toString()));
                }
            // Otherwise it's a negative TBD pattern which was combined with previous patterns as an
            // excluded directory. These can be skipped because there's no PrepareDepsOfPattern work
            // to be done for them.
            } else {
                builder.add(new PrepareDepsOfPatternSkyKeyValue(setExcludedDirectories(targetPatternKey, excludedDirectoriesBeneath(targetPatternKey, i, keysMaybe))));
            }
        }
    }
    return builder.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) TargetPatternKey(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ImmutableList(com.google.common.collect.ImmutableList) TargetPatternSkyKeyOrException(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Aggregations

ThreadSafe (com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)12 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Artifact (com.google.devtools.build.lib.actions.Artifact)2 Label (com.google.devtools.build.lib.cmdline.Label)2 TargetPattern (com.google.devtools.build.lib.cmdline.TargetPattern)2 CompactHashSet (com.google.devtools.build.lib.collect.CompactHashSet)2 ConditionallyThreadSafe (com.google.devtools.build.lib.concurrent.ThreadSafety.ConditionallyThreadSafe)2 Package (com.google.devtools.build.lib.packages.Package)2 Target (com.google.devtools.build.lib.packages.Target)2 QueryException (com.google.devtools.build.lib.query2.engine.QueryException)2 PackageValue (com.google.devtools.build.lib.skyframe.PackageValue)2 SkyValue (com.google.devtools.build.skyframe.SkyValue)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2