blob: a51b4bec3f57313837bd96d0599b6bb8dc252d5b [file] [log] [blame]
Googlereb00ae62024-04-23 13:18:49 -07001// Copyright 2024 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.skyframe;
15
16import com.google.devtools.build.lib.actions.ThreadStateReceiver;
17import com.google.devtools.build.lib.cmdline.PackageIdentifier;
18import com.google.devtools.build.lib.packages.CachingPackageLocator;
19import com.google.devtools.build.lib.packages.Globber;
20import com.google.devtools.build.lib.packages.NonSkyframeGlobber;
21import com.google.devtools.build.lib.packages.Package;
22import com.google.devtools.build.lib.packages.PackageFactory;
23import com.google.devtools.build.lib.vfs.Root;
24import com.google.devtools.build.skyframe.SkyKey;
25import java.util.concurrent.Semaphore;
26import java.util.concurrent.atomic.AtomicBoolean;
27import java.util.concurrent.atomic.AtomicInteger;
28import java.util.concurrent.atomic.AtomicReference;
29import java.util.function.Function;
30import javax.annotation.Nullable;
31
32/**
33 * Computes the {@link PackageValue} without performing Skyframe globbing.
34 *
35 * <p>{@link PackageFunctionWithoutGlobDeps} subclass is created when the globbing strategy is
36 * {@link com.google.devtools.build.lib.skyframe.PackageFunction.GlobbingStrategy#NON_SKYFRAME},
37 * which is used for non-incremental evaluations with no GLOB nodes queried and stored in Skyframe.
38 */
39final class PackageFunctionWithoutGlobDeps extends PackageFunction {
40
41 PackageFunctionWithoutGlobDeps(
42 PackageFactory packageFactory,
43 CachingPackageLocator pkgLocator,
44 AtomicBoolean showLoadingProgress,
45 AtomicInteger numPackagesSuccessfullyLoaded,
46 @Nullable BzlLoadFunction bzlLoadFunctionForInlining,
47 @Nullable PackageProgressReceiver packageProgress,
48 ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile,
Googlerc5925da2024-10-21 08:47:37 -070049 ActionOnFilesystemErrorCodeLoadingBzlFile actionOnFilesystemErrorCodeLoadingBzlFile,
Googlereb00ae62024-04-23 13:18:49 -070050 boolean shouldUseRepoDotBazel,
51 Function<SkyKey, ThreadStateReceiver> threadStateReceiverFactoryForMetrics,
52 AtomicReference<Semaphore> cpuBoundSemaphore) {
53 super(
54 packageFactory,
55 pkgLocator,
56 showLoadingProgress,
57 numPackagesSuccessfullyLoaded,
58 bzlLoadFunctionForInlining,
59 packageProgress,
60 actionOnIOExceptionReadingBuildFile,
Googlerc5925da2024-10-21 08:47:37 -070061 actionOnFilesystemErrorCodeLoadingBzlFile,
Googlereb00ae62024-04-23 13:18:49 -070062 shouldUseRepoDotBazel,
63 threadStateReceiverFactoryForMetrics,
64 cpuBoundSemaphore);
65 }
66
67 private static final class LoadedPackageWithoutDeps extends LoadedPackage {
68 LoadedPackageWithoutDeps(Package.Builder builder, long loadTimeNanos) {
69 super(builder, loadTimeNanos);
70 }
71 }
72
73 @Override
74 protected void handleGlobDepsAndPropagateFilesystemExceptions(
75 PackageIdentifier packageIdentifier,
Googler5cf60bd2024-05-01 16:07:26 -070076 Root packageRoot,
Googlereb00ae62024-04-23 13:18:49 -070077 LoadedPackage loadedPackage,
78 Environment env,
79 boolean packageWasInError) {
80 // No-op for non-Skyframe globbing.
81 }
82
83 @Override
84 protected Globber makeGlobber(
85 NonSkyframeGlobber nonSkyframeGlobber,
86 PackageIdentifier packageId,
87 Root packageRoot,
88 Environment env) {
89 return nonSkyframeGlobber;
90 }
91
92 @Override
93 protected LoadedPackage newLoadedPackage(
94 Package.Builder packageBuilder, @Nullable Globber globber, long loadTimeNanos) {
95 return new LoadedPackageWithoutDeps(packageBuilder, loadTimeNanos);
96 }
97}