Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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.buildtool; |
| 15 | |
mstaib | d9b141d | 2017-09-14 20:47:31 +0200 | [diff] [blame] | 16 | import static com.google.common.collect.ImmutableSet.toImmutableSet; |
Eric Fellheimer | e9b41c6 | 2016-06-14 15:39:51 +0000 | [diff] [blame] | 17 | |
steinman | 13a628a | 2019-01-09 08:39:32 -0800 | [diff] [blame] | 18 | import com.google.common.annotations.VisibleForTesting; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 19 | import com.google.common.base.Predicate; |
| 20 | import com.google.common.base.Stopwatch; |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 21 | import com.google.common.base.Throwables; |
Philipp Wollermann | 45bf15b | 2015-06-18 13:06:16 +0000 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableList; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.common.collect.ImmutableMap; |
| 24 | import com.google.common.collect.ImmutableSet; |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 25 | import com.google.common.collect.ImmutableSortedSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 26 | import com.google.devtools.build.lib.actions.Action; |
| 27 | import com.google.devtools.build.lib.actions.ActionCacheChecker; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.devtools.build.lib.actions.ActionGraph; |
ulfjack | 5b99e50 | 2017-07-20 22:22:36 +0200 | [diff] [blame] | 29 | import com.google.devtools.build.lib.actions.ActionInputPrefetcher; |
Ulf Adams | 3d67e00 | 2016-03-29 16:23:01 +0000 | [diff] [blame] | 30 | import com.google.devtools.build.lib.actions.ArtifactFactory; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | import com.google.devtools.build.lib.actions.BuildFailedException; |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 32 | import com.google.devtools.build.lib.actions.DynamicStrategyRegistry; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | import com.google.devtools.build.lib.actions.Executor; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | import com.google.devtools.build.lib.actions.ExecutorInitException; |
| 35 | import com.google.devtools.build.lib.actions.LocalHostCapacity; |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 36 | import com.google.devtools.build.lib.actions.PackageRoots; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 37 | import com.google.devtools.build.lib.actions.ResourceManager; |
Mark Schaller | dffb6ee | 2015-02-25 20:01:01 +0000 | [diff] [blame] | 38 | import com.google.devtools.build.lib.actions.ResourceSet; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | import com.google.devtools.build.lib.actions.TestExecException; |
| 40 | import com.google.devtools.build.lib.actions.cache.ActionCache; |
jmmv | ccb43ee | 2017-08-30 22:07:10 +0200 | [diff] [blame] | 41 | import com.google.devtools.build.lib.actions.cache.Protos.ActionCacheStatistics; |
ulfjack | c23bdac | 2018-06-13 03:06:16 -0700 | [diff] [blame] | 42 | import com.google.devtools.build.lib.analysis.AnalysisResult; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | import com.google.devtools.build.lib.analysis.ConfiguredTarget; |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 44 | import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper; |
Lukacs Berki | 7b2f2e8 | 2016-11-23 14:16:43 +0000 | [diff] [blame] | 46 | import com.google.devtools.build.lib.analysis.actions.SymlinkTreeActionContext; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 47 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
brandjon | 7b5043f | 2019-11-25 12:30:22 -0800 | [diff] [blame] | 48 | import com.google.devtools.build.lib.analysis.config.BuildOptions; |
| 49 | import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; |
schmitt | 4d6aff9 | 2020-01-13 10:49:30 -0800 | [diff] [blame] | 50 | import com.google.devtools.build.lib.analysis.test.TestActionContext; |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 51 | import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.ConvenienceSymlink; |
| 52 | import com.google.devtools.build.lib.buildtool.BuildRequestOptions.ConvenienceSymlinksMode; |
| 53 | import com.google.devtools.build.lib.buildtool.buildevent.ConvenienceSymlinksIdentifiedEvent; |
arostovtsev | 20b056a | 2019-08-30 15:00:31 -0700 | [diff] [blame] | 54 | import com.google.devtools.build.lib.buildtool.buildevent.ExecRootPreparedEvent; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 55 | import com.google.devtools.build.lib.buildtool.buildevent.ExecutionPhaseCompleteEvent; |
| 56 | import com.google.devtools.build.lib.buildtool.buildevent.ExecutionStartingEvent; |
Kristina Chodorow | 33aada2 | 2016-06-22 14:23:47 +0000 | [diff] [blame] | 57 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 58 | import com.google.devtools.build.lib.events.Event; |
| 59 | import com.google.devtools.build.lib.events.EventHandler; |
| 60 | import com.google.devtools.build.lib.events.EventKind; |
| 61 | import com.google.devtools.build.lib.events.Reporter; |
Ulf Adams | dba3c83 | 2016-12-21 16:50:02 +0000 | [diff] [blame] | 62 | import com.google.devtools.build.lib.exec.BlazeExecutor; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | import com.google.devtools.build.lib.exec.CheckUpToDateFilter; |
| 64 | import com.google.devtools.build.lib.exec.ExecutionOptions; |
Ulf Adams | dba3c83 | 2016-12-21 16:50:02 +0000 | [diff] [blame] | 65 | import com.google.devtools.build.lib.exec.ExecutorBuilder; |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 66 | import com.google.devtools.build.lib.exec.ExecutorLifecycleListener; |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 67 | import com.google.devtools.build.lib.exec.ModuleActionContextRegistry; |
| 68 | import com.google.devtools.build.lib.exec.RemoteLocalFallbackRegistry; |
| 69 | import com.google.devtools.build.lib.exec.SpawnStrategyRegistry; |
| 70 | import com.google.devtools.build.lib.exec.SpawnStrategyResolver; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 71 | import com.google.devtools.build.lib.exec.SymlinkTreeStrategy; |
Nathan Harmata | d480301 | 2015-09-08 20:03:22 +0000 | [diff] [blame] | 72 | import com.google.devtools.build.lib.profiler.AutoProfiler; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 73 | import com.google.devtools.build.lib.profiler.ProfilePhase; |
| 74 | import com.google.devtools.build.lib.profiler.Profiler; |
| 75 | import com.google.devtools.build.lib.profiler.ProfilerTask; |
ulfjack | 4cf2ebd | 2018-06-11 06:00:36 -0700 | [diff] [blame] | 76 | import com.google.devtools.build.lib.profiler.SilentCloseable; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 77 | import com.google.devtools.build.lib.runtime.BlazeModule; |
| 78 | import com.google.devtools.build.lib.runtime.BlazeRuntime; |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 79 | import com.google.devtools.build.lib.runtime.CommandEnvironment; |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 80 | import com.google.devtools.build.lib.skyframe.AspectValue; |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 81 | import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 82 | import com.google.devtools.build.lib.skyframe.Builder; |
cpeyser | 8e9b28f | 2018-06-04 08:05:13 -0700 | [diff] [blame] | 83 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 84 | import com.google.devtools.build.lib.skyframe.SkyframeExecutor; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 85 | import com.google.devtools.build.lib.util.AbruptExitException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 86 | import com.google.devtools.build.lib.util.LoggingUtil; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 87 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
Eric Fellheimer | f3b43af | 2015-11-13 19:51:20 +0000 | [diff] [blame] | 88 | import com.google.devtools.build.lib.vfs.ModifiedFileSet; |
shahan | e35e8cf | 2018-06-18 08:14:01 -0700 | [diff] [blame] | 89 | import com.google.devtools.build.lib.vfs.OutputService; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 90 | import com.google.devtools.build.lib.vfs.Path; |
| 91 | import com.google.devtools.build.lib.vfs.PathFragment; |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 92 | import com.google.devtools.build.lib.vfs.Root; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 93 | import java.io.IOException; |
| 94 | import java.io.OutputStream; |
lberki | 0d8d4cf | 2017-09-05 16:01:44 +0200 | [diff] [blame] | 95 | import java.io.OutputStreamWriter; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 96 | import java.io.PrintWriter; |
lberki | 0d8d4cf | 2017-09-05 16:01:44 +0200 | [diff] [blame] | 97 | import java.nio.charset.StandardCharsets; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 98 | import java.util.Collection; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 99 | import java.util.HashSet; |
| 100 | import java.util.LinkedHashSet; |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 101 | import java.util.Optional; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 102 | import java.util.Set; |
Eric Fellheimer | 2db6a74 | 2015-04-28 21:38:43 +0000 | [diff] [blame] | 103 | import java.util.UUID; |
jmmv | ccb43ee | 2017-08-30 22:07:10 +0200 | [diff] [blame] | 104 | import java.util.concurrent.TimeUnit; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 105 | import java.util.logging.Level; |
| 106 | import java.util.logging.Logger; |
brandjon | 7b5043f | 2019-11-25 12:30:22 -0800 | [diff] [blame] | 107 | import javax.annotation.Nullable; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 108 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 109 | /** |
| 110 | * This class manages the execution phase. The entry point is {@link #executeBuild}. |
| 111 | * |
| 112 | * <p>This is only intended for use by {@link BuildTool}. |
| 113 | * |
mstaib | d9b141d | 2017-09-14 20:47:31 +0200 | [diff] [blame] | 114 | * <p>This class contains an ActionCache, and refers to the Blaze Runtime's BuildView and |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 115 | * PackageCache. |
| 116 | * |
| 117 | * @see BuildTool |
Kristina Chodorow | e423fdb | 2016-09-15 14:08:08 +0000 | [diff] [blame] | 118 | * @see com.google.devtools.build.lib.analysis.BuildView |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 119 | */ |
| 120 | public class ExecutionTool { |
lberki | 97abb52 | 2017-09-04 18:51:57 +0200 | [diff] [blame] | 121 | static final Logger logger = Logger.getLogger(ExecutionTool.class.getName()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 122 | |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 123 | private final CommandEnvironment env; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 124 | private final BlazeRuntime runtime; |
| 125 | private final BuildRequest request; |
| 126 | private BlazeExecutor executor; |
Ulf Adams | ccd5c0a | 2017-01-13 15:46:51 +0000 | [diff] [blame] | 127 | private final ActionInputPrefetcher prefetcher; |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 128 | private final SpawnStrategyRegistry spawnStrategyRegistry; |
| 129 | private final ModuleActionContextRegistry actionContextRegistry; |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 130 | private final ImmutableSet<ExecutorLifecycleListener> executorLifecycleListeners; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 131 | |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 132 | ExecutionTool(CommandEnvironment env, BuildRequest request) throws ExecutorInitException { |
| 133 | this.env = env; |
| 134 | this.runtime = env.getRuntime(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 135 | this.request = request; |
| 136 | |
felly | 472320c | 2018-10-29 14:27:00 -0700 | [diff] [blame] | 137 | try { |
| 138 | env.getExecRoot().createDirectoryAndParents(); |
| 139 | } catch (IOException e) { |
| 140 | throw new ExecutorInitException("Execroot creation failed", e); |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 141 | } |
Philipp Wollermann | 590ea39 | 2015-08-25 13:57:33 +0000 | [diff] [blame] | 142 | |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 143 | ExecutionOptions options = request.getOptions(ExecutionOptions.class); |
Ulf Adams | a0e3af4 | 2016-10-31 16:52:48 +0000 | [diff] [blame] | 144 | ExecutorBuilder builder = new ExecutorBuilder(); |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 145 | ModuleActionContextRegistry.Builder actionContextRegistryBuilder = |
| 146 | new ModuleActionContextRegistry.Builder() |
| 147 | // TODO(philwo): ExecutionTool should not modify action contexts on its own, instead |
| 148 | // these should be added and restricted in modules. |
| 149 | .restrictTo(TestActionContext.class, options.testStrategy) |
| 150 | .register( |
| 151 | SymlinkTreeActionContext.class, |
| 152 | new SymlinkTreeStrategy( |
| 153 | env.getOutputService(), env.getBlazeWorkspace().getBinTools())) |
| 154 | .register(SpawnStrategyResolver.class, new SpawnStrategyResolver()); |
| 155 | SpawnStrategyRegistry.Builder spawnStrategyRegistryBuilder = |
| 156 | new SpawnStrategyRegistry.Builder() |
| 157 | // TODO: Wrap in incompatible flag. |
| 158 | .useLegacyDescriptionFilterPrecedence(); |
Ulf Adams | a0e3af4 | 2016-10-31 16:52:48 +0000 | [diff] [blame] | 159 | for (BlazeModule module : runtime.getBlazeModules()) { |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 160 | try (SilentCloseable ignored = Profiler.instance().profile(module + ".executorInit")) { |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 161 | module.executorInit(env, request, builder); |
| 162 | } |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 163 | |
| 164 | try (SilentCloseable ignored = |
| 165 | Profiler.instance().profile(module + ".registerActionContexts")) { |
| 166 | module.registerActionContexts(actionContextRegistryBuilder, env, request); |
| 167 | } |
| 168 | |
| 169 | try (SilentCloseable ignored = |
| 170 | Profiler.instance().profile(module + ".registerSpawnStrategies")) { |
| 171 | module.registerSpawnStrategies(spawnStrategyRegistryBuilder, env); |
| 172 | } |
Ulf Adams | a0e3af4 | 2016-10-31 16:52:48 +0000 | [diff] [blame] | 173 | } |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 174 | |
| 175 | spawnStrategyRegistry = spawnStrategyRegistryBuilder.build(); |
| 176 | actionContextRegistryBuilder.register(SpawnStrategyRegistry.class, spawnStrategyRegistry); |
| 177 | actionContextRegistryBuilder.register(DynamicStrategyRegistry.class, spawnStrategyRegistry); |
| 178 | actionContextRegistryBuilder.register(RemoteLocalFallbackRegistry.class, spawnStrategyRegistry); |
| 179 | |
| 180 | actionContextRegistry = actionContextRegistryBuilder.build(); |
| 181 | executorLifecycleListeners = builder.getExecutorLifecycleListeners(); |
schmitt | 4d6aff9 | 2020-01-13 10:49:30 -0800 | [diff] [blame] | 182 | |
Ulf Adams | ccd5c0a | 2017-01-13 15:46:51 +0000 | [diff] [blame] | 183 | this.prefetcher = builder.getActionInputPrefetcher(); |
steinman | 3501b21 | 2019-03-25 12:36:43 -0700 | [diff] [blame] | 184 | |
| 185 | if (options.availableResources != null && options.removeLocalResources) { |
| 186 | throw new ExecutorInitException( |
| 187 | "--local_resources is deprecated. Please use " |
| 188 | + "--local_ram_resources and/or --local_cpu_resources"); |
| 189 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | Executor getExecutor() throws ExecutorInitException { |
| 193 | if (executor == null) { |
| 194 | executor = createExecutor(); |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 195 | for (ExecutorLifecycleListener executorLifecycleListener : executorLifecycleListeners) { |
| 196 | executorLifecycleListener.executorCreated(); |
| 197 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 198 | } |
| 199 | return executor; |
| 200 | } |
| 201 | |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 202 | /** Creates an executor for the current set of blaze runtime, execution options, and request. */ |
| 203 | private BlazeExecutor createExecutor() throws ExecutorInitException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 204 | return new BlazeExecutor( |
tomlu | f903eb5 | 2017-10-27 12:12:11 -0400 | [diff] [blame] | 205 | runtime.getFileSystem(), |
Ulf Adams | 94b72db | 2016-03-30 11:58:37 +0000 | [diff] [blame] | 206 | env.getExecRoot(), |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 207 | getReporter(), |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 208 | runtime.getClock(), |
| 209 | request, |
schmitt | 37aeabc | 2020-01-27 08:34:29 -0800 | [diff] [blame] | 210 | actionContextRegistry, |
| 211 | spawnStrategyRegistry); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void init() throws ExecutorInitException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 215 | getExecutor(); |
| 216 | } |
| 217 | |
| 218 | void shutdown() { |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 219 | for (ExecutorLifecycleListener executorLifecycleListener : executorLifecycleListeners) { |
| 220 | executorLifecycleListener.executionPhaseEnding(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
| 224 | /** |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 225 | * Performs the execution phase (phase 3) of the build, in which the Builder is applied to the |
| 226 | * action graph to bring the targets up to date. (This function will return prior to |
| 227 | * execution-proper if --nobuild was specified.) |
| 228 | * |
Eric Fellheimer | 2db6a74 | 2015-04-28 21:38:43 +0000 | [diff] [blame] | 229 | * @param buildId UUID of the build id |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 230 | * @param analysisResult the analysis phase output |
| 231 | * @param buildResult the mutable build result |
Lukacs Berki | 3ea4d44 | 2016-01-21 15:15:30 +0000 | [diff] [blame] | 232 | * @param packageRoots package roots collected from loading phase and BuildConfigurationCollection |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 233 | * creation. May be empty if {@link |
| 234 | * SkyframeExecutor#getForcedSingleSourceRootIfNoExecrootSymlinkCreation} is false. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 235 | */ |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 236 | void executeBuild( |
| 237 | UUID buildId, |
| 238 | AnalysisResult analysisResult, |
Laurent Le Brun | f3cf98f | 2016-06-17 13:36:24 +0000 | [diff] [blame] | 239 | BuildResult buildResult, |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 240 | PackageRoots packageRoots, |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 241 | TopLevelArtifactContext topLevelArtifactContext) |
Nathan Harmata | ca06fa2 | 2015-07-27 19:54:14 +0000 | [diff] [blame] | 242 | throws BuildFailedException, InterruptedException, TestExecException, AbruptExitException { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 243 | Stopwatch timer = Stopwatch.createStarted(); |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 244 | prepare(packageRoots, analysisResult.getNonSymlinkedDirectoriesUnderExecRoot()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 245 | |
| 246 | ActionGraph actionGraph = analysisResult.getActionGraph(); |
| 247 | |
Ulf Adams | 706b7f2 | 2015-10-20 09:06:45 +0000 | [diff] [blame] | 248 | OutputService outputService = env.getOutputService(); |
Eric Fellheimer | f3b43af | 2015-11-13 19:51:20 +0000 | [diff] [blame] | 249 | ModifiedFileSet modifiedOutputFiles = ModifiedFileSet.EVERYTHING_MODIFIED; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 250 | if (outputService != null) { |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 251 | try (SilentCloseable c = Profiler.instance().profile("outputService.startBuild")) { |
| 252 | modifiedOutputFiles = |
| 253 | outputService.startBuild( |
| 254 | env.getReporter(), buildId, request.getBuildOptions().finalizeActions); |
| 255 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 256 | } else { |
Kristina Chodorow | e423fdb | 2016-09-15 14:08:08 +0000 | [diff] [blame] | 257 | // TODO(bazel-team): this could be just another OutputService |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 258 | try (SilentCloseable c = Profiler.instance().profile("startLocalOutputBuild")) { |
| 259 | startLocalOutputBuild(); |
| 260 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 261 | } |
| 262 | |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 263 | if (outputService == null || !outputService.actionFileSystemType().inMemoryFileSystem()) { |
| 264 | // Must be created after the output path is created above. |
| 265 | createActionLogDirectory(); |
| 266 | } |
janakr | 0049e96 | 2017-04-05 21:41:23 +0000 | [diff] [blame] | 267 | |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 268 | handleConvenienceSymlinks(analysisResult); |
Lukacs Berki | 85c63c4 | 2016-01-22 09:25:20 +0000 | [diff] [blame] | 269 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 270 | ActionCache actionCache = getActionCache(); |
jmmv | 9573a0d | 2017-09-26 11:59:22 -0400 | [diff] [blame] | 271 | actionCache.resetStatistics(); |
Ulf Adams | 8061302 | 2015-09-16 09:11:33 +0000 | [diff] [blame] | 272 | SkyframeExecutor skyframeExecutor = env.getSkyframeExecutor(); |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 273 | Builder builder; |
| 274 | try (SilentCloseable c = Profiler.instance().profile("createBuilder")) { |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 275 | builder = createBuilder(request, actionCache, skyframeExecutor, modifiedOutputFiles); |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 276 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 277 | |
| 278 | // |
| 279 | // Execution proper. All statements below are logically nested in |
| 280 | // begin/end pairs. No early returns or exceptions please! |
| 281 | // |
| 282 | |
| 283 | Collection<ConfiguredTarget> configuredTargets = buildResult.getActualTargets(); |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 284 | try (SilentCloseable c = Profiler.instance().profile("ExecutionStartingEvent")) { |
| 285 | env.getEventBus().post(new ExecutionStartingEvent(configuredTargets)); |
| 286 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 287 | |
| 288 | getReporter().handle(Event.progress("Building...")); |
| 289 | |
| 290 | // Conditionally record dependency-checker log: |
| 291 | ExplanationHandler explanationHandler = |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 292 | installExplanationHandler( |
| 293 | request.getBuildOptions().explanationPath, request.getOptionsDescription()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 294 | |
cpeyser | 8e9b28f | 2018-06-04 08:05:13 -0700 | [diff] [blame] | 295 | Set<ConfiguredTargetKey> builtTargets = new HashSet<>(); |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 296 | Set<AspectKey> builtAspects = new HashSet<>(); |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 297 | Collection<AspectValue> aspects = analysisResult.getAspects(); |
| 298 | |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 299 | if (request.isRunningInEmacs()) { |
| 300 | // The syntax of this message is tightly constrained by lisp/progmodes/compile.el in emacs |
Klaus Aehlig | ad87c13 | 2017-08-14 12:20:39 +0200 | [diff] [blame] | 301 | request |
| 302 | .getOutErr() |
brandjon | 79712cb | 2019-12-04 10:01:17 -0800 | [diff] [blame] | 303 | .printErrLn(runtime.getProductName() + ": Entering directory `" + getExecRoot() + "/'"); |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 304 | } |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 305 | |
| 306 | Throwable catastrophe = null; |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 307 | boolean buildCompleted = false; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 308 | try { |
Googler | 594c32d | 2019-07-17 17:55:18 -0700 | [diff] [blame] | 309 | if (request.getViewOptions().discardAnalysisCache |
| 310 | || !skyframeExecutor.tracksStateForIncrementality()) { |
| 311 | // Free memory by removing cache entries that aren't going to be needed. |
| 312 | try (SilentCloseable c = Profiler.instance().profile("clearAnalysisCache")) { |
| 313 | env.getSkyframeBuildView() |
| 314 | .clearAnalysisCache(analysisResult.getTargetsToBuild(), analysisResult.getAspects()); |
| 315 | } |
| 316 | } |
| 317 | |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 318 | for (ExecutorLifecycleListener executorLifecycleListener : executorLifecycleListeners) { |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 319 | try (SilentCloseable c = |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 320 | Profiler.instance().profile(executorLifecycleListener + ".executionPhaseStarting")) { |
| 321 | executorLifecycleListener.executionPhaseStarting( |
janakr | ccb7456 | 2018-07-30 10:56:57 -0700 | [diff] [blame] | 322 | actionGraph, |
Googler | 184b454 | 2019-07-19 19:34:19 -0700 | [diff] [blame] | 323 | // If this supplier is ever consumed by more than one ActionContextProvider, it can be |
| 324 | // pulled out of the loop and made a memoizing supplier. |
| 325 | () -> |
| 326 | TopLevelArtifactHelper.makeTopLevelArtifactsToOwnerLabels( |
| 327 | analysisResult, aspects)); |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 328 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 329 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 330 | skyframeExecutor.drainChangedFiles(); |
| 331 | |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 332 | try (SilentCloseable c = Profiler.instance().profile("configureResourceManager")) { |
ulfjack | 985a34ad | 2019-08-09 01:51:15 -0700 | [diff] [blame] | 333 | configureResourceManager(env.getLocalResourceManager(), request); |
ulfjack | ef5b63d | 2018-06-15 07:19:11 -0700 | [diff] [blame] | 334 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 335 | |
| 336 | Profiler.instance().markPhase(ProfilePhase.EXECUTE); |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 337 | builder.buildArtifacts( |
Ulf Adams | 5b9009b | 2015-09-24 09:52:53 +0000 | [diff] [blame] | 338 | env.getReporter(), |
janakr | ccb7456 | 2018-07-30 10:56:57 -0700 | [diff] [blame] | 339 | analysisResult.getTopLevelArtifactsToOwnerLabels().getArtifacts(), |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 340 | analysisResult.getParallelTests(), |
| 341 | analysisResult.getExclusiveTests(), |
| 342 | analysisResult.getTargetsToBuild(), |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 343 | analysisResult.getTargetsToSkip(), |
Dmitry Lomov | e2033b1 | 2015-08-19 16:57:49 +0000 | [diff] [blame] | 344 | analysisResult.getAspects(), |
| 345 | executor, |
| 346 | builtTargets, |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 347 | builtAspects, |
tomlu | 2661be8 | 2018-08-30 08:30:01 -0700 | [diff] [blame] | 348 | request, |
Googler | bfd4e24 | 2016-07-15 22:23:37 +0000 | [diff] [blame] | 349 | env.getBlazeWorkspace().getLastExecutionTimeRange(), |
| 350 | topLevelArtifactContext); |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 351 | buildCompleted = true; |
| 352 | } catch (BuildFailedException | TestExecException e) { |
| 353 | buildCompleted = true; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 354 | throw e; |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 355 | } catch (Error | RuntimeException e) { |
| 356 | catastrophe = e; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 357 | } finally { |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 358 | // These may flush logs, which may help if there is a catastrophic failure. |
schmitt | be241a1 | 2020-01-16 13:30:55 -0800 | [diff] [blame] | 359 | for (ExecutorLifecycleListener executorLifecycleListener : executorLifecycleListeners) { |
| 360 | executorLifecycleListener.executionPhaseEnding(); |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | // Handlers process these events and others (e.g. CommandCompleteEvent), even in the event of |
| 364 | // a catastrophic failure. Posting these is consistent with other behavior. |
janakr | ac58ca8 | 2019-02-14 09:34:20 -0800 | [diff] [blame] | 365 | env.getEventBus().post(skyframeExecutor.createExecutionFinishedEvent()); |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 366 | |
| 367 | env.getEventBus() |
| 368 | .post(new ExecutionPhaseCompleteEvent(timer.stop().elapsed(TimeUnit.MILLISECONDS))); |
| 369 | |
| 370 | if (catastrophe != null) { |
| 371 | Throwables.throwIfUnchecked(catastrophe); |
| 372 | } |
| 373 | // NOTE: No finalization activities below will run in the event of a catastrophic error! |
| 374 | |
Ulf Adams | b514610 | 2015-10-20 08:57:26 +0000 | [diff] [blame] | 375 | env.recordLastExecutionTime(); |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 376 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 377 | if (request.isRunningInEmacs()) { |
Klaus Aehlig | ad87c13 | 2017-08-14 12:20:39 +0200 | [diff] [blame] | 378 | request |
| 379 | .getOutErr() |
brandjon | 79712cb | 2019-12-04 10:01:17 -0800 | [diff] [blame] | 380 | .printErrLn(runtime.getProductName() + ": Leaving directory `" + getExecRoot() + "/'"); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 381 | } |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 382 | if (buildCompleted) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 383 | getReporter().handle(Event.progress("Building complete.")); |
| 384 | } |
| 385 | |
Janak Ramakrishnan | a5d8d09 | 2015-12-08 18:32:47 +0000 | [diff] [blame] | 386 | if (buildCompleted) { |
jmmv | 59787f1 | 2017-08-28 21:41:21 +0200 | [diff] [blame] | 387 | saveActionCache(actionCache); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 388 | } |
| 389 | |
ulfjack | 1fbe72e | 2018-06-14 04:46:27 -0700 | [diff] [blame] | 390 | try (SilentCloseable c = Profiler.instance().profile("Show results")) { |
Ulf Adams | 7a3fe52 | 2015-12-04 10:48:56 +0000 | [diff] [blame] | 391 | buildResult.setSuccessfulTargets( |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 392 | determineSuccessfulTargets(configuredTargets, builtTargets)); |
| 393 | buildResult.setSuccessfulAspects(determineSuccessfulAspects(aspects, builtAspects)); |
gregce | 45ae096 | 2017-07-22 00:11:13 +0200 | [diff] [blame] | 394 | buildResult.setSkippedTargets(analysisResult.getTargetsToSkip()); |
Googler | 3ca7b78 | 2015-10-12 15:44:09 +0000 | [diff] [blame] | 395 | BuildResultPrinter buildResultPrinter = new BuildResultPrinter(env); |
mschaller | 4037908 | 2019-02-01 14:14:47 -0800 | [diff] [blame] | 396 | buildResultPrinter.showBuildResult( |
| 397 | request, |
| 398 | buildResult, |
| 399 | configuredTargets, |
| 400 | analysisResult.getTargetsToSkip(), |
| 401 | analysisResult.getAspects()); |
Nathan Harmata | d480301 | 2015-09-08 20:03:22 +0000 | [diff] [blame] | 402 | } |
Googler | 3ca7b78 | 2015-10-12 15:44:09 +0000 | [diff] [blame] | 403 | |
ulfjack | 1fbe72e | 2018-06-14 04:46:27 -0700 | [diff] [blame] | 404 | try (SilentCloseable c = Profiler.instance().profile("Show artifacts")) { |
Googler | 3ca7b78 | 2015-10-12 15:44:09 +0000 | [diff] [blame] | 405 | if (request.getBuildOptions().showArtifacts) { |
| 406 | BuildResultPrinter buildResultPrinter = new BuildResultPrinter(env); |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 407 | buildResultPrinter.showArtifacts(request, configuredTargets, analysisResult.getAspects()); |
Googler | 3ca7b78 | 2015-10-12 15:44:09 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 411 | if (explanationHandler != null) { |
| 412 | uninstallExplanationHandler(explanationHandler); |
laszlocsomor | 482235b | 2018-11-22 08:15:15 -0800 | [diff] [blame] | 413 | try { |
| 414 | explanationHandler.close(); |
| 415 | } catch (IOException _ignored) { |
| 416 | // Ignored |
| 417 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 418 | } |
| 419 | // Finalize output service last, so that if we do throw an exception, we know all the other |
| 420 | // code has already run. |
Ulf Adams | 706b7f2 | 2015-10-20 09:06:45 +0000 | [diff] [blame] | 421 | if (env.getOutputService() != null) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 422 | boolean isBuildSuccessful = |
| 423 | buildResult.getSuccessfulTargets().size() == configuredTargets.size(); |
Ulf Adams | 706b7f2 | 2015-10-20 09:06:45 +0000 | [diff] [blame] | 424 | env.getOutputService().finalizeBuild(isBuildSuccessful); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 429 | private void prepare( |
| 430 | PackageRoots packageRoots, ImmutableSortedSet<String> nonSymlinkedDirectoriesUnderExecRoot) |
| 431 | throws AbruptExitException, InterruptedException { |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 432 | Optional<ImmutableMap<PackageIdentifier, Root>> packageRootMap = |
janakr | ae32398 | 2017-09-29 21:11:53 +0200 | [diff] [blame] | 433 | packageRoots.getPackageRootsMap(); |
arostovtsev | 20b056a | 2019-08-30 15:00:31 -0700 | [diff] [blame] | 434 | if (packageRootMap.isPresent()) { |
| 435 | // Prepare for build. |
| 436 | Profiler.instance().markPhase(ProfilePhase.PREPARE); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 437 | |
arostovtsev | 20b056a | 2019-08-30 15:00:31 -0700 | [diff] [blame] | 438 | // Plant the symlink forest. |
| 439 | try (SilentCloseable c = Profiler.instance().profile("plantSymlinkForest")) { |
ichern | 121933e | 2020-01-27 02:08:19 -0800 | [diff] [blame] | 440 | SymlinkForest symlinkForest = |
| 441 | new SymlinkForest( |
| 442 | packageRootMap.get(), |
| 443 | getExecRoot(), |
| 444 | runtime.getProductName(), |
| 445 | nonSymlinkedDirectoriesUnderExecRoot); |
| 446 | symlinkForest.plantSymlinkForest(); |
arostovtsev | 20b056a | 2019-08-30 15:00:31 -0700 | [diff] [blame] | 447 | } catch (IOException e) { |
| 448 | throw new ExecutorInitException("Source forest creation failed", e); |
| 449 | } |
Kristina Chodorow | 52bc57c | 2016-06-20 14:27:56 +0000 | [diff] [blame] | 450 | } |
arostovtsev | 20b056a | 2019-08-30 15:00:31 -0700 | [diff] [blame] | 451 | env.getEventBus().post(new ExecRootPreparedEvent(packageRootMap)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Nathan Harmata | ca06fa2 | 2015-07-27 19:54:14 +0000 | [diff] [blame] | 454 | private void createActionLogDirectory() throws ExecutorInitException { |
jmmv | 88e22cd | 2019-09-15 09:59:49 -0700 | [diff] [blame] | 455 | Path directory = env.getActionTempsDirectory(); |
arostovtsev | 702a1c6 | 2020-01-15 11:59:50 -0800 | [diff] [blame] | 456 | if (directory.exists()) { |
| 457 | try { |
jmmv | 5cc1f65 | 2019-03-20 09:34:08 -0700 | [diff] [blame] | 458 | directory.deleteTree(); |
arostovtsev | 702a1c6 | 2020-01-15 11:59:50 -0800 | [diff] [blame] | 459 | } catch (IOException e) { |
| 460 | throw new ExecutorInitException("Couldn't delete action output directory", e); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 461 | } |
arostovtsev | 702a1c6 | 2020-01-15 11:59:50 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | try { |
janakr | 0049e96 | 2017-04-05 21:41:23 +0000 | [diff] [blame] | 465 | FileSystemUtils.createDirectoryAndParents(directory); |
Nathan Harmata | ca06fa2 | 2015-07-27 19:54:14 +0000 | [diff] [blame] | 466 | } catch (IOException e) { |
arostovtsev | 702a1c6 | 2020-01-15 11:59:50 -0800 | [diff] [blame] | 467 | throw new ExecutorInitException("Couldn't create action output directory", e); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 471 | /** |
brandjon | 7b5043f | 2019-11-25 12:30:22 -0800 | [diff] [blame] | 472 | * Obtains the {@link BuildConfiguration} for a given {@link BuildOptions} for the purpose of |
| 473 | * symlink creation. |
| 474 | * |
| 475 | * <p>In the event of a {@link InvalidConfigurationException}, a warning is emitted and null is |
| 476 | * returned. |
| 477 | */ |
| 478 | @Nullable |
| 479 | private static BuildConfiguration getConfiguration( |
| 480 | SkyframeExecutor executor, Reporter reporter, BuildOptions options) { |
| 481 | try { |
| 482 | return executor.getConfiguration(reporter, options, /*keepGoing=*/ false); |
| 483 | } catch (InvalidConfigurationException e) { |
| 484 | reporter.handle( |
| 485 | Event.warn( |
| 486 | "Couldn't get configuration for convenience symlink creation: " + e.getMessage())); |
| 487 | return null; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 492 | * Handles what action to perform on the convenience symlinks. If the the mode is {@link |
| 493 | * ConvenienceSymlinksMode.IGNORE}, then skip any creating or cleaning of convenience symlinks. |
| 494 | * Otherwise, manage the convenience symlinks and then post a {@link |
| 495 | * ConvenienceSymlinksIdentifiedEvent} build event. |
| 496 | */ |
| 497 | private void handleConvenienceSymlinks(AnalysisResult analysisResult) { |
| 498 | ImmutableList<ConvenienceSymlink> convenienceSymlinks = ImmutableList.of(); |
| 499 | if (request.getBuildOptions().experimentalConvenienceSymlinks |
| 500 | != ConvenienceSymlinksMode.IGNORE) { |
| 501 | convenienceSymlinks = createConvenienceSymlinks(request.getBuildOptions(), analysisResult); |
| 502 | } |
| 503 | if (request.getBuildOptions().experimentalConvenienceSymlinksBepEvent) { |
| 504 | env.getEventBus().post(new ConvenienceSymlinksIdentifiedEvent(convenienceSymlinks)); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /** |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 509 | * Creates convenience symlinks based on the target configurations. |
| 510 | * |
| 511 | * <p>Exactly what target configurations we consider depends on the value of {@code |
| 512 | * --use_top_level_targets_for_symlinks}. If this flag is false, we use the top-level target |
| 513 | * configuration as represented by the command line prior to processing any target. If the flag is |
| 514 | * true, we instead use the configurations OF the top-level targets -- meaning that we account for |
| 515 | * the effects of any rule transitions these targets may have. |
| 516 | * |
| 517 | * <p>For each type of convenience symlink, if all the considered configurations agree on what |
| 518 | * path the symlink should point to, it gets created; otherwise, the symlink is not created, and |
| 519 | * in fact gets removed if it was already present from a previous invocation. |
| 520 | */ |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 521 | private ImmutableList<ConvenienceSymlink> createConvenienceSymlinks( |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 522 | BuildRequestOptions buildRequestOptions, AnalysisResult analysisResult) { |
| 523 | SkyframeExecutor executor = env.getSkyframeExecutor(); |
| 524 | Reporter reporter = env.getReporter(); |
| 525 | |
| 526 | // Gather configurations to consider. |
| 527 | Set<BuildConfiguration> targetConfigurations = |
| 528 | buildRequestOptions.useTopLevelTargetsForSymlinks() |
| 529 | ? analysisResult.getTargetsToBuild().stream() |
| 530 | .map(ConfiguredTarget::getConfigurationKey) |
| 531 | .filter(configuration -> configuration != null) |
| 532 | .distinct() |
| 533 | .map((key) -> executor.getConfiguration(reporter, key)) |
| 534 | .collect(toImmutableSet()) |
| 535 | : ImmutableSet.copyOf( |
| 536 | analysisResult.getConfigurationCollection().getTargetConfigurations()); |
| 537 | |
| 538 | String productName = runtime.getProductName(); |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 539 | try (SilentCloseable c = |
| 540 | Profiler.instance().profile("OutputDirectoryLinksUtils.createOutputDirectoryLinks")) { |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 541 | return OutputDirectoryLinksUtils.createOutputDirectoryLinks( |
brandjon | 8a60360 | 2019-12-04 10:40:38 -0800 | [diff] [blame] | 542 | runtime.getRuleClassProvider().getSymlinkDefinitions(), |
brandjon | 282958b | 2019-12-04 08:14:26 -0800 | [diff] [blame] | 543 | buildRequestOptions, |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 544 | env.getWorkspaceName(), |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 545 | env.getWorkspace(), |
Googler | 8763639 | 2019-12-30 12:57:56 -0800 | [diff] [blame] | 546 | env.getDirectories(), |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 547 | getReporter(), |
| 548 | targetConfigurations, |
brandjon | 7b5043f | 2019-11-25 12:30:22 -0800 | [diff] [blame] | 549 | options -> getConfiguration(executor, reporter, options), |
brandjon | 282958b | 2019-12-04 08:14:26 -0800 | [diff] [blame] | 550 | productName); |
brandjon | 07cc56d | 2019-11-25 10:00:12 -0800 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 554 | /** Prepare for a local output build. */ |
kchodorow | 85ae190 | 2017-04-22 15:07:22 -0400 | [diff] [blame] | 555 | private void startLocalOutputBuild() throws ExecutorInitException { |
ulfjack | 1fbe72e | 2018-06-14 04:46:27 -0700 | [diff] [blame] | 556 | try (SilentCloseable c = Profiler.instance().profile("Starting local output build")) { |
kchodorow | 85ae190 | 2017-04-22 15:07:22 -0400 | [diff] [blame] | 557 | Path outputPath = env.getDirectories().getOutputPath(env.getWorkspaceName()); |
Ulf Adams | 94b72db | 2016-03-30 11:58:37 +0000 | [diff] [blame] | 558 | Path localOutputPath = env.getDirectories().getLocalOutputPath(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 559 | |
| 560 | if (outputPath.isSymbolicLink()) { |
Nathan Harmata | ca06fa2 | 2015-07-27 19:54:14 +0000 | [diff] [blame] | 561 | try { |
| 562 | // Remove the existing symlink first. |
| 563 | outputPath.delete(); |
| 564 | if (localOutputPath.exists()) { |
| 565 | // Pre-existing local output directory. Move to outputPath. |
| 566 | localOutputPath.renameTo(outputPath); |
| 567 | } |
| 568 | } catch (IOException e) { |
| 569 | throw new ExecutorInitException("Couldn't handle local output directory symlinks", e); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 570 | } |
| 571 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
| 575 | /** |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 576 | * If a path is supplied, creates and installs an ExplanationHandler. Returns an instance on |
| 577 | * success. Reports an error and returns null otherwise. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 578 | */ |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 579 | private ExplanationHandler installExplanationHandler( |
| 580 | PathFragment explanationPath, String allOptions) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 581 | if (explanationPath == null) { |
| 582 | return null; |
| 583 | } |
| 584 | ExplanationHandler handler; |
| 585 | try { |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 586 | handler = |
| 587 | new ExplanationHandler( |
| 588 | getWorkspace().getRelative(explanationPath).getOutputStream(), allOptions); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 589 | } catch (IOException e) { |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 590 | getReporter() |
| 591 | .handle( |
| 592 | Event.warn( |
| 593 | String.format( |
| 594 | "Cannot write explanation of rebuilds to file '%s': %s", |
| 595 | explanationPath, e.getMessage()))); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 596 | return null; |
| 597 | } |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 598 | getReporter() |
| 599 | .handle(Event.info("Writing explanation of rebuilds to '" + explanationPath + "'")); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 600 | getReporter().addHandler(handler); |
| 601 | return handler; |
| 602 | } |
| 603 | |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 604 | /** Uninstalls the specified ExplanationHandler (if any) and closes the log file. */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 605 | private void uninstallExplanationHandler(ExplanationHandler handler) { |
| 606 | if (handler != null) { |
| 607 | getReporter().removeHandler(handler); |
| 608 | handler.log.close(); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /** |
laszlocsomor | 482235b | 2018-11-22 08:15:15 -0800 | [diff] [blame] | 613 | * An ErrorEventListener implementation that records DEPCHECKER events into a log file, iff the |
| 614 | * --explain flag is specified during a build. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 615 | */ |
laszlocsomor | 482235b | 2018-11-22 08:15:15 -0800 | [diff] [blame] | 616 | private static class ExplanationHandler implements EventHandler, AutoCloseable { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 617 | private final PrintWriter log; |
| 618 | |
| 619 | private ExplanationHandler(OutputStream log, String optionsDescription) { |
lberki | 0d8d4cf | 2017-09-05 16:01:44 +0200 | [diff] [blame] | 620 | this.log = new PrintWriter(new OutputStreamWriter(log, StandardCharsets.UTF_8)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 621 | this.log.println("Build options: " + optionsDescription); |
| 622 | } |
| 623 | |
laszlocsomor | 482235b | 2018-11-22 08:15:15 -0800 | [diff] [blame] | 624 | @Override |
| 625 | public void close() throws IOException { |
| 626 | this.log.close(); |
| 627 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 628 | |
| 629 | @Override |
| 630 | public void handle(Event event) { |
| 631 | if (event.getKind() == EventKind.DEPCHECKER) { |
| 632 | log.println(event.getMessage()); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /** |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 638 | * Computes the result of the build. Sets the list of successful (up-to-date) targets in the |
| 639 | * request object. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 640 | * |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 641 | * @param configuredTargets The configured targets whose artifacts are to be built. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 642 | */ |
Ulf Adams | 7a3fe52 | 2015-12-04 10:48:56 +0000 | [diff] [blame] | 643 | private Collection<ConfiguredTarget> determineSuccessfulTargets( |
cpeyser | 8e9b28f | 2018-06-04 08:05:13 -0700 | [diff] [blame] | 644 | Collection<ConfiguredTarget> configuredTargets, Set<ConfiguredTargetKey> builtTargets) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 645 | // Maintain the ordering by copying builtTargets into a LinkedHashSet in the same iteration |
| 646 | // order as configuredTargets. |
| 647 | Collection<ConfiguredTarget> successfulTargets = new LinkedHashSet<>(); |
| 648 | for (ConfiguredTarget target : configuredTargets) { |
cpeyser | 8e9b28f | 2018-06-04 08:05:13 -0700 | [diff] [blame] | 649 | if (builtTargets.contains(ConfiguredTargetKey.inTargetConfig(target))) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 650 | successfulTargets.add(target); |
| 651 | } |
| 652 | } |
Ulf Adams | 7a3fe52 | 2015-12-04 10:48:56 +0000 | [diff] [blame] | 653 | return successfulTargets; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 654 | } |
| 655 | |
tomlu | 6ed4fd5 | 2018-04-03 10:01:10 -0700 | [diff] [blame] | 656 | private Collection<AspectValue> determineSuccessfulAspects( |
| 657 | Collection<AspectValue> aspects, Set<AspectKey> builtAspects) { |
| 658 | // Maintain the ordering by copying builtTargets into a LinkedHashSet in the same iteration |
| 659 | // order as configuredTargets. |
| 660 | Collection<AspectValue> successfulAspects = new LinkedHashSet<>(); |
| 661 | for (AspectValue aspect : aspects) { |
| 662 | if (builtAspects.contains(aspect.getKey())) { |
| 663 | successfulAspects.add(aspect); |
| 664 | } |
| 665 | } |
| 666 | return successfulAspects; |
| 667 | } |
| 668 | |
ccalvarin | b5fd761 | 2017-12-14 12:21:48 -0800 | [diff] [blame] | 669 | /** Get action cache if present or reload it from the on-disk cache. */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 670 | private ActionCache getActionCache() throws LocalEnvironmentException { |
| 671 | try { |
Ulf Adams | 8061302 | 2015-09-16 09:11:33 +0000 | [diff] [blame] | 672 | return env.getPersistentActionCache(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 673 | } catch (IOException e) { |
| 674 | // TODO(bazel-team): (2010) Ideally we should just remove all cache data and reinitialize |
| 675 | // caches. |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 676 | LoggingUtil.logToRemote( |
| 677 | Level.WARNING, "Failed to initialize action cache: " + e.getMessage(), e); |
Dan Fabulich | 1d35ca0 | 2018-07-05 16:08:06 -0700 | [diff] [blame] | 678 | throw new LocalEnvironmentException( |
| 679 | "couldn't create action cache: " |
| 680 | + e.getMessage() |
| 681 | + ". If error persists, use 'bazel clean'"); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 685 | private Builder createBuilder( |
| 686 | BuildRequest request, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 687 | ActionCache actionCache, |
Eric Fellheimer | f3b43af | 2015-11-13 19:51:20 +0000 | [diff] [blame] | 688 | SkyframeExecutor skyframeExecutor, |
Ulf Adams | 1ac1b99 | 2016-11-02 12:50:26 +0000 | [diff] [blame] | 689 | ModifiedFileSet modifiedOutputFiles) { |
janakr | 6b1b8a9 | 2017-11-10 23:20:22 +0100 | [diff] [blame] | 690 | BuildRequestOptions options = request.getBuildOptions(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 691 | |
jmmv | 88e22cd | 2019-09-15 09:59:49 -0700 | [diff] [blame] | 692 | Path actionOutputRoot = env.getActionTempsDirectory(); |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 693 | Predicate<Action> executionFilter = |
| 694 | CheckUpToDateFilter.fromOptions(request.getOptions(ExecutionOptions.class)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 695 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 696 | skyframeExecutor.setActionOutputRoot(actionOutputRoot); |
Ulf Adams | 3d67e00 | 2016-03-29 16:23:01 +0000 | [diff] [blame] | 697 | ArtifactFactory artifactFactory = env.getSkyframeBuildView().getArtifactFactory(); |
Googler | 2f11192 | 2017-02-28 20:58:45 +0000 | [diff] [blame] | 698 | return new SkyframeBuilder( |
| 699 | skyframeExecutor, |
ulfjack | 985a34ad | 2019-08-09 01:51:15 -0700 | [diff] [blame] | 700 | env.getLocalResourceManager(), |
Googler | 2f11192 | 2017-02-28 20:58:45 +0000 | [diff] [blame] | 701 | new ActionCacheChecker( |
| 702 | actionCache, |
| 703 | artifactFactory, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 704 | skyframeExecutor.getActionKeyContext(), |
Googler | 2f11192 | 2017-02-28 20:58:45 +0000 | [diff] [blame] | 705 | executionFilter, |
| 706 | ActionCacheChecker.CacheConfig.builder() |
| 707 | .setEnabled(options.useActionCache) |
| 708 | .setVerboseExplanations(options.verboseExplanations) |
| 709 | .build()), |
felly | c5c078c | 2019-07-31 12:05:24 -0700 | [diff] [blame] | 710 | env.getTopDownActionCache(), |
Nathan Harmata | 6010883 | 2016-03-25 08:02:42 +0000 | [diff] [blame] | 711 | request.getPackageCacheOptions().checkOutputFiles |
Googler | 2f11192 | 2017-02-28 20:58:45 +0000 | [diff] [blame] | 712 | ? modifiedOutputFiles |
| 713 | : ModifiedFileSet.NOTHING_MODIFIED, |
schmitt | e643340 | 2020-01-07 12:57:46 -0800 | [diff] [blame] | 714 | env.getFileCache(), |
tomlu | 2661be8 | 2018-08-30 08:30:01 -0700 | [diff] [blame] | 715 | prefetcher); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 716 | } |
| 717 | |
steinman | 13a628a | 2019-01-09 08:39:32 -0800 | [diff] [blame] | 718 | @VisibleForTesting |
ulfjack | 985a34ad | 2019-08-09 01:51:15 -0700 | [diff] [blame] | 719 | public static void configureResourceManager(ResourceManager resourceMgr, BuildRequest request) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 720 | ExecutionOptions options = request.getOptions(ExecutionOptions.class); |
Mark Schaller | dffb6ee | 2015-02-25 20:01:01 +0000 | [diff] [blame] | 721 | ResourceSet resources; |
steinman | 3501b21 | 2019-03-25 12:36:43 -0700 | [diff] [blame] | 722 | if (options.availableResources != null && !options.removeLocalResources) { |
steinman | 13a628a | 2019-01-09 08:39:32 -0800 | [diff] [blame] | 723 | logger.warning( |
| 724 | "--local_resources will be deprecated. Please use --local_ram_resources " |
| 725 | + "and/or --local_cpu_resources."); |
Mark Schaller | dffb6ee | 2015-02-25 20:01:01 +0000 | [diff] [blame] | 726 | resources = options.availableResources; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 727 | resourceMgr.setRamUtilizationPercentage(100); |
steinman | 13a628a | 2019-01-09 08:39:32 -0800 | [diff] [blame] | 728 | } else if (options.ramUtilizationPercentage != 0) { |
| 729 | logger.warning( |
| 730 | "--ram_utilization_factor will soon be deprecated. Please use " |
| 731 | + "--local_ram_resources=HOST_RAM*<float>, where <float> is the percentage of " |
| 732 | + "available RAM you want to devote to Bazel."); |
| 733 | resources = |
| 734 | ResourceSet.createWithRamCpu( |
| 735 | LocalHostCapacity.getLocalHostCapacity().getMemoryMb(), options.localCpuResources); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 736 | resourceMgr.setRamUtilizationPercentage(options.ramUtilizationPercentage); |
steinman | 13a628a | 2019-01-09 08:39:32 -0800 | [diff] [blame] | 737 | } else { |
| 738 | resources = |
| 739 | ResourceSet.createWithRamCpu(options.localRamResources, options.localCpuResources); |
| 740 | resourceMgr.setRamUtilizationPercentage(100); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 741 | } |
Josh Pieper | 7f3bddd | 2018-05-04 00:39:37 -0700 | [diff] [blame] | 742 | resourceMgr.setUseLocalMemoryEstimate(options.localMemoryEstimate); |
Mark Schaller | dffb6ee | 2015-02-25 20:01:01 +0000 | [diff] [blame] | 743 | |
buchgr | 7b51552 | 2019-03-29 04:42:17 -0700 | [diff] [blame] | 744 | resourceMgr.setAvailableResources( |
| 745 | ResourceSet.create( |
| 746 | resources.getMemoryMb(), |
| 747 | resources.getCpuUsage(), |
| 748 | request.getExecutionOptions().usingLocalTestJobs() |
| 749 | ? request.getExecutionOptions().localTestJobs |
| 750 | : Integer.MAX_VALUE)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /** |
jmmv | 59787f1 | 2017-08-28 21:41:21 +0200 | [diff] [blame] | 754 | * Writes the action cache files to disk, reporting any errors that occurred during writing and |
| 755 | * capturing statistics. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 756 | */ |
jmmv | 59787f1 | 2017-08-28 21:41:21 +0200 | [diff] [blame] | 757 | private void saveActionCache(ActionCache actionCache) { |
jmmv | ccb43ee | 2017-08-30 22:07:10 +0200 | [diff] [blame] | 758 | ActionCacheStatistics.Builder builder = ActionCacheStatistics.newBuilder(); |
jmmv | 9573a0d | 2017-09-26 11:59:22 -0400 | [diff] [blame] | 759 | actionCache.mergeIntoActionCacheStatistics(builder); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 760 | |
lberki | 97abb52 | 2017-09-04 18:51:57 +0200 | [diff] [blame] | 761 | AutoProfiler p = |
| 762 | AutoProfiler.profiledAndLogged("Saving action cache", ProfilerTask.INFO, logger); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 763 | try { |
jmmv | 59787f1 | 2017-08-28 21:41:21 +0200 | [diff] [blame] | 764 | builder.setSizeInBytes(actionCache.save()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 765 | } catch (IOException e) { |
jmmv | 59787f1 | 2017-08-28 21:41:21 +0200 | [diff] [blame] | 766 | builder.setSizeInBytes(0); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 767 | getReporter().handle(Event.error("I/O error while writing action log: " + e.getMessage())); |
| 768 | } finally { |
jmmv | ccb43ee | 2017-08-30 22:07:10 +0200 | [diff] [blame] | 769 | builder.setSaveTimeInMs( |
| 770 | TimeUnit.MILLISECONDS.convert(p.completeAndGetElapsedTimeNanos(), TimeUnit.NANOSECONDS)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 771 | } |
jmmv | 59787f1 | 2017-08-28 21:41:21 +0200 | [diff] [blame] | 772 | |
| 773 | env.getEventBus().post(builder.build()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 774 | } |
| 775 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 776 | private Reporter getReporter() { |
Ulf Adams | 633f539 | 2015-09-15 11:13:08 +0000 | [diff] [blame] | 777 | return env.getReporter(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 780 | private Path getWorkspace() { |
Ulf Adams | 94b72db | 2016-03-30 11:58:37 +0000 | [diff] [blame] | 781 | return env.getWorkspace(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | private Path getExecRoot() { |
Ulf Adams | 94b72db | 2016-03-30 11:58:37 +0000 | [diff] [blame] | 785 | return env.getExecRoot(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 786 | } |
| 787 | } |