Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1 | // Copyright 2015 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; |
Janak Ramakrishnan | a5578af | 2017-03-21 17:28:39 +0000 | [diff] [blame] | 15 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 16 | import static com.google.common.truth.Truth.assertThat; |
lberki | 812e6fe | 2019-07-25 07:50:55 -0700 | [diff] [blame] | 17 | import static com.google.devtools.build.lib.actions.FileArtifactValue.createForTesting; |
michajlo | 660d17f | 2020-03-27 09:01:57 -0700 | [diff] [blame] | 18 | import static org.junit.Assert.assertThrows; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 19 | |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 20 | import com.google.common.base.Preconditions; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableList; |
| 22 | import com.google.common.collect.ImmutableMap; |
| 23 | import com.google.common.collect.ImmutableSet; |
| 24 | import com.google.common.collect.Iterables; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 25 | import com.google.devtools.build.lib.actions.Action; |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 26 | import com.google.devtools.build.lib.actions.ActionAnalysisMetadata.MiddlemanType; |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 27 | import com.google.devtools.build.lib.actions.ActionLookupData; |
| 28 | import com.google.devtools.build.lib.actions.ActionLookupValue; |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 29 | import com.google.devtools.build.lib.actions.ActionTemplate; |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 30 | import com.google.devtools.build.lib.actions.Actions; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 31 | import com.google.devtools.build.lib.actions.Artifact; |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.actions.Artifact.DerivedArtifact; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 33 | import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; |
| 34 | import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType; |
| 35 | import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 36 | import com.google.devtools.build.lib.actions.ArtifactRoot; |
cparsons | e2d200f | 2018-03-06 16:15:11 -0800 | [diff] [blame] | 37 | import com.google.devtools.build.lib.actions.BasicActionLookupValue; |
shahan | 602cc85 | 2018-06-06 20:09:57 -0700 | [diff] [blame] | 38 | import com.google.devtools.build.lib.actions.FileArtifactValue; |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 39 | import com.google.devtools.build.lib.actions.FilesetOutputSymlink; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 40 | import com.google.devtools.build.lib.actions.MissingInputFileException; |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 41 | import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 42 | import com.google.devtools.build.lib.actions.util.ActionsTestUtil; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 43 | import com.google.devtools.build.lib.actions.util.TestAction.DummyAction; |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 44 | import com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate; |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 45 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 46 | import com.google.devtools.build.lib.collect.nestedset.Order; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 47 | import com.google.devtools.build.lib.events.NullEventHandler; |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 48 | import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 49 | import com.google.devtools.build.lib.util.Pair; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 50 | import com.google.devtools.build.lib.vfs.FileStatus; |
lberki | f225af1 | 2019-08-01 04:21:58 -0700 | [diff] [blame] | 51 | import com.google.devtools.build.lib.vfs.FileStatusWithDigestAdapter; |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 52 | import com.google.devtools.build.lib.vfs.FileSystem; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 53 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
| 54 | import com.google.devtools.build.lib.vfs.Path; |
| 55 | import com.google.devtools.build.lib.vfs.PathFragment; |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 56 | import com.google.devtools.build.lib.vfs.Root; |
lberki | f225af1 | 2019-08-01 04:21:58 -0700 | [diff] [blame] | 57 | import com.google.devtools.build.lib.vfs.Symlinks; |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 58 | import com.google.devtools.build.skyframe.EvaluationContext; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 59 | import com.google.devtools.build.skyframe.EvaluationResult; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 60 | import com.google.devtools.build.skyframe.SkyFunction; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 61 | import com.google.devtools.build.skyframe.SkyKey; |
| 62 | import com.google.devtools.build.skyframe.SkyValue; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 63 | import java.io.IOException; |
buchgr | d4d3d50 | 2018-08-02 06:47:19 -0700 | [diff] [blame] | 64 | import java.util.ArrayList; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 65 | import java.util.Arrays; |
| 66 | import java.util.HashMap; |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 67 | import java.util.HashSet; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 68 | import java.util.Map; |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 69 | import java.util.Set; |
Janak Ramakrishnan | ad77f97 | 2016-07-29 20:58:42 +0000 | [diff] [blame] | 70 | import org.junit.Before; |
| 71 | import org.junit.Test; |
| 72 | import org.junit.runner.RunWith; |
| 73 | import org.junit.runners.JUnit4; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Tests for {@link ArtifactFunction}. |
| 77 | */ |
| 78 | // Doesn't actually need any particular Skyframe, but is only relevant to Skyframe full mode. |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 79 | @RunWith(JUnit4.class) |
Michael Thvedt | 8d5a7bb | 2016-02-09 03:06:34 +0000 | [diff] [blame] | 80 | public class ArtifactFunctionTest extends ArtifactFunctionTestCase { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 81 | |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 82 | private final Set<Artifact> omittedOutputs = new HashSet<>(); |
| 83 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 84 | @Before |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 85 | public final void setUp() { |
| 86 | delegateActionExecutionFunction = new SimpleActionExecutionFunction(omittedOutputs); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | private void assertFileArtifactValueMatches(boolean expectDigest) throws Throwable { |
| 90 | Artifact output = createDerivedArtifact("output"); |
| 91 | Path path = output.getPath(); |
| 92 | file(path, "contents"); |
olaola | bfd1d33 | 2017-06-19 16:55:24 -0400 | [diff] [blame] | 93 | assertValueMatches(path.stat(), expectDigest ? path.getDigest() : null, evaluateFAN(output)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 96 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 97 | public void testBasicArtifact() throws Throwable { |
| 98 | fastDigest = false; |
| 99 | assertFileArtifactValueMatches(/*expectDigest=*/ true); |
| 100 | } |
| 101 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 102 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 103 | public void testBasicArtifactWithXattr() throws Throwable { |
| 104 | fastDigest = true; |
| 105 | assertFileArtifactValueMatches(/*expectDigest=*/ true); |
| 106 | } |
| 107 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 108 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 109 | public void testMissingNonMandatoryArtifact() throws Throwable { |
| 110 | Artifact input = createSourceArtifact("input1"); |
lberki | 36df7ed | 2019-06-27 06:32:03 -0700 | [diff] [blame] | 111 | assertThat(evaluateArtifactValue(input)).isNotNull(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 114 | @Test |
Michajlo Matijkiw | 528957e | 2016-01-19 21:17:45 +0000 | [diff] [blame] | 115 | public void testUnreadableInputWithFsWithAvailableDigest() throws Throwable { |
Googler | e764d56 | 2019-10-16 10:56:33 -0700 | [diff] [blame] | 116 | final byte[] expectedDigest = {1, 2, 3, 4}; |
Michajlo Matijkiw | 528957e | 2016-01-19 21:17:45 +0000 | [diff] [blame] | 117 | setupRoot( |
| 118 | new CustomInMemoryFs() { |
| 119 | @Override |
ccalvarin | dd9f60e | 2018-07-23 18:16:18 -0700 | [diff] [blame] | 120 | public byte[] getDigest(Path path) throws IOException { |
| 121 | return path.getBaseName().equals("unreadable") ? expectedDigest : super.getDigest(path); |
Michajlo Matijkiw | 528957e | 2016-01-19 21:17:45 +0000 | [diff] [blame] | 122 | } |
| 123 | }); |
| 124 | |
| 125 | Artifact input = createSourceArtifact("unreadable"); |
| 126 | Path inputPath = input.getPath(); |
| 127 | file(inputPath, "dummynotused"); |
| 128 | inputPath.chmod(0); |
| 129 | |
lberki | 36df7ed | 2019-06-27 06:32:03 -0700 | [diff] [blame] | 130 | FileArtifactValue value = (FileArtifactValue) evaluateArtifactValue(input); |
Michajlo Matijkiw | 528957e | 2016-01-19 21:17:45 +0000 | [diff] [blame] | 131 | |
| 132 | FileStatus stat = inputPath.stat(); |
| 133 | assertThat(value.getSize()).isEqualTo(stat.getSize()); |
| 134 | assertThat(value.getDigest()).isEqualTo(expectedDigest); |
| 135 | } |
| 136 | |
| 137 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 138 | public void testMiddlemanArtifact() throws Throwable { |
Janak Ramakrishnan | a5578af | 2017-03-21 17:28:39 +0000 | [diff] [blame] | 139 | Artifact output = createMiddlemanArtifact("output"); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 140 | Artifact input1 = createSourceArtifact("input1"); |
| 141 | Artifact input2 = createDerivedArtifact("input2"); |
Benjamin Peterson | 63748e4 | 2018-06-03 22:11:16 -0700 | [diff] [blame] | 142 | SpecialArtifact tree = createDerivedTreeArtifactWithAction("treeArtifact"); |
buchgr | d4d3d50 | 2018-08-02 06:47:19 -0700 | [diff] [blame] | 143 | TreeFileArtifact treeFile1 = createFakeTreeFileArtifact(tree, "child1", "hello1"); |
| 144 | TreeFileArtifact treeFile2 = createFakeTreeFileArtifact(tree, "child2", "hello2"); |
| 145 | file(treeFile1.getPath(), "src1"); |
| 146 | file(treeFile2.getPath(), "src2"); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 147 | Action action = |
| 148 | new DummyAction( |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 149 | NestedSetBuilder.create(Order.STABLE_ORDER, input1, input2, tree), |
| 150 | output, |
| 151 | MiddlemanType.AGGREGATING_MIDDLEMAN); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 152 | actions.add(action); |
| 153 | file(input2.getPath(), "contents"); |
| 154 | file(input1.getPath(), "source contents"); |
janakr | 8541f6d | 2019-06-11 14:40:21 -0700 | [diff] [blame] | 155 | evaluate( |
| 156 | Iterables.toArray( |
lberki | 36df7ed | 2019-06-27 06:32:03 -0700 | [diff] [blame] | 157 | Artifact.keys(ImmutableSet.of(input2, input1, input2, tree)), SkyKey.class)); |
Janak Ramakrishnan | ad77f97 | 2016-07-29 20:58:42 +0000 | [diff] [blame] | 158 | SkyValue value = evaluateArtifactValue(output); |
buchgr | d4d3d50 | 2018-08-02 06:47:19 -0700 | [diff] [blame] | 159 | ArrayList<Pair<Artifact, ?>> inputs = new ArrayList<>(); |
| 160 | inputs.addAll(((AggregatingArtifactValue) value).getFileArtifacts()); |
| 161 | inputs.addAll(((AggregatingArtifactValue) value).getTreeArtifacts()); |
| 162 | assertThat(inputs) |
Benjamin Peterson | 63748e4 | 2018-06-03 22:11:16 -0700 | [diff] [blame] | 163 | .containsExactly( |
lberki | 812e6fe | 2019-07-25 07:50:55 -0700 | [diff] [blame] | 164 | Pair.of(input1, createForTesting(input1)), |
| 165 | Pair.of(input2, createForTesting(input2)), |
buchgr | d4d3d50 | 2018-08-02 06:47:19 -0700 | [diff] [blame] | 166 | Pair.of(tree, ((TreeArtifactValue) evaluateArtifactValue(tree)))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 169 | /** |
| 170 | * Tests that ArtifactFunction rethrows transitive {@link IOException}s as |
| 171 | * {@link MissingInputFileException}s. |
| 172 | */ |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 173 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 174 | public void testIOException_EndToEnd() throws Throwable { |
| 175 | final IOException exception = new IOException("beep"); |
| 176 | setupRoot( |
| 177 | new CustomInMemoryFs() { |
| 178 | @Override |
felly | a205ed8 | 2018-09-10 11:52:34 -0700 | [diff] [blame] | 179 | public FileStatus statIfFound(Path path, boolean followSymlinks) throws IOException { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 180 | if (path.getBaseName().equals("bad")) { |
| 181 | throw exception; |
| 182 | } |
felly | a205ed8 | 2018-09-10 11:52:34 -0700 | [diff] [blame] | 183 | return super.statIfFound(path, followSymlinks); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 184 | } |
| 185 | }); |
lberki | 36df7ed | 2019-06-27 06:32:03 -0700 | [diff] [blame] | 186 | IOException e = |
| 187 | assertThrows(IOException.class, () -> evaluateArtifactValue(createSourceArtifact("bad"))); |
jcater | 83130f4 | 2019-04-30 14:29:28 -0700 | [diff] [blame] | 188 | assertThat(e).hasMessageThat().contains(exception.getMessage()); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 191 | @Test |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 192 | public void testActionTreeArtifactOutput() throws Throwable { |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 193 | SpecialArtifact artifact = createDerivedTreeArtifactWithAction("treeArtifact"); |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 194 | TreeFileArtifact treeFileArtifact1 = createFakeTreeFileArtifact(artifact, "child1", "hello1"); |
| 195 | TreeFileArtifact treeFileArtifact2 = createFakeTreeFileArtifact(artifact, "child2", "hello2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 196 | |
| 197 | TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 198 | assertThat(value.getChildValues()).containsKey(treeFileArtifact1); |
| 199 | assertThat(value.getChildValues()).containsKey(treeFileArtifact2); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 200 | assertThat(value.getChildValues().get(treeFileArtifact1).getDigest()).isNotNull(); |
| 201 | assertThat(value.getChildValues().get(treeFileArtifact2).getDigest()).isNotNull(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Test |
| 205 | public void testSpawnActionTemplate() throws Throwable { |
| 206 | // artifact1 is a tree artifact generated by normal action. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 207 | SpecialArtifact artifact1 = createDerivedTreeArtifactWithAction("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 208 | createFakeTreeFileArtifact(artifact1, "child1", "hello1"); |
| 209 | createFakeTreeFileArtifact(artifact1, "child2", "hello2"); |
| 210 | |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 211 | // artifact2 is a tree artifact generated by action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 212 | SpecialArtifact artifact2 = createDerivedTreeArtifactOnly("treeArtifact2"); |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 213 | SpawnActionTemplate actionTemplate = |
| 214 | ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2); |
| 215 | actions.add(actionTemplate); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 216 | TreeFileArtifact treeFileArtifact1 = |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 217 | createFakeExpansionTreeFileArtifact(actionTemplate, "child1", "hello1"); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 218 | TreeFileArtifact treeFileArtifact2 = |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 219 | createFakeExpansionTreeFileArtifact(actionTemplate, "child2", "hello2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 220 | |
| 221 | TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact2); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 222 | assertThat(value.getChildValues()).containsKey(treeFileArtifact1); |
| 223 | assertThat(value.getChildValues()).containsKey(treeFileArtifact2); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 224 | assertThat(value.getChildValues().get(treeFileArtifact1).getDigest()).isNotNull(); |
| 225 | assertThat(value.getChildValues().get(treeFileArtifact2).getDigest()).isNotNull(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Test |
| 229 | public void testConsecutiveSpawnActionTemplates() throws Throwable { |
| 230 | // artifact1 is a tree artifact generated by normal action. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 231 | SpecialArtifact artifact1 = createDerivedTreeArtifactWithAction("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 232 | createFakeTreeFileArtifact(artifact1, "child1", "hello1"); |
| 233 | createFakeTreeFileArtifact(artifact1, "child2", "hello2"); |
| 234 | |
| 235 | // artifact2 is a tree artifact generated by action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 236 | SpecialArtifact artifact2 = createDerivedTreeArtifactOnly("treeArtifact2"); |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 237 | SpawnActionTemplate template2 = |
| 238 | ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2); |
| 239 | actions.add(template2); |
| 240 | createFakeExpansionTreeFileArtifact(template2, "child1", "hello1"); |
| 241 | createFakeExpansionTreeFileArtifact(template2, "child2", "hello2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 242 | |
| 243 | // artifact3 is a tree artifact generated by action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 244 | SpecialArtifact artifact3 = createDerivedTreeArtifactOnly("treeArtifact3"); |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 245 | SpawnActionTemplate template3 = |
| 246 | ActionsTestUtil.createDummySpawnActionTemplate(artifact2, artifact3); |
| 247 | actions.add(template3); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 248 | TreeFileArtifact treeFileArtifact1 = |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 249 | createFakeExpansionTreeFileArtifact(template3, "child1", "hello1"); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 250 | TreeFileArtifact treeFileArtifact2 = |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 251 | createFakeExpansionTreeFileArtifact(template3, "child2", "hello2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 252 | |
| 253 | TreeArtifactValue value = (TreeArtifactValue) evaluateArtifactValue(artifact3); |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 254 | assertThat(value.getChildValues()).containsKey(treeFileArtifact1); |
| 255 | assertThat(value.getChildValues()).containsKey(treeFileArtifact2); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 256 | assertThat(value.getChildValues().get(treeFileArtifact1).getDigest()).isNotNull(); |
| 257 | assertThat(value.getChildValues().get(treeFileArtifact2).getDigest()).isNotNull(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 258 | } |
| 259 | |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 260 | @Test |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 261 | public void actionTemplateExpansionOutputsOmitted() throws Throwable { |
| 262 | // artifact1 is a tree artifact generated by normal action. |
| 263 | SpecialArtifact artifact1 = createDerivedTreeArtifactWithAction("treeArtifact1"); |
| 264 | createFakeTreeFileArtifact(artifact1, "child1", "hello1"); |
| 265 | createFakeTreeFileArtifact(artifact1, "child2", "hello2"); |
| 266 | |
| 267 | // artifact2 is a tree artifact generated by action template. |
| 268 | SpecialArtifact artifact2 = createDerivedTreeArtifactOnly("treeArtifact2"); |
| 269 | SpawnActionTemplate actionTemplate = |
| 270 | ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2); |
| 271 | actions.add(actionTemplate); |
| 272 | TreeFileArtifact treeFileArtifact1 = |
| 273 | createFakeExpansionTreeFileArtifact(actionTemplate, "child1", "hello1"); |
| 274 | TreeFileArtifact treeFileArtifact2 = |
| 275 | createFakeExpansionTreeFileArtifact(actionTemplate, "child2", "hello2"); |
| 276 | |
| 277 | omittedOutputs.add(treeFileArtifact1); |
| 278 | omittedOutputs.add(treeFileArtifact2); |
| 279 | |
| 280 | SkyValue value = evaluateArtifactValue(artifact2); |
Googler | a98fc73 | 2020-05-25 12:18:56 -0700 | [diff] [blame] | 281 | assertThat(value).isEqualTo(TreeArtifactValue.OMITTED_TREE_MARKER); |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Test |
| 285 | public void cannotOmitSomeButNotAllActionTemplateExpansionOutputs() throws Throwable { |
| 286 | // artifact1 is a tree artifact generated by normal action. |
| 287 | SpecialArtifact artifact1 = createDerivedTreeArtifactWithAction("treeArtifact1"); |
| 288 | createFakeTreeFileArtifact(artifact1, "child1", "hello1"); |
| 289 | createFakeTreeFileArtifact(artifact1, "child2", "hello2"); |
| 290 | |
| 291 | // artifact2 is a tree artifact generated by action template. |
| 292 | SpecialArtifact artifact2 = createDerivedTreeArtifactOnly("treeArtifact2"); |
| 293 | SpawnActionTemplate actionTemplate = |
| 294 | ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2); |
| 295 | actions.add(actionTemplate); |
| 296 | TreeFileArtifact treeFileArtifact1 = |
| 297 | createFakeExpansionTreeFileArtifact(actionTemplate, "child1", "hello1"); |
| 298 | TreeFileArtifact treeFileArtifact2 = |
| 299 | createFakeExpansionTreeFileArtifact(actionTemplate, "child2", "hello2"); |
| 300 | |
| 301 | omittedOutputs.add(treeFileArtifact1); |
| 302 | |
| 303 | Exception e = assertThrows(RuntimeException.class, () -> evaluateArtifactValue(artifact2)); |
| 304 | assertThat(e).hasCauseThat().isInstanceOf(IllegalStateException.class); |
| 305 | assertThat(e) |
| 306 | .hasCauseThat() |
| 307 | .hasMessageThat() |
| 308 | .matches( |
| 309 | "Action template expansion has some but not all outputs omitted, present outputs: .*" |
| 310 | + treeFileArtifact2.getParentRelativePath() |
| 311 | + ".*"); |
| 312 | } |
| 313 | |
| 314 | @Test |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 315 | public void actionExecutionValueSerialization() throws Exception { |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 316 | ActionLookupData dummyData = ActionLookupData.create(ALL_OWNER, 0); |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 317 | DerivedArtifact artifact1 = createDerivedArtifact("one"); |
lberki | f7eee1e | 2019-07-31 05:49:10 -0700 | [diff] [blame] | 318 | FileArtifactValue metadata1 = |
| 319 | ActionMetadataHandler.fileArtifactValueFromArtifact(artifact1, null, null); |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 320 | SpecialArtifact treeArtifact = createDerivedTreeArtifactOnly("tree"); |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 321 | treeArtifact.setGeneratingActionKey(dummyData); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 322 | TreeFileArtifact treeFileArtifact = TreeFileArtifact.createTreeOutput(treeArtifact, "subpath"); |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 323 | Path path = treeFileArtifact.getPath(); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 324 | path.getParentDirectory().createDirectoryAndParents(); |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 325 | writeFile(path, "contents"); |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 326 | TreeArtifactValue treeArtifactValue = |
| 327 | TreeArtifactValue.create( |
lberki | 812e6fe | 2019-07-25 07:50:55 -0700 | [diff] [blame] | 328 | ImmutableMap.of( |
| 329 | treeFileArtifact, FileArtifactValue.createForTesting(treeFileArtifact))); |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 330 | DerivedArtifact artifact3 = createDerivedArtifact("three"); |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 331 | FilesetOutputSymlink filesetOutputSymlink = |
| 332 | FilesetOutputSymlink.createForTesting( |
| 333 | PathFragment.EMPTY_FRAGMENT, PathFragment.EMPTY_FRAGMENT, PathFragment.EMPTY_FRAGMENT); |
| 334 | ActionExecutionValue actionExecutionValue = |
| 335 | ActionExecutionValue.create( |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 336 | ImmutableMap.of(artifact1, metadata1, artifact3, FileArtifactValue.DEFAULT_MIDDLEMAN), |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 337 | ImmutableMap.of(treeArtifact, treeArtifactValue), |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 338 | ImmutableList.of(filesetOutputSymlink), |
| 339 | null, |
| 340 | true); |
Googler | ce6ad29 | 2019-12-20 10:29:21 -0800 | [diff] [blame] | 341 | new SerializationTester(actionExecutionValue) |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 342 | .addDependency(FileSystem.class, root.getFileSystem()) |
nharmata | f93c72c | 2020-03-13 14:22:10 -0700 | [diff] [blame] | 343 | .addDependency( |
| 344 | Root.RootCodecDependencies.class, |
| 345 | new Root.RootCodecDependencies(Root.absoluteRoot(root.getFileSystem()))) |
janakr | e82933c | 2019-01-02 14:41:50 -0800 | [diff] [blame] | 346 | .runTests(); |
| 347 | } |
| 348 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 349 | private static void file(Path path, String contents) throws Exception { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 350 | FileSystemUtils.createDirectoryAndParents(path.getParentDirectory()); |
| 351 | writeFile(path, contents); |
| 352 | } |
| 353 | |
| 354 | private Artifact createSourceArtifact(String path) { |
janakr | aea0560 | 2019-05-22 15:41:29 -0700 | [diff] [blame] | 355 | return ActionsTestUtil.createArtifactWithExecPath( |
| 356 | ArtifactRoot.asSourceRoot(Root.fromPath(root)), PathFragment.create(path)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 359 | private DerivedArtifact createDerivedArtifact(String path) { |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 360 | PathFragment execPath = PathFragment.create("out").getRelative(path); |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 361 | DerivedArtifact output = |
| 362 | new DerivedArtifact(ArtifactRoot.asDerivedRoot(root, "out"), execPath, ALL_OWNER); |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 363 | actions.add(new DummyAction(NestedSetBuilder.emptySet(Order.STABLE_ORDER), output)); |
janakr | 8541f6d | 2019-06-11 14:40:21 -0700 | [diff] [blame] | 364 | output.setGeneratingActionKey(ActionLookupData.create(ALL_OWNER, actions.size() - 1)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 365 | return output; |
| 366 | } |
| 367 | |
Janak Ramakrishnan | a5578af | 2017-03-21 17:28:39 +0000 | [diff] [blame] | 368 | private Artifact createMiddlemanArtifact(String path) { |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 369 | ArtifactRoot middlemanRoot = |
| 370 | ArtifactRoot.middlemanRoot(middlemanPath, middlemanPath.getRelative("out")); |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 371 | return new DerivedArtifact( |
janakr | 3290e22 | 2019-05-29 16:34:22 -0700 | [diff] [blame] | 372 | middlemanRoot, middlemanRoot.getExecPath().getRelative(path), ALL_OWNER); |
Janak Ramakrishnan | a5578af | 2017-03-21 17:28:39 +0000 | [diff] [blame] | 373 | } |
| 374 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 375 | private SpecialArtifact createDerivedTreeArtifactWithAction(String path) { |
| 376 | SpecialArtifact treeArtifact = createDerivedTreeArtifactOnly(path); |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 377 | actions.add(new DummyAction(NestedSetBuilder.emptySet(Order.STABLE_ORDER), treeArtifact)); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 378 | treeArtifact.setGeneratingActionKey(ActionLookupData.create(ALL_OWNER, actions.size() - 1)); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 379 | return treeArtifact; |
| 380 | } |
| 381 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 382 | private SpecialArtifact createDerivedTreeArtifactOnly(String path) { |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 383 | PathFragment execPath = PathFragment.create("out").getRelative(path); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 384 | return new SpecialArtifact( |
janakr | 448f1cf | 2020-03-30 09:12:44 -0700 | [diff] [blame] | 385 | ArtifactRoot.asDerivedRoot(root, "out"), execPath, ALL_OWNER, SpecialArtifactType.TREE); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 386 | } |
| 387 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 388 | private static TreeFileArtifact createFakeTreeFileArtifact( |
| 389 | SpecialArtifact treeArtifact, String parentRelativePath, String content) throws Exception { |
janakr | 45b308a | 2018-06-08 12:51:58 -0700 | [diff] [blame] | 390 | TreeFileArtifact treeFileArtifact = |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 391 | TreeFileArtifact.createTreeOutput(treeArtifact, parentRelativePath); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 392 | Path path = treeFileArtifact.getPath(); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 393 | path.getParentDirectory().createDirectoryAndParents(); |
| 394 | writeFile(path, content); |
| 395 | return treeFileArtifact; |
| 396 | } |
| 397 | |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 398 | private TreeFileArtifact createFakeExpansionTreeFileArtifact( |
| 399 | ActionTemplate<?> actionTemplate, String parentRelativePath, String content) |
| 400 | throws Exception { |
| 401 | int actionIndex = Iterables.indexOf(actions, actionTemplate::equals); |
| 402 | Preconditions.checkState(actionIndex >= 0, "%s not registered", actionTemplate); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 403 | TreeFileArtifact treeFileArtifact = |
| 404 | TreeFileArtifact.createTemplateExpansionOutput( |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 405 | actionTemplate.getOutputTreeArtifact(), |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 406 | parentRelativePath, |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 407 | ActionTemplateExpansionValue.key(ALL_OWNER, actionIndex)); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 408 | Path path = treeFileArtifact.getPath(); |
| 409 | path.getParentDirectory().createDirectoryAndParents(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 410 | writeFile(path, content); |
| 411 | return treeFileArtifact; |
| 412 | } |
| 413 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 414 | private static void assertValueMatches(FileStatus file, byte[] digest, FileArtifactValue value) |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 415 | throws IOException { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 416 | assertThat(value.getSize()).isEqualTo(file.getSize()); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 417 | if (digest == null) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 418 | assertThat(value.getDigest()).isNull(); |
| 419 | assertThat(value.getModifiedTime()).isEqualTo(file.getLastModifiedTime()); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 420 | } else { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 421 | assertThat(value.getDigest()).isEqualTo(digest); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | private FileArtifactValue evaluateFAN(Artifact artifact) throws Throwable { |
| 426 | return ((FileArtifactValue) evaluateArtifactValue(artifact)); |
| 427 | } |
| 428 | |
Janak Ramakrishnan | ad77f97 | 2016-07-29 20:58:42 +0000 | [diff] [blame] | 429 | private SkyValue evaluateArtifactValue(Artifact artifact) throws Throwable { |
lberki | 36df7ed | 2019-06-27 06:32:03 -0700 | [diff] [blame] | 430 | SkyKey key = Artifact.key(artifact); |
Janak Ramakrishnan | ad77f97 | 2016-07-29 20:58:42 +0000 | [diff] [blame] | 431 | EvaluationResult<SkyValue> result = evaluate(ImmutableList.of(key).toArray(new SkyKey[0])); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 432 | if (result.hasError()) { |
| 433 | throw result.getError().getException(); |
| 434 | } |
janakr | 8541f6d | 2019-06-11 14:40:21 -0700 | [diff] [blame] | 435 | SkyValue value = result.get(key); |
| 436 | if (value instanceof ActionExecutionValue) { |
Googler | 72d648a | 2020-05-21 11:56:40 -0700 | [diff] [blame] | 437 | return ((ActionExecutionValue) value) |
| 438 | .getExistingFileArtifactValue((DerivedArtifact) artifact); |
janakr | 8541f6d | 2019-06-11 14:40:21 -0700 | [diff] [blame] | 439 | } |
| 440 | return value; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 441 | } |
| 442 | |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 443 | private void setGeneratingActions() throws InterruptedException, ActionConflictException { |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 444 | if (evaluator.getExistingValue(ALL_OWNER) == null) { |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 445 | differencer.inject( |
| 446 | ImmutableMap.of( |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 447 | ALL_OWNER, |
cparsons | e2d200f | 2018-03-06 16:15:11 -0800 | [diff] [blame] | 448 | new BasicActionLookupValue( |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 449 | Actions.assignOwnersAndFilterSharedActionsAndThrowActionConflict( |
| 450 | actionKeyContext, |
| 451 | ImmutableList.copyOf(actions), |
| 452 | ALL_OWNER, |
Googler | ce6ad29 | 2019-12-20 10:29:21 -0800 | [diff] [blame] | 453 | /*outputFiles=*/ null)))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
| 457 | private <E extends SkyValue> EvaluationResult<E> evaluate(SkyKey... keys) |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 458 | throws InterruptedException, ActionConflictException { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 459 | setGeneratingActions(); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 460 | EvaluationContext evaluationContext = |
| 461 | EvaluationContext.newBuilder() |
| 462 | .setKeepGoing(false) |
| 463 | .setNumThreads(SkyframeExecutor.DEFAULT_THREAD_COUNT) |
| 464 | .setEventHander(NullEventHandler.INSTANCE) |
| 465 | .build(); |
| 466 | return driver.evaluate(Arrays.asList(keys), evaluationContext); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 469 | /** |
| 470 | * Value builder for actions that just stats and stores the output file (which must either be |
| 471 | * orphaned or exist). |
| 472 | */ |
| 473 | private static final class SimpleActionExecutionFunction implements SkyFunction { |
| 474 | private final Set<Artifact> omittedOutputs; |
| 475 | |
| 476 | SimpleActionExecutionFunction(Set<Artifact> omittedOutputs) { |
| 477 | this.omittedOutputs = omittedOutputs; |
| 478 | } |
| 479 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 480 | @Override |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 481 | public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException { |
lberki | f7eee1e | 2019-07-31 05:49:10 -0700 | [diff] [blame] | 482 | Map<Artifact, FileArtifactValue> artifactData = new HashMap<>(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 483 | Map<Artifact, TreeArtifactValue> treeArtifactData = new HashMap<>(); |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 484 | ActionLookupData actionLookupData = (ActionLookupData) skyKey.argument(); |
| 485 | ActionLookupValue actionLookupValue = |
janakr | baf52ae | 2018-02-14 09:03:18 -0800 | [diff] [blame] | 486 | (ActionLookupValue) env.getValue(actionLookupData.getActionLookupKey()); |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 487 | Action action = actionLookupValue.getAction(actionLookupData.getActionIndex()); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 488 | Artifact output = Iterables.getOnlyElement(action.getOutputs()); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 489 | |
| 490 | try { |
Googler | 3b2967d | 2020-05-18 14:54:46 -0700 | [diff] [blame] | 491 | if (omittedOutputs.contains(output)) { |
| 492 | Preconditions.checkState(!output.isTreeArtifact(), "Cannot omit %s", output); |
| 493 | artifactData.put(output, FileArtifactValue.OMITTED_FILE_MARKER); |
| 494 | } else if (output.isTreeArtifact()) { |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 495 | TreeFileArtifact treeFileArtifact1 = |
| 496 | TreeFileArtifact.createTreeOutput((SpecialArtifact) output, "child1"); |
| 497 | TreeFileArtifact treeFileArtifact2 = |
| 498 | TreeFileArtifact.createTreeOutput((SpecialArtifact) output, "child2"); |
lberki | 812e6fe | 2019-07-25 07:50:55 -0700 | [diff] [blame] | 499 | TreeArtifactValue treeArtifactValue = |
| 500 | TreeArtifactValue.create( |
| 501 | ImmutableMap.of( |
| 502 | treeFileArtifact1, FileArtifactValue.createForTesting(treeFileArtifact1), |
| 503 | treeFileArtifact2, FileArtifactValue.createForTesting(treeFileArtifact2))); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 504 | treeArtifactData.put(output, treeArtifactValue); |
| 505 | } else if (action.getActionType() == MiddlemanType.NORMAL) { |
lberki | f225af1 | 2019-08-01 04:21:58 -0700 | [diff] [blame] | 506 | Path path = output.getPath(); |
| 507 | FileArtifactValue noDigest = |
| 508 | ActionMetadataHandler.fileArtifactValueFromArtifact( |
| 509 | output, |
| 510 | FileStatusWithDigestAdapter.adapt(path.statIfFound(Symlinks.NOFOLLOW)), |
| 511 | null); |
| 512 | FileArtifactValue withDigest = |
| 513 | FileArtifactValue.createFromInjectedDigest( |
| 514 | noDigest, path.getDigest(), !output.isConstantMetadata()); |
| 515 | artifactData.put(output, withDigest); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 516 | } else { |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 517 | artifactData.put(output, FileArtifactValue.DEFAULT_MIDDLEMAN); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 518 | } |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 519 | } catch (IOException e) { |
| 520 | throw new IllegalStateException(e); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 521 | } |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 522 | return ActionExecutionValue.create( |
| 523 | artifactData, |
| 524 | treeArtifactData, |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 525 | /*outputSymlinks=*/ null, |
shahan | ef6f4cf | 2018-06-26 11:24:59 -0700 | [diff] [blame] | 526 | /*discoveredModules=*/ null, |
janakr | 9f496f3 | 2018-10-24 15:08:09 -0700 | [diff] [blame] | 527 | /*actionDependsOnBuildId=*/ false); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | @Override |
| 531 | public String extractTag(SkyKey skyKey) { |
| 532 | return null; |
| 533 | } |
| 534 | } |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 535 | } |