Search in sources :

Example 6 with ThreadSafe

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

the class FileSystemUtils method copyFile.

/**
   * Copies the file from location "from" to location "to", while overwriting a
   * potentially existing "to". File's last modified time, executable and
   * writable bits are also preserved.
   *
   * <p>If no error occurs, the method returns normally. If a parent directory does
   * not exist, a FileNotFoundException is thrown. An IOException is thrown when
   * other erroneous situations occur. (e.g. read errors)
   */
// but not atomic
@ThreadSafe
public static void copyFile(Path from, Path to) throws IOException {
    try {
        to.delete();
    } catch (IOException e) {
        throw new IOException("error copying file: " + "couldn't delete destination: " + e.getMessage());
    }
    asByteSource(from).copyTo(asByteSink(to));
    // Preserve mtime.
    to.setLastModifiedTime(from.getLastModifiedTime());
    if (!from.isWritable()) {
        // Make file read-only if original was read-only.
        to.setWritable(false);
    }
    // Copy executable bit.
    to.setExecutable(from.isExecutable());
}
Also used : IOException(java.io.IOException) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe) ConditionallyThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ConditionallyThreadSafe)

Example 7 with ThreadSafe

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

the class SkyQueryEnvironment method getTargetsMatchingPattern.

@ThreadSafe
@Override
public QueryTaskFuture<Void> getTargetsMatchingPattern(final QueryExpression owner, String pattern, Callback<Target> callback) {
    // Directly evaluate the target pattern, making use of packages in the graph.
    Pair<TargetPattern, ImmutableSet<PathFragment>> patternToEvalAndSubdirectoriesToExclude;
    try {
        patternToEvalAndSubdirectoriesToExclude = getPatternAndExcludes(pattern);
    } catch (TargetParsingException tpe) {
        try {
            reportBuildFileError(owner, tpe.getMessage());
        } catch (QueryException qe) {
            return immediateFailedFuture(qe);
        }
        return immediateSuccessfulFuture(null);
    } catch (InterruptedException ie) {
        return immediateCancelledFuture();
    }
    TargetPattern patternToEval = patternToEvalAndSubdirectoriesToExclude.getFirst();
    ImmutableSet<PathFragment> subdirectoriesToExclude = patternToEvalAndSubdirectoriesToExclude.getSecond();
    AsyncFunction<TargetParsingException, Void> reportBuildFileErrorAsyncFunction = new AsyncFunction<TargetParsingException, Void>() {

        @Override
        public ListenableFuture<Void> apply(TargetParsingException exn) throws QueryException {
            reportBuildFileError(owner, exn.getMessage());
            return Futures.immediateFuture(null);
        }
    };
    ListenableFuture<Void> evalFuture = patternToEval.evalAsync(resolver, subdirectoriesToExclude, callback, QueryException.class, executor);
    return QueryTaskFutureImpl.ofDelegate(Futures.catchingAsync(evalFuture, TargetParsingException.class, reportBuildFileErrorAsyncFunction));
}
Also used : QueryException(com.google.devtools.build.lib.query2.engine.QueryException) TargetPattern(com.google.devtools.build.lib.cmdline.TargetPattern) ImmutableSet(com.google.common.collect.ImmutableSet) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 8 with ThreadSafe

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

the class SkyQueryEnvironment method getBuildFiles.

@ThreadSafe
@Override
public Set<Target> getBuildFiles(QueryExpression caller, Set<Target> nodes, boolean buildFiles, boolean subincludes, boolean loads) throws QueryException {
    Set<Target> dependentFiles = new LinkedHashSet<>();
    Set<Package> seenPackages = new HashSet<>();
    // Keep track of seen labels, to avoid adding a fake subinclude label that also exists as a
    // real target.
    Set<Label> seenLabels = new HashSet<>();
    // extensions) for package "pkg", to "buildfiles".
    for (Target x : nodes) {
        Package pkg = x.getPackage();
        if (seenPackages.add(pkg)) {
            if (buildFiles) {
                addIfUniqueLabel(pkg.getBuildFile(), seenLabels, dependentFiles);
            }
            List<Label> extensions = new ArrayList<>();
            if (subincludes) {
                extensions.addAll(pkg.getSubincludeLabels());
            }
            if (loads) {
                extensions.addAll(pkg.getSkylarkFileDependencies());
            }
            for (Label subinclude : extensions) {
                addIfUniqueLabel(getSubincludeTarget(subinclude, pkg), seenLabels, dependentFiles);
                if (buildFiles) {
                    // Also add the BUILD file of the subinclude.
                    try {
                        addIfUniqueLabel(getSubincludeTarget(subinclude.getLocalTargetLabel("BUILD"), pkg), seenLabels, dependentFiles);
                    } catch (LabelSyntaxException e) {
                        throw new AssertionError("BUILD should always parse as a target name", e);
                    }
                }
            }
        }
    }
    return dependentFiles;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Target(com.google.devtools.build.lib.packages.Target) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) Label(com.google.devtools.build.lib.cmdline.Label) ArrayList(java.util.ArrayList) Package(com.google.devtools.build.lib.packages.Package) LinkedHashSet(java.util.LinkedHashSet) CompactHashSet(com.google.devtools.build.lib.collect.CompactHashSet) HashSet(java.util.HashSet) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 9 with ThreadSafe

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

the class SkyQueryEnvironment method makeTargetsFromPackageKeyToTargetKeyMap.

@ThreadSafe
public Map<SkyKey, Target> makeTargetsFromPackageKeyToTargetKeyMap(Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap) throws InterruptedException {
    ImmutableMap.Builder<SkyKey, Target> result = ImmutableMap.builder();
    Set<SkyKey> processedTargets = new HashSet<>();
    Map<SkyKey, SkyValue> packageMap = graph.getSuccessfulValues(packageKeyToTargetKeyMap.keySet());
    for (Map.Entry<SkyKey, SkyValue> entry : packageMap.entrySet()) {
        for (SkyKey targetKey : packageKeyToTargetKeyMap.get(entry.getKey())) {
            if (processedTargets.add(targetKey)) {
                try {
                    result.put(targetKey, ((PackageValue) entry.getValue()).getPackage().getTarget((SKYKEY_TO_LABEL.apply(targetKey)).getName()));
                } catch (NoSuchTargetException e) {
                // Skip missing target.
                }
            }
        }
    }
    return result.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Target(com.google.devtools.build.lib.packages.Target) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashSet(java.util.LinkedHashSet) CompactHashSet(com.google.devtools.build.lib.collect.CompactHashSet) HashSet(java.util.HashSet) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 10 with ThreadSafe

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

the class FdoSupport method buildProfileForLtoBackend.

/**
   * Adds the AutoFDO profile path to the variable builder and returns the profile artifact.
   * If AutoFDO is disabled, no build variable is added and returns null.
   */
@ThreadSafe
public Artifact buildProfileForLtoBackend(FdoSupportProvider fdoSupportProvider, FeatureConfiguration featureConfiguration, CcToolchainFeatures.Variables.Builder buildVariables, RuleContext ruleContext) {
    if (!featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
        return null;
    }
    Artifact profile = fdoSupportProvider.getProfileArtifact();
    buildVariables.addStringVariable("fdo_profile_path", profile.getExecPathString());
    return profile;
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) 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