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());
}
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));
}
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;
}
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();
}
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;
}
Aggregations