Googler | eb00ae6 | 2024-04-23 13:18:49 -0700 | [diff] [blame] | 1 | // 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. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
| 16 | import com.google.devtools.build.lib.actions.ThreadStateReceiver; |
| 17 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
| 18 | import com.google.devtools.build.lib.packages.CachingPackageLocator; |
| 19 | import com.google.devtools.build.lib.packages.Globber; |
| 20 | import com.google.devtools.build.lib.packages.NonSkyframeGlobber; |
| 21 | import com.google.devtools.build.lib.packages.Package; |
| 22 | import com.google.devtools.build.lib.packages.PackageFactory; |
| 23 | import com.google.devtools.build.lib.vfs.Root; |
| 24 | import com.google.devtools.build.skyframe.SkyKey; |
| 25 | import java.util.concurrent.Semaphore; |
| 26 | import java.util.concurrent.atomic.AtomicBoolean; |
| 27 | import java.util.concurrent.atomic.AtomicInteger; |
| 28 | import java.util.concurrent.atomic.AtomicReference; |
| 29 | import java.util.function.Function; |
| 30 | import 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 | */ |
| 39 | final 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, |
Googler | c5925da | 2024-10-21 08:47:37 -0700 | [diff] [blame] | 49 | ActionOnFilesystemErrorCodeLoadingBzlFile actionOnFilesystemErrorCodeLoadingBzlFile, |
Googler | eb00ae6 | 2024-04-23 13:18:49 -0700 | [diff] [blame] | 50 | 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, |
Googler | c5925da | 2024-10-21 08:47:37 -0700 | [diff] [blame] | 61 | actionOnFilesystemErrorCodeLoadingBzlFile, |
Googler | eb00ae6 | 2024-04-23 13:18:49 -0700 | [diff] [blame] | 62 | 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, |
Googler | 5cf60bd | 2024-05-01 16:07:26 -0700 | [diff] [blame] | 76 | Root packageRoot, |
Googler | eb00ae6 | 2024-04-23 13:18:49 -0700 | [diff] [blame] | 77 | 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 | } |