Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1 | // Copyright 2016 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 16 | import static com.google.common.truth.Truth.assertThat; |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 17 | import static com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 18 | import static org.junit.Assert.fail; |
| 19 | |
| 20 | import com.google.common.base.Function; |
| 21 | import com.google.common.base.Preconditions; |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 22 | import com.google.common.base.Predicate; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 23 | import com.google.common.collect.Collections2; |
| 24 | import com.google.common.collect.ImmutableList; |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 25 | import com.google.common.collect.Iterables; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 26 | import com.google.common.collect.Lists; |
| 27 | import com.google.common.hash.Hashing; |
| 28 | import com.google.common.util.concurrent.Runnables; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 29 | import com.google.devtools.build.lib.actions.Action; |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 30 | import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 31 | import com.google.devtools.build.lib.actions.ActionExecutionContext; |
| 32 | import com.google.devtools.build.lib.actions.ActionExecutionException; |
| 33 | import com.google.devtools.build.lib.actions.ActionInput; |
| 34 | import com.google.devtools.build.lib.actions.ActionInputHelper; |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 35 | import com.google.devtools.build.lib.actions.ActionKeyContext; |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 36 | import com.google.devtools.build.lib.actions.ActionResult; |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 37 | import com.google.devtools.build.lib.actions.Actions; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 38 | import com.google.devtools.build.lib.actions.Artifact; |
| 39 | import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; |
| 40 | import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType; |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 41 | import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 42 | import com.google.devtools.build.lib.actions.ArtifactRoot; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 43 | import com.google.devtools.build.lib.actions.BuildFailedException; |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 44 | import com.google.devtools.build.lib.actions.MetadataProvider; |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 45 | import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; |
shahan | 2cbfb89 | 2018-03-28 09:00:11 -0700 | [diff] [blame] | 46 | import com.google.devtools.build.lib.actions.OutputBaseSupplier; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 47 | import com.google.devtools.build.lib.actions.cache.MetadataHandler; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 48 | import com.google.devtools.build.lib.actions.util.ActionsTestUtil; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 49 | import com.google.devtools.build.lib.actions.util.TestAction; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 50 | import com.google.devtools.build.lib.actions.util.TestAction.DummyAction; |
| 51 | import com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate; |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 52 | import com.google.devtools.build.lib.events.Event; |
| 53 | import com.google.devtools.build.lib.events.EventKind; |
| 54 | import com.google.devtools.build.lib.events.StoredEventHandler; |
shahan | 20f35b4 | 2018-02-28 15:57:33 -0800 | [diff] [blame] | 55 | import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 56 | import com.google.devtools.build.lib.testutil.TestUtils; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 57 | import com.google.devtools.build.lib.vfs.FileStatus; |
| 58 | import com.google.devtools.build.lib.vfs.FileSystem; |
| 59 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
| 60 | import com.google.devtools.build.lib.vfs.Path; |
| 61 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 62 | import com.google.devtools.build.lib.vfs.Symlinks; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 63 | import com.google.devtools.build.skyframe.SkyFunction; |
| 64 | import com.google.devtools.build.skyframe.SkyKey; |
| 65 | import com.google.devtools.build.skyframe.SkyValue; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 66 | import java.io.IOException; |
| 67 | import java.nio.charset.Charset; |
| 68 | import java.util.Arrays; |
| 69 | import java.util.Collection; |
| 70 | import java.util.Iterator; |
| 71 | import java.util.List; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 72 | import javax.annotation.Nullable; |
Rumou Duan | baeed33 | 2016-10-18 15:30:25 +0000 | [diff] [blame] | 73 | import org.junit.Before; |
| 74 | import org.junit.Test; |
| 75 | import org.junit.runner.RunWith; |
| 76 | import org.junit.runners.JUnit4; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 77 | |
| 78 | /** Timestamp builder tests for TreeArtifacts. */ |
| 79 | @RunWith(JUnit4.class) |
| 80 | public class TreeArtifactBuildTest extends TimestampBuilderTestCase { |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 81 | |
| 82 | private static final Predicate<Event> IS_ERROR_EVENT = new Predicate<Event>() { |
| 83 | @Override |
| 84 | public boolean apply(Event event) { |
| 85 | return event.getKind().equals(EventKind.ERROR); |
| 86 | } |
| 87 | }; |
| 88 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 89 | // Common Artifacts, TreeFileArtifact, and Buttons. These aren't all used in all tests, but |
| 90 | // they're used often enough that we can save ourselves a lot of copy-pasted code by creating them |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 91 | // in setUp(). |
| 92 | |
| 93 | Artifact in; |
| 94 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 95 | SpecialArtifact outOne; |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 96 | TreeFileArtifact outOneFileOne; |
| 97 | TreeFileArtifact outOneFileTwo; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 98 | Button buttonOne = new Button(); |
| 99 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 100 | SpecialArtifact outTwo; |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 101 | TreeFileArtifact outTwoFileOne; |
| 102 | TreeFileArtifact outTwoFileTwo; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 103 | Button buttonTwo = new Button(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 104 | @Before |
| 105 | public void setUp() throws Exception { |
| 106 | in = createSourceArtifact("input"); |
| 107 | writeFile(in, "input_content"); |
| 108 | |
| 109 | outOne = createTreeArtifact("outputOne"); |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 110 | outOneFileOne = treeFileArtifact(outOne, "out_one_file_one"); |
| 111 | outOneFileTwo = treeFileArtifact(outOne, "out_one_file_two"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 112 | |
| 113 | outTwo = createTreeArtifact("outputTwo"); |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 114 | outTwoFileOne = treeFileArtifact(outTwo, "out_one_file_one"); |
| 115 | outTwoFileTwo = treeFileArtifact(outTwo, "out_one_file_two"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 116 | } |
| 117 | |
cpeyser | 875068a | 2018-02-01 08:40:58 -0800 | [diff] [blame] | 118 | @Test |
| 119 | public void testCodec() throws Exception { |
shahan | 20f35b4 | 2018-02-28 15:57:33 -0800 | [diff] [blame] | 120 | new SerializationTester(outOne, outOneFileOne) |
shahan | fae34b9 | 2018-02-13 10:08:47 -0800 | [diff] [blame] | 121 | .addDependency(FileSystem.class, scratch.getFileSystem()) |
shahan | 2cbfb89 | 2018-03-28 09:00:11 -0700 | [diff] [blame] | 122 | .addDependency( |
| 123 | OutputBaseSupplier.class, () -> scratch.getFileSystem().getPath(TestUtils.tmpDir())) |
shahan | 20f35b4 | 2018-02-28 15:57:33 -0800 | [diff] [blame] | 124 | .runTests(); |
cpeyser | 875068a | 2018-02-01 08:40:58 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 127 | /** Simple smoke test. If this isn't passing, something is very wrong... */ |
| 128 | @Test |
| 129 | public void testTreeArtifactSimpleCase() throws Exception { |
| 130 | TouchingTestAction action = new TouchingTestAction(outOneFileOne, outOneFileTwo); |
| 131 | registerAction(action); |
| 132 | buildArtifact(action.getSoleOutput()); |
| 133 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 134 | assertThat(outOneFileOne.getPath().exists()).isTrue(); |
| 135 | assertThat(outOneFileTwo.getPath().exists()).isTrue(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** Simple test for the case with dependencies. */ |
| 139 | @Test |
| 140 | public void testDependentTreeArtifacts() throws Exception { |
| 141 | TouchingTestAction actionOne = new TouchingTestAction(outOneFileOne, outOneFileTwo); |
| 142 | registerAction(actionOne); |
| 143 | |
| 144 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 145 | ImmutableList.of(outOneFileOne, outOneFileTwo), |
| 146 | ImmutableList.of(outTwoFileOne, outTwoFileTwo)); |
| 147 | registerAction(actionTwo); |
| 148 | |
| 149 | buildArtifact(outTwo); |
| 150 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 151 | assertThat(outOneFileOne.getPath().exists()).isTrue(); |
| 152 | assertThat(outOneFileTwo.getPath().exists()).isTrue(); |
| 153 | assertThat(outTwoFileOne.getPath().exists()).isTrue(); |
| 154 | assertThat(outTwoFileTwo.getPath().exists()).isTrue(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Rumou Duan | baeed33 | 2016-10-18 15:30:25 +0000 | [diff] [blame] | 157 | @Test |
| 158 | public void testInputTreeArtifactPerActionFileCache() throws Exception { |
| 159 | TouchingTestAction actionOne = new TouchingTestAction(outOneFileOne, outOneFileTwo); |
| 160 | registerAction(actionOne); |
| 161 | |
Philipp Wollermann | 3d93b8f | 2016-10-19 13:35:27 +0000 | [diff] [blame] | 162 | final Artifact normalOutput = createDerivedArtifact("normal/out"); |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 163 | Action testAction = |
| 164 | new TestAction( |
| 165 | TestAction.NO_EFFECT, ImmutableList.of(outOne), ImmutableList.of(normalOutput)) { |
| 166 | @Override |
| 167 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
| 168 | try { |
| 169 | // Check the file cache for input TreeFileArtifacts. |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 170 | MetadataProvider fileCache = actionExecutionContext.getMetadataProvider(); |
ulfjack | 4abd6c3 | 2017-12-21 10:52:16 -0800 | [diff] [blame] | 171 | assertThat(fileCache.getMetadata(outOneFileOne).getType().isFile()).isTrue(); |
| 172 | assertThat(fileCache.getMetadata(outOneFileTwo).getType().isFile()).isTrue(); |
Rumou Duan | baeed33 | 2016-10-18 15:30:25 +0000 | [diff] [blame] | 173 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 174 | // Touch the action output. |
| 175 | touchFile(normalOutput); |
| 176 | } catch (Exception e) { |
| 177 | throw new RuntimeException(e); |
| 178 | } |
| 179 | return ActionResult.EMPTY; |
| 180 | } |
| 181 | }; |
Rumou Duan | baeed33 | 2016-10-18 15:30:25 +0000 | [diff] [blame] | 182 | |
| 183 | registerAction(testAction); |
| 184 | buildArtifact(normalOutput); |
| 185 | } |
| 186 | |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 187 | /** Unchanged TreeArtifact outputs should not cause reexecution. */ |
| 188 | @Test |
| 189 | public void testCacheCheckingForTreeArtifactsDoesNotCauseReexecution() throws Exception { |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 190 | SpecialArtifact outOne = createTreeArtifact("outputOne"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 191 | Button buttonOne = new Button(); |
| 192 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 193 | SpecialArtifact outTwo = createTreeArtifact("outputTwo"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 194 | Button buttonTwo = new Button(); |
| 195 | |
| 196 | TouchingTestAction actionOne = new TouchingTestAction( |
| 197 | buttonOne, outOne, "file_one", "file_two"); |
| 198 | registerAction(actionOne); |
| 199 | |
| 200 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 201 | buttonTwo, outOne, outTwo, "file_one", "file_two"); |
| 202 | registerAction(actionTwo); |
| 203 | |
| 204 | buttonOne.pressed = buttonTwo.pressed = false; |
| 205 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 206 | assertThat(buttonOne.pressed).isTrue(); // built |
| 207 | assertThat(buttonTwo.pressed).isTrue(); // built |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 208 | |
| 209 | buttonOne.pressed = buttonTwo.pressed = false; |
| 210 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 211 | assertThat(buttonOne.pressed).isFalse(); // not built |
| 212 | assertThat(buttonTwo.pressed).isFalse(); // not built |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Test rebuilding TreeArtifacts for inputs, outputs, and dependents. |
| 217 | * Also a test for caching. |
| 218 | */ |
| 219 | @Test |
| 220 | public void testTransitiveReexecutionForTreeArtifacts() throws Exception { |
| 221 | WriteInputToFilesAction actionOne = new WriteInputToFilesAction( |
| 222 | buttonOne, |
| 223 | in, |
| 224 | outOneFileOne, outOneFileTwo); |
| 225 | registerAction(actionOne); |
| 226 | |
| 227 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 228 | buttonTwo, |
| 229 | ImmutableList.of(outOneFileOne, outOneFileTwo), |
| 230 | ImmutableList.of(outTwoFileOne, outTwoFileTwo)); |
| 231 | registerAction(actionTwo); |
| 232 | |
| 233 | buttonOne.pressed = buttonTwo.pressed = false; |
| 234 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 235 | assertThat(buttonOne.pressed).isTrue(); // built |
| 236 | assertThat(buttonTwo.pressed).isTrue(); // built |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 237 | |
| 238 | buttonOne.pressed = buttonTwo.pressed = false; |
| 239 | writeFile(in, "modified_input"); |
| 240 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 241 | assertThat(buttonOne.pressed).isTrue(); // built |
| 242 | assertThat(buttonTwo.pressed).isTrue(); // not built |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 243 | |
| 244 | buttonOne.pressed = buttonTwo.pressed = false; |
| 245 | writeFile(outOneFileOne, "modified_output"); |
| 246 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 247 | assertThat(buttonOne.pressed).isTrue(); // built |
| 248 | assertThat(buttonTwo.pressed).isFalse(); // should have been cached |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 249 | |
| 250 | buttonOne.pressed = buttonTwo.pressed = false; |
| 251 | writeFile(outTwoFileOne, "more_modified_output"); |
| 252 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 253 | assertThat(buttonOne.pressed).isFalse(); // not built |
| 254 | assertThat(buttonTwo.pressed).isTrue(); // built |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /** Tests that changing a TreeArtifact directory should cause reexeuction. */ |
| 258 | @Test |
| 259 | public void testDirectoryContentsCachingForTreeArtifacts() throws Exception { |
| 260 | WriteInputToFilesAction actionOne = new WriteInputToFilesAction( |
| 261 | buttonOne, |
| 262 | in, |
| 263 | outOneFileOne, outOneFileTwo); |
| 264 | registerAction(actionOne); |
| 265 | |
| 266 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 267 | buttonTwo, |
| 268 | ImmutableList.of(outOneFileOne, outOneFileTwo), |
| 269 | ImmutableList.of(outTwoFileOne, outTwoFileTwo)); |
| 270 | registerAction(actionTwo); |
| 271 | |
| 272 | buttonOne.pressed = buttonTwo.pressed = false; |
| 273 | buildArtifact(outTwo); |
| 274 | // just a smoke test--if these aren't built we have bigger problems! |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 275 | assertThat(buttonOne.pressed).isTrue(); |
| 276 | assertThat(buttonTwo.pressed).isTrue(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 277 | |
| 278 | // Adding a file to a directory should cause reexecution. |
| 279 | buttonOne.pressed = buttonTwo.pressed = false; |
| 280 | Path spuriousOutputOne = outOne.getPath().getRelative("spuriousOutput"); |
| 281 | touchFile(spuriousOutputOne); |
| 282 | buildArtifact(outTwo); |
| 283 | // Should re-execute, and delete spurious output |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 284 | assertThat(spuriousOutputOne.exists()).isFalse(); |
| 285 | assertThat(buttonOne.pressed).isTrue(); |
| 286 | assertThat(buttonTwo.pressed).isFalse(); // should have been cached |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 287 | |
| 288 | buttonOne.pressed = buttonTwo.pressed = false; |
| 289 | Path spuriousOutputTwo = outTwo.getPath().getRelative("anotherSpuriousOutput"); |
| 290 | touchFile(spuriousOutputTwo); |
| 291 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 292 | assertThat(spuriousOutputTwo.exists()).isFalse(); |
| 293 | assertThat(buttonOne.pressed).isFalse(); |
| 294 | assertThat(buttonTwo.pressed).isTrue(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 295 | |
| 296 | // Deleting should cause reexecution. |
| 297 | buttonOne.pressed = buttonTwo.pressed = false; |
| 298 | deleteFile(outOneFileOne); |
| 299 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 300 | assertThat(outOneFileOne.getPath().exists()).isTrue(); |
| 301 | assertThat(buttonOne.pressed).isTrue(); |
| 302 | assertThat(buttonTwo.pressed).isFalse(); // should have been cached |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 303 | |
| 304 | buttonOne.pressed = buttonTwo.pressed = false; |
| 305 | deleteFile(outTwoFileOne); |
| 306 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 307 | assertThat(outTwoFileOne.getPath().exists()).isTrue(); |
| 308 | assertThat(buttonOne.pressed).isFalse(); |
| 309 | assertThat(buttonTwo.pressed).isTrue(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Janak Ramakrishnan | 08b0f7f | 2016-07-13 17:00:59 +0000 | [diff] [blame] | 312 | /** TreeArtifacts don't care about mtime, even when the file is empty. */ |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 313 | @Test |
| 314 | public void testMTimeForTreeArtifactsDoesNotMatter() throws Exception { |
| 315 | // For this test, we only touch the input file. |
| 316 | Artifact in = createSourceArtifact("touchable_input"); |
| 317 | touchFile(in); |
| 318 | |
| 319 | WriteInputToFilesAction actionOne = new WriteInputToFilesAction( |
| 320 | buttonOne, |
| 321 | in, |
| 322 | outOneFileOne, outOneFileTwo); |
| 323 | registerAction(actionOne); |
| 324 | |
| 325 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 326 | buttonTwo, |
| 327 | ImmutableList.of(outOneFileOne, outOneFileTwo), |
| 328 | ImmutableList.of(outTwoFileOne, outTwoFileTwo)); |
| 329 | registerAction(actionTwo); |
| 330 | |
| 331 | buttonOne.pressed = buttonTwo.pressed = false; |
| 332 | buildArtifact(outTwo); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 333 | assertThat(buttonOne.pressed).isTrue(); // built |
| 334 | assertThat(buttonTwo.pressed).isTrue(); // built |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 335 | |
| 336 | buttonOne.pressed = buttonTwo.pressed = false; |
| 337 | touchFile(in); |
| 338 | buildArtifact(outTwo); |
Janak Ramakrishnan | 08b0f7f | 2016-07-13 17:00:59 +0000 | [diff] [blame] | 339 | // mtime does not matter. |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 340 | assertThat(buttonOne.pressed).isFalse(); |
| 341 | assertThat(buttonTwo.pressed).isFalse(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 342 | |
| 343 | // None of the below following should result in anything being built. |
| 344 | buttonOne.pressed = buttonTwo.pressed = false; |
| 345 | touchFile(outOneFileOne); |
| 346 | buildArtifact(outTwo); |
| 347 | // Nothing should be built. |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 348 | assertThat(buttonOne.pressed).isFalse(); |
| 349 | assertThat(buttonTwo.pressed).isFalse(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 350 | |
| 351 | buttonOne.pressed = buttonTwo.pressed = false; |
| 352 | touchFile(outOneFileTwo); |
| 353 | buildArtifact(outTwo); |
| 354 | // Nothing should be built. |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 355 | assertThat(buttonOne.pressed).isFalse(); |
| 356 | assertThat(buttonTwo.pressed).isFalse(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /** Tests that the declared order of TreeArtifact contents does not matter. */ |
| 360 | @Test |
| 361 | public void testOrderIndependenceOfTreeArtifactContents() throws Exception { |
| 362 | WriteInputToFilesAction actionOne = new WriteInputToFilesAction( |
| 363 | in, |
| 364 | // The design of WritingTestAction is s.t. |
| 365 | // these files will be registered in the given order. |
| 366 | outOneFileTwo, outOneFileOne); |
| 367 | registerAction(actionOne); |
| 368 | |
| 369 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 370 | ImmutableList.of(outOneFileOne, outOneFileTwo), |
| 371 | ImmutableList.of(outTwoFileOne, outTwoFileTwo)); |
| 372 | registerAction(actionTwo); |
| 373 | |
| 374 | buildArtifact(outTwo); |
| 375 | } |
| 376 | |
| 377 | @Test |
| 378 | public void testActionExpansion() throws Exception { |
| 379 | WriteInputToFilesAction action = new WriteInputToFilesAction(in, outOneFileOne, outOneFileTwo); |
| 380 | |
| 381 | CopyTreeAction actionTwo = new CopyTreeAction( |
| 382 | ImmutableList.of(outOneFileOne, outOneFileTwo), |
| 383 | ImmutableList.of(outTwoFileOne, outTwoFileTwo)) { |
| 384 | @Override |
| 385 | public void executeTestBehavior(ActionExecutionContext actionExecutionContext) |
| 386 | throws ActionExecutionException { |
| 387 | super.executeTestBehavior(actionExecutionContext); |
| 388 | |
| 389 | Collection<ActionInput> expanded = |
| 390 | ActionInputHelper.expandArtifacts(ImmutableList.of(outOne), |
| 391 | actionExecutionContext.getArtifactExpander()); |
| 392 | // Only files registered should show up here. |
| 393 | assertThat(expanded).containsExactly(outOneFileOne, outOneFileTwo); |
| 394 | } |
| 395 | }; |
| 396 | |
| 397 | registerAction(action); |
| 398 | registerAction(actionTwo); |
| 399 | |
| 400 | buildArtifact(outTwo); // should not fail |
| 401 | } |
| 402 | |
| 403 | @Test |
| 404 | public void testInvalidOutputRegistrations() throws Exception { |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 405 | // Failure expected |
| 406 | StoredEventHandler storingEventHandler = new StoredEventHandler(); |
| 407 | reporter.removeHandler(failFastHandler); |
| 408 | reporter.addHandler(storingEventHandler); |
| 409 | |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 410 | TreeArtifactTestAction failureOne = new TreeArtifactTestAction( |
| 411 | Runnables.doNothing(), outOneFileOne, outOneFileTwo) { |
| 412 | @Override |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 413 | public void executeTestBehavior(ActionExecutionContext actionExecutionContext) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 414 | try { |
| 415 | writeFile(outOneFileOne, "one"); |
| 416 | writeFile(outOneFileTwo, "two"); |
| 417 | // In this test case, we only register one output. This will fail. |
| 418 | registerOutput(actionExecutionContext, "one"); |
| 419 | } catch (IOException e) { |
| 420 | throw new RuntimeException(e); |
| 421 | } |
| 422 | } |
| 423 | }; |
| 424 | |
| 425 | registerAction(failureOne); |
| 426 | try { |
| 427 | buildArtifact(outOne); |
| 428 | fail(); // Should have thrown |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 429 | } catch (BuildFailedException e) { |
| 430 | //not all outputs were created |
| 431 | List<Event> errors = ImmutableList.copyOf( |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 432 | Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT)); |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 433 | assertThat(errors).hasSize(2); |
| 434 | assertThat(errors.get(0).getMessage()).contains("not present on disk"); |
| 435 | assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | TreeArtifactTestAction failureTwo = new TreeArtifactTestAction( |
| 439 | Runnables.doNothing(), outTwoFileOne, outTwoFileTwo) { |
| 440 | @Override |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 441 | public void executeTestBehavior(ActionExecutionContext actionExecutionContext) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 442 | try { |
| 443 | writeFile(outTwoFileOne, "one"); |
| 444 | writeFile(outTwoFileTwo, "two"); |
| 445 | // In this test case, register too many outputs. This will fail. |
| 446 | registerOutput(actionExecutionContext, "one"); |
| 447 | registerOutput(actionExecutionContext, "two"); |
| 448 | registerOutput(actionExecutionContext, "three"); |
| 449 | } catch (IOException e) { |
| 450 | throw new RuntimeException(e); |
| 451 | } |
| 452 | } |
| 453 | }; |
| 454 | |
| 455 | registerAction(failureTwo); |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 456 | storingEventHandler.clear(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 457 | try { |
| 458 | buildArtifact(outTwo); |
| 459 | fail(); // Should have thrown |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 460 | } catch (BuildFailedException e) { |
| 461 | List<Event> errors = ImmutableList.copyOf( |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 462 | Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT)); |
Rumou Duan | 9ad28cd | 2016-10-19 19:28:06 +0000 | [diff] [blame] | 463 | assertThat(errors).hasSize(2); |
| 464 | assertThat(errors.get(0).getMessage()).contains("not present on disk"); |
| 465 | assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | private static void checkDirectoryPermissions(Path path) throws IOException { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 470 | assertThat(path.isDirectory()).isTrue(); |
| 471 | assertThat(path.isExecutable()).isTrue(); |
| 472 | assertThat(path.isReadable()).isTrue(); |
| 473 | assertThat(path.isWritable()).isFalse(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | private static void checkFilePermissions(Path path) throws IOException { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 477 | assertThat(path.isDirectory()).isFalse(); |
| 478 | assertThat(path.isExecutable()).isTrue(); |
| 479 | assertThat(path.isReadable()).isTrue(); |
| 480 | assertThat(path.isWritable()).isFalse(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | @Test |
| 484 | public void testOutputsAreReadOnlyAndExecutable() throws Exception { |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 485 | final SpecialArtifact out = createTreeArtifact("output"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 486 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 487 | TreeArtifactTestAction action = |
| 488 | new TreeArtifactTestAction(out) { |
| 489 | @Override |
| 490 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
| 491 | try { |
| 492 | writeFile(out.getPath().getChild("one"), "one"); |
| 493 | writeFile(out.getPath().getChild("two"), "two"); |
| 494 | writeFile(out.getPath().getChild("three").getChild("four"), "three/four"); |
| 495 | registerOutput(actionExecutionContext, "one"); |
| 496 | registerOutput(actionExecutionContext, "two"); |
| 497 | registerOutput(actionExecutionContext, "three/four"); |
| 498 | } catch (Exception e) { |
| 499 | throw new RuntimeException(e); |
| 500 | } |
| 501 | return ActionResult.EMPTY; |
| 502 | } |
| 503 | }; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 504 | |
| 505 | registerAction(action); |
| 506 | |
| 507 | buildArtifact(action.getSoleOutput()); |
| 508 | |
| 509 | checkDirectoryPermissions(out.getPath()); |
| 510 | checkFilePermissions(out.getPath().getChild("one")); |
| 511 | checkFilePermissions(out.getPath().getChild("two")); |
| 512 | checkDirectoryPermissions(out.getPath().getChild("three")); |
| 513 | checkFilePermissions(out.getPath().getChild("three").getChild("four")); |
| 514 | } |
| 515 | |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 516 | @Test |
| 517 | public void testValidRelativeSymlinkAccepted() throws Exception { |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 518 | final SpecialArtifact out = createTreeArtifact("output"); |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 519 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 520 | TreeArtifactTestAction action = |
| 521 | new TreeArtifactTestAction(out) { |
| 522 | @Override |
| 523 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
| 524 | try { |
| 525 | writeFile(out.getPath().getChild("one"), "one"); |
| 526 | writeFile(out.getPath().getChild("two"), "two"); |
| 527 | FileSystemUtils.ensureSymbolicLink( |
| 528 | out.getPath().getChild("links").getChild("link"), "../one"); |
| 529 | } catch (Exception e) { |
| 530 | throw new RuntimeException(e); |
| 531 | } |
| 532 | return ActionResult.EMPTY; |
| 533 | } |
| 534 | }; |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 535 | |
| 536 | registerAction(action); |
| 537 | |
| 538 | buildArtifact(action.getSoleOutput()); |
| 539 | } |
| 540 | |
| 541 | @Test |
| 542 | public void testInvalidSymlinkRejected() throws Exception { |
| 543 | // Failure expected |
| 544 | StoredEventHandler storingEventHandler = new StoredEventHandler(); |
| 545 | reporter.removeHandler(failFastHandler); |
| 546 | reporter.addHandler(storingEventHandler); |
| 547 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 548 | final SpecialArtifact out = createTreeArtifact("output"); |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 549 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 550 | TreeArtifactTestAction action = |
| 551 | new TreeArtifactTestAction(out) { |
| 552 | @Override |
| 553 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
| 554 | try { |
| 555 | writeFile(out.getPath().getChild("one"), "one"); |
| 556 | writeFile(out.getPath().getChild("two"), "two"); |
| 557 | FileSystemUtils.ensureSymbolicLink( |
| 558 | out.getPath().getChild("links").getChild("link"), "../invalid"); |
| 559 | } catch (Exception e) { |
| 560 | throw new RuntimeException(e); |
| 561 | } |
| 562 | return ActionResult.EMPTY; |
| 563 | } |
| 564 | }; |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 565 | |
| 566 | registerAction(action); |
| 567 | |
| 568 | try { |
| 569 | buildArtifact(action.getSoleOutput()); |
| 570 | fail(); // Should have thrown |
| 571 | } catch (BuildFailedException e) { |
| 572 | List<Event> errors = ImmutableList.copyOf( |
| 573 | Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT)); |
| 574 | assertThat(errors).hasSize(2); |
| 575 | assertThat(errors.get(0).getMessage()).contains( |
| 576 | "Failed to resolve relative path links/link"); |
| 577 | assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid"); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | @Test |
Janak Ramakrishnan | 6b4a8b3 | 2017-02-22 19:51:28 +0000 | [diff] [blame] | 582 | public void testAbsoluteSymlinkBadTargetRejected() throws Exception { |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 583 | // Failure expected |
| 584 | StoredEventHandler storingEventHandler = new StoredEventHandler(); |
| 585 | reporter.removeHandler(failFastHandler); |
| 586 | reporter.addHandler(storingEventHandler); |
| 587 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 588 | final SpecialArtifact out = createTreeArtifact("output"); |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 589 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 590 | TreeArtifactTestAction action = |
| 591 | new TreeArtifactTestAction(out) { |
| 592 | @Override |
| 593 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
| 594 | try { |
| 595 | writeFile(out.getPath().getChild("one"), "one"); |
| 596 | writeFile(out.getPath().getChild("two"), "two"); |
| 597 | FileSystemUtils.ensureSymbolicLink( |
| 598 | out.getPath().getChild("links").getChild("link"), "/random/pointer"); |
| 599 | } catch (Exception e) { |
| 600 | throw new RuntimeException(e); |
| 601 | } |
| 602 | return ActionResult.EMPTY; |
| 603 | } |
| 604 | }; |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 605 | |
| 606 | registerAction(action); |
| 607 | |
| 608 | try { |
| 609 | buildArtifact(action.getSoleOutput()); |
| 610 | fail(); // Should have thrown |
| 611 | } catch (BuildFailedException e) { |
| 612 | List<Event> errors = ImmutableList.copyOf( |
| 613 | Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT)); |
| 614 | assertThat(errors).hasSize(2); |
Janak Ramakrishnan | 6b4a8b3 | 2017-02-22 19:51:28 +0000 | [diff] [blame] | 615 | assertThat(errors.get(0).getMessage()).contains("Failed to resolve relative path links/link"); |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 616 | assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid"); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | @Test |
Janak Ramakrishnan | 6b4a8b3 | 2017-02-22 19:51:28 +0000 | [diff] [blame] | 621 | public void testAbsoluteSymlinkAccepted() throws Exception { |
| 622 | scratch.overwriteFile("/random/pointer"); |
| 623 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 624 | final SpecialArtifact out = createTreeArtifact("output"); |
Janak Ramakrishnan | 6b4a8b3 | 2017-02-22 19:51:28 +0000 | [diff] [blame] | 625 | |
| 626 | TreeArtifactTestAction action = |
| 627 | new TreeArtifactTestAction(out) { |
| 628 | @Override |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 629 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
Janak Ramakrishnan | 6b4a8b3 | 2017-02-22 19:51:28 +0000 | [diff] [blame] | 630 | try { |
| 631 | writeFile(out.getPath().getChild("one"), "one"); |
| 632 | writeFile(out.getPath().getChild("two"), "two"); |
| 633 | FileSystemUtils.ensureSymbolicLink( |
| 634 | out.getPath().getChild("links").getChild("link"), "/random/pointer"); |
| 635 | } catch (Exception e) { |
| 636 | throw new RuntimeException(e); |
| 637 | } |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 638 | return ActionResult.EMPTY; |
Janak Ramakrishnan | 6b4a8b3 | 2017-02-22 19:51:28 +0000 | [diff] [blame] | 639 | } |
| 640 | }; |
| 641 | |
| 642 | registerAction(action); |
| 643 | |
| 644 | buildArtifact(action.getSoleOutput()); |
| 645 | } |
| 646 | |
| 647 | @Test |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 648 | public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception { |
| 649 | // Failure expected |
| 650 | StoredEventHandler storingEventHandler = new StoredEventHandler(); |
| 651 | reporter.removeHandler(failFastHandler); |
| 652 | reporter.addHandler(storingEventHandler); |
| 653 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 654 | final SpecialArtifact out = createTreeArtifact("output"); |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 655 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 656 | TreeArtifactTestAction action = |
| 657 | new TreeArtifactTestAction(out) { |
| 658 | @Override |
| 659 | public ActionResult execute(ActionExecutionContext actionExecutionContext) { |
| 660 | try { |
| 661 | writeFile(out.getPath().getChild("one"), "one"); |
| 662 | writeFile(out.getPath().getChild("two"), "two"); |
| 663 | FileSystemUtils.ensureSymbolicLink( |
| 664 | out.getPath().getChild("links").getChild("link"), "../../output/random/pointer"); |
| 665 | } catch (Exception e) { |
| 666 | throw new RuntimeException(e); |
| 667 | } |
| 668 | return ActionResult.EMPTY; |
| 669 | } |
| 670 | }; |
Rumou Duan | 11730a0 | 2016-10-24 20:27:58 +0000 | [diff] [blame] | 671 | |
| 672 | registerAction(action); |
| 673 | |
| 674 | try { |
| 675 | buildArtifact(action.getSoleOutput()); |
| 676 | fail(); // Should have thrown |
| 677 | } catch (BuildFailedException e) { |
| 678 | List<Event> errors = ImmutableList.copyOf( |
| 679 | Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT)); |
| 680 | assertThat(errors).hasSize(2); |
| 681 | assertThat(errors.get(0).getMessage()).contains( |
| 682 | "A TreeArtifact may not contain relative symlinks whose target paths traverse " |
| 683 | + "outside of the TreeArtifact"); |
| 684 | assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid"); |
| 685 | } |
| 686 | } |
| 687 | |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 688 | // This is more a smoke test than anything, because it turns out that: |
| 689 | // 1) there is no easy way to turn fast digests on/off for these test cases, and |
| 690 | // 2) injectDigest() doesn't really complain if you inject bad digests or digests |
| 691 | // for nonexistent files. Instead some weird error shows up down the line. |
| 692 | // In fact, there are no tests for injectDigest anywhere in the codebase. |
| 693 | // So all we're really testing here is that injectDigest() doesn't throw a weird exception. |
| 694 | // TODO(bazel-team): write real tests for injectDigest, here and elsewhere. |
| 695 | @Test |
| 696 | public void testDigestInjection() throws Exception { |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 697 | TreeArtifactTestAction action = |
| 698 | new TreeArtifactTestAction(outOne) { |
| 699 | @Override |
| 700 | public ActionResult execute(ActionExecutionContext actionExecutionContext) |
| 701 | throws ActionExecutionException { |
| 702 | try { |
| 703 | writeFile(outOneFileOne, "one"); |
| 704 | writeFile(outOneFileTwo, "two"); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 705 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 706 | MetadataHandler md = actionExecutionContext.getMetadataHandler(); |
| 707 | FileStatus stat = outOneFileOne.getPath().stat(Symlinks.NOFOLLOW); |
| 708 | md.injectDigest( |
| 709 | outOneFileOne, |
| 710 | stat, |
| 711 | Hashing.md5().hashString("one", Charset.forName("UTF-8")).asBytes()); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 712 | |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 713 | stat = outOneFileTwo.getPath().stat(Symlinks.NOFOLLOW); |
| 714 | md.injectDigest( |
| 715 | outOneFileTwo, |
| 716 | stat, |
| 717 | Hashing.md5().hashString("two", Charset.forName("UTF-8")).asBytes()); |
| 718 | } catch (Exception e) { |
| 719 | throw new RuntimeException(e); |
| 720 | } |
| 721 | return ActionResult.EMPTY; |
| 722 | } |
| 723 | }; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 724 | |
| 725 | registerAction(action); |
| 726 | buildArtifact(action.getSoleOutput()); |
| 727 | } |
| 728 | |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 729 | @Test |
| 730 | public void testExpandedActionsBuildInActionTemplate() throws Throwable { |
| 731 | // artifact1 is a tree artifact generated by a TouchingTestAction. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 732 | SpecialArtifact artifact1 = createTreeArtifact("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 733 | TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 734 | artifact1, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 735 | TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 736 | artifact1, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 737 | registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB)); |
| 738 | |
| 739 | // artifact2 is a tree artifact generated by an action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 740 | SpecialArtifact artifact2 = createTreeArtifact("treeArtifact2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 741 | SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate( |
| 742 | artifact1, artifact2); |
| 743 | registerAction(actionTemplate); |
| 744 | |
| 745 | // We mock out the action template function to expand into two actions that just touch the |
| 746 | // output files. |
| 747 | TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 748 | artifact2, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 749 | TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 750 | artifact2, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 751 | Action generateOutputAction = new DummyAction( |
| 752 | ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1); |
| 753 | Action noGenerateOutputAction = new DummyAction( |
| 754 | ImmutableList.<Artifact>of(treeFileArtifactB), expectedOutputTreeFileArtifact2); |
| 755 | |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 756 | actionTemplateExpansionFunction = |
| 757 | new DummyActionTemplateExpansionFunction( |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 758 | actionKeyContext, ImmutableList.of(generateOutputAction, noGenerateOutputAction)); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 759 | |
| 760 | buildArtifact(artifact2); |
| 761 | } |
| 762 | |
| 763 | @Test |
| 764 | public void testExpandedActionDoesNotGenerateOutputInActionTemplate() throws Throwable { |
| 765 | // expect errors |
| 766 | reporter.removeHandler(failFastHandler); |
| 767 | |
| 768 | // artifact1 is a tree artifact generated by a TouchingTestAction. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 769 | SpecialArtifact artifact1 = createTreeArtifact("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 770 | TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 771 | artifact1, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 772 | TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 773 | artifact1, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 774 | registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB)); |
| 775 | |
| 776 | // artifact2 is a tree artifact generated by an action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 777 | SpecialArtifact artifact2 = createTreeArtifact("treeArtifact2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 778 | SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate( |
| 779 | artifact1, artifact2); |
| 780 | registerAction(actionTemplate); |
| 781 | |
| 782 | // We mock out the action template function to expand into two actions: |
| 783 | // One Action that touches the output file. |
| 784 | // The other action that does not generate the output file. |
| 785 | TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 786 | artifact2, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 787 | TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 788 | artifact2, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 789 | Action generateOutputAction = new DummyAction( |
| 790 | ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1); |
| 791 | Action noGenerateOutputAction = new NoOpDummyAction( |
| 792 | ImmutableList.<Artifact>of(treeFileArtifactB), |
| 793 | ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2)); |
| 794 | |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 795 | actionTemplateExpansionFunction = |
| 796 | new DummyActionTemplateExpansionFunction( |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 797 | actionKeyContext, ImmutableList.of(generateOutputAction, noGenerateOutputAction)); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 798 | |
| 799 | try { |
| 800 | buildArtifact(artifact2); |
| 801 | fail("Expected BuildFailedException"); |
| 802 | } catch (BuildFailedException e) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 803 | assertThat(e).hasMessageThat().contains("not all outputs were created or valid"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
| 807 | @Test |
| 808 | public void testOneExpandedActionThrowsInActionTemplate() throws Throwable { |
| 809 | // expect errors |
| 810 | reporter.removeHandler(failFastHandler); |
| 811 | |
| 812 | // artifact1 is a tree artifact generated by a TouchingTestAction. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 813 | SpecialArtifact artifact1 = createTreeArtifact("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 814 | TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 815 | artifact1, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 816 | TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 817 | artifact1, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 818 | registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB)); |
| 819 | |
| 820 | // artifact2 is a tree artifact generated by an action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 821 | SpecialArtifact artifact2 = createTreeArtifact("treeArtifact2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 822 | SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate( |
| 823 | artifact1, artifact2); |
| 824 | registerAction(actionTemplate); |
| 825 | |
| 826 | // We mock out the action template function to expand into two actions: |
| 827 | // One Action that touches the output file. |
| 828 | // The other action that just throws when executed. |
| 829 | TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 830 | artifact2, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 831 | TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 832 | artifact2, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 833 | Action generateOutputAction = new DummyAction( |
| 834 | ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1); |
| 835 | Action throwingAction = new ThrowingDummyAction( |
| 836 | ImmutableList.<Artifact>of(treeFileArtifactB), |
| 837 | ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2)); |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 838 | |
| 839 | actionTemplateExpansionFunction = |
| 840 | new DummyActionTemplateExpansionFunction( |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 841 | actionKeyContext, ImmutableList.of(generateOutputAction, throwingAction)); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 842 | |
| 843 | try { |
| 844 | buildArtifact(artifact2); |
| 845 | fail("Expected BuildFailedException"); |
| 846 | } catch (BuildFailedException e) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 847 | assertThat(e).hasMessageThat().contains("Throwing dummy action"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
| 851 | @Test |
| 852 | public void testAllExpandedActionsThrowInActionTemplate() throws Throwable { |
| 853 | // expect errors |
| 854 | reporter.removeHandler(failFastHandler); |
| 855 | |
| 856 | // artifact1 is a tree artifact generated by a TouchingTestAction. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 857 | SpecialArtifact artifact1 = createTreeArtifact("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 858 | TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 859 | artifact1, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 860 | TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 861 | artifact1, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 862 | registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB)); |
| 863 | |
| 864 | // artifact2 is a tree artifact generated by an action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 865 | SpecialArtifact artifact2 = createTreeArtifact("treeArtifact2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 866 | SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate( |
| 867 | artifact1, artifact2); |
| 868 | registerAction(actionTemplate); |
| 869 | |
| 870 | // We mock out the action template function to expand into two actions that throw when executed. |
| 871 | TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 872 | artifact2, PathFragment.create("child1")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 873 | TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 874 | artifact2, PathFragment.create("child2")); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 875 | Action throwingAction = new ThrowingDummyAction( |
| 876 | ImmutableList.<Artifact>of(treeFileArtifactA), |
| 877 | ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact1)); |
| 878 | Action anotherThrowingAction = new ThrowingDummyAction( |
| 879 | ImmutableList.<Artifact>of(treeFileArtifactB), |
| 880 | ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2)); |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 881 | |
| 882 | actionTemplateExpansionFunction = |
| 883 | new DummyActionTemplateExpansionFunction( |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 884 | actionKeyContext, ImmutableList.of(throwingAction, anotherThrowingAction)); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 885 | |
| 886 | try { |
| 887 | buildArtifact(artifact2); |
| 888 | fail("Expected BuildFailedException"); |
| 889 | } catch (BuildFailedException e) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 890 | assertThat(e).hasMessageThat().contains("Throwing dummy action"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
| 894 | @Test |
| 895 | public void testInputTreeArtifactCreationFailedInActionTemplate() throws Throwable { |
| 896 | // expect errors |
| 897 | reporter.removeHandler(failFastHandler); |
| 898 | |
| 899 | // artifact1 is created by a action that throws. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 900 | SpecialArtifact artifact1 = createTreeArtifact("treeArtifact1"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 901 | registerAction( |
| 902 | new ThrowingDummyAction(ImmutableList.<Artifact>of(), ImmutableList.of(artifact1))); |
| 903 | |
| 904 | // artifact2 is a tree artifact generated by an action template. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 905 | SpecialArtifact artifact2 = createTreeArtifact("treeArtifact2"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 906 | SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate( |
| 907 | artifact1, artifact2); |
| 908 | registerAction(actionTemplate); |
| 909 | |
| 910 | try { |
| 911 | buildArtifact(artifact2); |
| 912 | fail("Expected BuildFailedException"); |
| 913 | } catch (BuildFailedException e) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 914 | assertThat(e).hasMessageThat().contains("Throwing dummy action"); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
Rumou Duan | 3ddb4c9 | 2016-06-13 20:10:48 +0000 | [diff] [blame] | 918 | @Test |
| 919 | public void testEmptyInputAndOutputTreeArtifactInActionTemplate() throws Throwable { |
| 920 | // artifact1 is an empty tree artifact which is generated by a single no-op dummy action. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 921 | SpecialArtifact artifact1 = createTreeArtifact("treeArtifact1"); |
Rumou Duan | 3ddb4c9 | 2016-06-13 20:10:48 +0000 | [diff] [blame] | 922 | registerAction(new NoOpDummyAction(ImmutableList.<Artifact>of(), ImmutableList.of(artifact1))); |
| 923 | |
| 924 | // artifact2 is a tree artifact generated by an action template that takes artifact1 as input. |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 925 | SpecialArtifact artifact2 = createTreeArtifact("treeArtifact2"); |
Rumou Duan | 3ddb4c9 | 2016-06-13 20:10:48 +0000 | [diff] [blame] | 926 | SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate( |
| 927 | artifact1, artifact2); |
| 928 | registerAction(actionTemplate); |
| 929 | |
| 930 | buildArtifact(artifact2); |
| 931 | |
| 932 | assertThat(artifact1.getPath().exists()).isTrue(); |
| 933 | assertThat(artifact1.getPath().getDirectoryEntries()).isEmpty(); |
| 934 | assertThat(artifact2.getPath().exists()).isTrue(); |
| 935 | assertThat(artifact2.getPath().getDirectoryEntries()).isEmpty(); |
| 936 | } |
| 937 | |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 938 | /** |
| 939 | * A generic test action that takes at most one input TreeArtifact, |
| 940 | * exactly one output TreeArtifact, and some path fragment inputs/outputs. |
| 941 | */ |
| 942 | private abstract static class TreeArtifactTestAction extends TestAction { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 943 | final Iterable<TreeFileArtifact> inputFiles; |
| 944 | final Iterable<TreeFileArtifact> outputFiles; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 945 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 946 | TreeArtifactTestAction(final SpecialArtifact output, final String... subOutputs) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 947 | this(Runnables.doNothing(), |
| 948 | null, |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 949 | ImmutableList.<TreeFileArtifact>of(), |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 950 | output, |
| 951 | Collections2.transform( |
| 952 | Arrays.asList(subOutputs), |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 953 | new Function<String, TreeFileArtifact>() { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 954 | @Nullable |
| 955 | @Override |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 956 | public TreeFileArtifact apply(String s) { |
| 957 | return ActionInputHelper.treeFileArtifact(output, s); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 958 | } |
| 959 | })); |
| 960 | } |
| 961 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 962 | TreeArtifactTestAction(Runnable effect, TreeFileArtifact... outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 963 | this(effect, Arrays.asList(outputFiles)); |
| 964 | } |
| 965 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 966 | TreeArtifactTestAction(Runnable effect, Collection<TreeFileArtifact> outputFiles) { |
| 967 | this(effect, null, ImmutableList.<TreeFileArtifact>of(), |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 968 | outputFiles.iterator().next().getParent(), outputFiles); |
| 969 | } |
| 970 | |
| 971 | TreeArtifactTestAction(Runnable effect, Artifact inputFile, |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 972 | Collection<TreeFileArtifact> outputFiles) { |
| 973 | this(effect, inputFile, ImmutableList.<TreeFileArtifact>of(), |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 974 | outputFiles.iterator().next().getParent(), outputFiles); |
| 975 | } |
| 976 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 977 | TreeArtifactTestAction(Runnable effect, Collection<TreeFileArtifact> inputFiles, |
| 978 | Collection<TreeFileArtifact> outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 979 | this(effect, inputFiles.iterator().next().getParent(), inputFiles, |
| 980 | outputFiles.iterator().next().getParent(), outputFiles); |
| 981 | } |
| 982 | |
| 983 | TreeArtifactTestAction( |
| 984 | Runnable effect, |
| 985 | @Nullable Artifact input, |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 986 | Collection<TreeFileArtifact> inputFiles, |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 987 | Artifact output, |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 988 | Collection<TreeFileArtifact> outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 989 | super(effect, |
| 990 | input == null ? ImmutableList.<Artifact>of() : ImmutableList.of(input), |
| 991 | ImmutableList.of(output)); |
| 992 | Preconditions.checkArgument( |
| 993 | inputFiles.isEmpty() || (input != null && input.isTreeArtifact())); |
| 994 | Preconditions.checkArgument(output == null || output.isTreeArtifact()); |
| 995 | this.inputFiles = ImmutableList.copyOf(inputFiles); |
| 996 | this.outputFiles = ImmutableList.copyOf(outputFiles); |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 997 | for (TreeFileArtifact inputFile : inputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 998 | Preconditions.checkState(inputFile.getParent().equals(input)); |
| 999 | } |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1000 | for (TreeFileArtifact outputFile : outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1001 | Preconditions.checkState(outputFile.getParent().equals(output)); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | @Override |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 1006 | public ActionResult execute(ActionExecutionContext actionExecutionContext) |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1007 | throws ActionExecutionException { |
| 1008 | if (getInputs().iterator().hasNext()) { |
| 1009 | // Sanity check--verify all inputs exist. |
| 1010 | Artifact input = getSoleInput(); |
| 1011 | if (!input.getPath().exists()) { |
| 1012 | throw new IllegalStateException("action's input Artifact does not exist: " |
| 1013 | + input.getPath()); |
| 1014 | } |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1015 | for (Artifact inputFile : inputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1016 | if (!inputFile.getPath().exists()) { |
| 1017 | throw new IllegalStateException("action's input does not exist: " + inputFile); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | Artifact output = getSoleOutput(); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 1023 | assertThat(output.getPath().exists()).isTrue(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1024 | try { |
| 1025 | effect.call(); |
| 1026 | executeTestBehavior(actionExecutionContext); |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1027 | for (TreeFileArtifact outputFile : outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1028 | actionExecutionContext.getMetadataHandler().addExpandedTreeOutput(outputFile); |
| 1029 | } |
| 1030 | } catch (RuntimeException e) { |
| 1031 | throw new RuntimeException(e); |
| 1032 | } catch (Exception e) { |
| 1033 | throw new ActionExecutionException("TestAction failed due to exception", |
| 1034 | e, this, false); |
| 1035 | } |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 1036 | return ActionResult.EMPTY; |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | void executeTestBehavior(ActionExecutionContext c) throws ActionExecutionException { |
| 1040 | // Default: do nothing |
| 1041 | } |
| 1042 | |
| 1043 | /** Checks there's exactly one input, and returns it. */ |
| 1044 | // This prevents us from making testing mistakes, like |
| 1045 | // assuming there's only one input when this isn't actually true. |
| 1046 | Artifact getSoleInput() { |
| 1047 | Iterator<Artifact> it = getInputs().iterator(); |
| 1048 | Artifact r = it.next(); |
| 1049 | Preconditions.checkNotNull(r); |
| 1050 | Preconditions.checkState(!it.hasNext()); |
| 1051 | return r; |
| 1052 | } |
| 1053 | |
| 1054 | /** Checks there's exactly one output, and returns it. */ |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 1055 | SpecialArtifact getSoleOutput() { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1056 | Iterator<Artifact> it = getOutputs().iterator(); |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 1057 | SpecialArtifact r = (SpecialArtifact) it.next(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1058 | Preconditions.checkNotNull(r); |
| 1059 | Preconditions.checkState(!it.hasNext()); |
| 1060 | Preconditions.checkState(r.equals(getPrimaryOutput())); |
| 1061 | return r; |
| 1062 | } |
| 1063 | |
| 1064 | void registerOutput(ActionExecutionContext context, String outputName) throws IOException { |
| 1065 | context.getMetadataHandler().addExpandedTreeOutput( |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 1066 | treeFileArtifact(getSoleOutput(), PathFragment.create(outputName))); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 1069 | static List<TreeFileArtifact> asTreeFileArtifacts( |
| 1070 | final SpecialArtifact parent, String... files) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1071 | return Lists.transform( |
| 1072 | Arrays.asList(files), |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1073 | new Function<String, TreeFileArtifact>() { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1074 | @Nullable |
| 1075 | @Override |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1076 | public TreeFileArtifact apply(String s) { |
| 1077 | return ActionInputHelper.treeFileArtifact(parent, s); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1078 | } |
| 1079 | }); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1083 | /** An action that touches some output TreeFileArtifacts. Takes no inputs. */ |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1084 | private static class TouchingTestAction extends TreeArtifactTestAction { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1085 | TouchingTestAction(TreeFileArtifact... outputPaths) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1086 | super(Runnables.doNothing(), outputPaths); |
| 1087 | } |
| 1088 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 1089 | TouchingTestAction(Runnable effect, SpecialArtifact output, String... outputPaths) { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1090 | super(effect, asTreeFileArtifacts(output, outputPaths)); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | @Override |
| 1094 | public void executeTestBehavior(ActionExecutionContext actionExecutionContext) |
| 1095 | throws ActionExecutionException { |
| 1096 | try { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1097 | for (Artifact file : outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1098 | touchFile(file); |
| 1099 | } |
| 1100 | } catch (IOException e) { |
| 1101 | throw new RuntimeException(e); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | /** Takes an input file and populates several copies inside a TreeArtifact. */ |
| 1107 | private static class WriteInputToFilesAction extends TreeArtifactTestAction { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1108 | WriteInputToFilesAction(Artifact input, TreeFileArtifact... outputs) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1109 | this(Runnables.doNothing(), input, outputs); |
| 1110 | } |
| 1111 | |
| 1112 | WriteInputToFilesAction( |
| 1113 | Runnable effect, |
| 1114 | Artifact input, |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1115 | TreeFileArtifact... outputs) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1116 | super(effect, input, Arrays.asList(outputs)); |
| 1117 | Preconditions.checkArgument(!input.isTreeArtifact()); |
| 1118 | } |
| 1119 | |
| 1120 | @Override |
| 1121 | public void executeTestBehavior(ActionExecutionContext actionExecutionContext) |
| 1122 | throws ActionExecutionException { |
| 1123 | try { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1124 | for (Artifact file : outputFiles) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1125 | FileSystemUtils.createDirectoryAndParents(file.getPath().getParentDirectory()); |
| 1126 | FileSystemUtils.copyFile(getSoleInput().getPath(), file.getPath()); |
| 1127 | } |
| 1128 | } catch (IOException e) { |
| 1129 | throw new RuntimeException(e); |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1134 | /** Copies the given TreeFileArtifact inputs to the given outputs, in respective order. */ |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1135 | private static class CopyTreeAction extends TreeArtifactTestAction { |
| 1136 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 1137 | CopyTreeAction( |
| 1138 | Runnable effect, SpecialArtifact input, SpecialArtifact output, String... sourcesAndDests) { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1139 | super(effect, input, asTreeFileArtifacts(input, sourcesAndDests), output, |
| 1140 | asTreeFileArtifacts(output, sourcesAndDests)); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | CopyTreeAction( |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1144 | Collection<TreeFileArtifact> inputPaths, |
| 1145 | Collection<TreeFileArtifact> outputPaths) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1146 | super(Runnables.doNothing(), inputPaths, outputPaths); |
| 1147 | } |
| 1148 | |
| 1149 | CopyTreeAction( |
| 1150 | Runnable effect, |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1151 | Collection<TreeFileArtifact> inputPaths, |
| 1152 | Collection<TreeFileArtifact> outputPaths) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1153 | super(effect, inputPaths, outputPaths); |
| 1154 | } |
| 1155 | |
| 1156 | @Override |
| 1157 | public void executeTestBehavior(ActionExecutionContext actionExecutionContext) |
| 1158 | throws ActionExecutionException { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1159 | Iterator<TreeFileArtifact> inputIterator = inputFiles.iterator(); |
| 1160 | Iterator<TreeFileArtifact> outputIterator = outputFiles.iterator(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1161 | |
| 1162 | try { |
| 1163 | while (inputIterator.hasNext() || outputIterator.hasNext()) { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1164 | Artifact input = inputIterator.next(); |
| 1165 | Artifact output = outputIterator.next(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1166 | FileSystemUtils.createDirectoryAndParents(output.getPath().getParentDirectory()); |
| 1167 | FileSystemUtils.copyFile(input.getPath(), output.getPath()); |
| 1168 | } |
| 1169 | } catch (IOException e) { |
| 1170 | throw new RuntimeException(e); |
| 1171 | } |
| 1172 | |
| 1173 | // both iterators must be of the same size |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 1174 | assertThat(inputIterator.hasNext()).isFalse(); |
| 1175 | assertThat(inputIterator.hasNext()).isFalse(); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 1179 | private SpecialArtifact createTreeArtifact(String name) { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1180 | FileSystem fs = scratch.getFileSystem(); |
| 1181 | Path execRoot = fs.getPath(TestUtils.tmpDir()); |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 1182 | PathFragment execPath = PathFragment.create("out").getRelative(name); |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1183 | return new SpecialArtifact( |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 1184 | ArtifactRoot.asDerivedRoot(execRoot, execRoot.getRelative("out")), |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 1185 | execPath, |
| 1186 | ACTION_LOOKUP_KEY, |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1187 | SpecialArtifactType.TREE); |
| 1188 | } |
| 1189 | |
Ulf Adams | 94f6330 | 2016-04-29 15:04:13 +0000 | [diff] [blame] | 1190 | private void buildArtifact(Artifact artifact) throws Exception { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1191 | buildArtifacts(cachingBuilder(), artifact); |
| 1192 | } |
| 1193 | |
| 1194 | private static void writeFile(Path path, String contents) throws IOException { |
| 1195 | FileSystemUtils.createDirectoryAndParents(path.getParentDirectory()); |
| 1196 | // sometimes we write read-only files |
| 1197 | if (path.exists()) { |
| 1198 | path.setWritable(true); |
| 1199 | } |
| 1200 | FileSystemUtils.writeContentAsLatin1(path, contents); |
| 1201 | } |
| 1202 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1203 | private static void writeFile(Artifact file, String contents) throws IOException { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1204 | writeFile(file.getPath(), contents); |
| 1205 | } |
| 1206 | |
| 1207 | private static void touchFile(Path path) throws IOException { |
| 1208 | FileSystemUtils.createDirectoryAndParents(path.getParentDirectory()); |
| 1209 | path.getParentDirectory().setWritable(true); |
| 1210 | FileSystemUtils.touchFile(path); |
| 1211 | } |
| 1212 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1213 | private static void touchFile(Artifact file) throws IOException { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1214 | touchFile(file.getPath()); |
| 1215 | } |
| 1216 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 1217 | private static void deleteFile(Artifact file) throws IOException { |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1218 | Path path = file.getPath(); |
| 1219 | // sometimes we write read-only files |
| 1220 | if (path.exists()) { |
| 1221 | path.setWritable(true); |
| 1222 | // work around the sticky bit (this might depend on the behavior of the OS?) |
| 1223 | path.getParentDirectory().setWritable(true); |
| 1224 | path.delete(); |
| 1225 | } |
| 1226 | } |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1227 | |
| 1228 | /** A dummy action template expansion function that just returns the injected actions */ |
| 1229 | private static class DummyActionTemplateExpansionFunction implements SkyFunction { |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 1230 | private final ActionKeyContext actionKeyContext; |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 1231 | private final ImmutableList<ActionAnalysisMetadata> actions; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1232 | |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 1233 | DummyActionTemplateExpansionFunction( |
| 1234 | ActionKeyContext actionKeyContext, ImmutableList<ActionAnalysisMetadata> actions) { |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 1235 | this.actionKeyContext = actionKeyContext; |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 1236 | this.actions = actions; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | @Override |
| 1240 | public SkyValue compute(SkyKey skyKey, Environment env) { |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 1241 | try { |
| 1242 | return new ActionTemplateExpansionValue( |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 1243 | Actions.filterSharedActionsAndThrowActionConflict(actionKeyContext, actions)); |
janakr | 0175ce3 | 2018-02-26 15:54:57 -0800 | [diff] [blame] | 1244 | } catch (ActionConflictException e) { |
| 1245 | throw new IllegalStateException(e); |
| 1246 | } |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | @Override |
| 1250 | public String extractTag(SkyKey skyKey) { |
| 1251 | return null; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | /** No-op action that does not generate the action outputs. */ |
| 1256 | private static class NoOpDummyAction extends TestAction { |
| 1257 | public NoOpDummyAction(Collection<Artifact> inputs, Collection<Artifact> outputs) { |
| 1258 | super(NO_EFFECT, inputs, outputs); |
| 1259 | } |
| 1260 | |
| 1261 | /** Do nothing */ |
| 1262 | @Override |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 1263 | public ActionResult execute(ActionExecutionContext actionExecutionContext) |
| 1264 | throws ActionExecutionException { |
| 1265 | return ActionResult.EMPTY; |
| 1266 | } |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /** No-op action that throws when executed */ |
| 1270 | private static class ThrowingDummyAction extends TestAction { |
| 1271 | public ThrowingDummyAction(Collection<Artifact> inputs, Collection<Artifact> outputs) { |
| 1272 | super(NO_EFFECT, inputs, outputs); |
| 1273 | } |
| 1274 | |
| 1275 | /** Throws */ |
| 1276 | @Override |
ruperts | 841880d | 2017-10-18 00:58:29 +0200 | [diff] [blame] | 1277 | public ActionResult execute(ActionExecutionContext actionExecutionContext) |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1278 | throws ActionExecutionException { |
| 1279 | throw new ActionExecutionException("Throwing dummy action", this, true); |
| 1280 | } |
| 1281 | } |
Googler | ece7572 | 2016-02-11 17:55:41 +0000 | [diff] [blame] | 1282 | } |