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; |
| 15 | |
| 16 | import static com.google.common.truth.Truth.assertThat; |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 17 | import static com.google.common.truth.Truth.assertWithMessage; |
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 | |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import com.google.common.collect.ImmutableMap; |
| 22 | import com.google.common.collect.ImmutableSet; |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 23 | import com.google.common.hash.HashCode; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 24 | import com.google.common.util.concurrent.Runnables; |
| 25 | import com.google.devtools.build.lib.actions.Action; |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 26 | import com.google.devtools.build.lib.actions.ActionLookupData; |
janakr | 93e3eea | 2017-03-30 22:09:37 +0000 | [diff] [blame] | 27 | import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 28 | import com.google.devtools.build.lib.actions.Artifact; |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 29 | import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 30 | import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 31 | import com.google.devtools.build.lib.actions.ArtifactRoot; |
shahan | 602cc85 | 2018-06-06 20:09:57 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.actions.FileArtifactValue; |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 33 | import com.google.devtools.build.lib.actions.FileArtifactValue.RemoteFileArtifactValue; |
shahan | 602cc85 | 2018-06-06 20:09:57 -0700 | [diff] [blame] | 34 | import com.google.devtools.build.lib.actions.FileStateValue; |
| 35 | import com.google.devtools.build.lib.actions.FileValue; |
janakr | aea0560 | 2019-05-22 15:41:29 -0700 | [diff] [blame] | 36 | import com.google.devtools.build.lib.actions.util.ActionsTestUtil; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 37 | import com.google.devtools.build.lib.actions.util.TestAction; |
Kristina Chodorow | f9fdc8d | 2015-12-08 12:49:31 +0000 | [diff] [blame] | 38 | import com.google.devtools.build.lib.analysis.BlazeDirectories; |
janakr | 3b63a4e | 2017-09-14 09:55:40 +0200 | [diff] [blame] | 39 | import com.google.devtools.build.lib.analysis.ServerDirectories; |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 40 | import com.google.devtools.build.lib.clock.BlazeClock; |
Kristina Chodorow | f9fdc8d | 2015-12-08 12:49:31 +0000 | [diff] [blame] | 41 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 42 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 43 | import com.google.devtools.build.lib.collect.nestedset.Order; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 44 | import com.google.devtools.build.lib.events.NullEventHandler; |
janakr | 15e15c2 | 2019-01-30 11:24:49 -0800 | [diff] [blame] | 45 | import com.google.devtools.build.lib.packages.WorkspaceFileValue; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 46 | import com.google.devtools.build.lib.pkgcache.PathPackageLocator; |
| 47 | import com.google.devtools.build.lib.skyframe.DirtinessCheckerUtils.BasicFilesystemDirtinessChecker; |
Nathan Harmata | d4f7594 | 2016-10-18 08:55:17 +0000 | [diff] [blame] | 48 | import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction; |
John Cater | 5e9ce94 | 2016-10-12 17:23:30 +0000 | [diff] [blame] | 49 | import com.google.devtools.build.lib.skyframe.PackageLookupFunction.CrossRepositoryLabelViolationStrategy; |
Luis Fernando Pino Duque | be10218 | 2016-05-23 14:03:55 +0000 | [diff] [blame] | 50 | import com.google.devtools.build.lib.testutil.TestConstants; |
michajlo | 8083e32 | 2020-03-20 13:32:52 -0700 | [diff] [blame] | 51 | import com.google.devtools.build.lib.testutil.TestPackageFactoryBuilderFactory; |
Kristina Chodorow | f9fdc8d | 2015-12-08 12:49:31 +0000 | [diff] [blame] | 52 | import com.google.devtools.build.lib.testutil.TestRuleClassProvider; |
laszlocsomor | 29bdf63 | 2018-03-13 02:50:46 -0700 | [diff] [blame] | 53 | import com.google.devtools.build.lib.testutil.TimestampGranularityUtils; |
Laszlo Csomor | a278aec | 2018-03-09 04:07:31 -0800 | [diff] [blame] | 54 | import com.google.devtools.build.lib.util.io.OutErr; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 55 | import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; |
| 56 | import com.google.devtools.build.lib.vfs.BatchStat; |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 57 | import com.google.devtools.build.lib.vfs.DigestHashFunction; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 58 | import com.google.devtools.build.lib.vfs.FileStatus; |
| 59 | import com.google.devtools.build.lib.vfs.FileStatusWithDigest; |
| 60 | import com.google.devtools.build.lib.vfs.FileStatusWithDigestAdapter; |
| 61 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
Eric Fellheimer | e659072 | 2015-11-17 17:07:48 +0000 | [diff] [blame] | 62 | import com.google.devtools.build.lib.vfs.ModifiedFileSet; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 63 | import com.google.devtools.build.lib.vfs.Path; |
| 64 | import com.google.devtools.build.lib.vfs.PathFragment; |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 65 | import com.google.devtools.build.lib.vfs.Root; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 66 | import com.google.devtools.build.lib.vfs.RootedPath; |
| 67 | import com.google.devtools.build.lib.vfs.Symlinks; |
djasper | 7faa0ef | 2019-03-28 10:00:00 -0700 | [diff] [blame] | 68 | import com.google.devtools.build.lib.vfs.UnixGlob; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 69 | import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; |
| 70 | import com.google.devtools.build.skyframe.Differencer.Diff; |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 71 | import com.google.devtools.build.skyframe.EvaluationContext; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 72 | import com.google.devtools.build.skyframe.EvaluationResult; |
| 73 | import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; |
| 74 | import com.google.devtools.build.skyframe.MemoizingEvaluator; |
| 75 | import com.google.devtools.build.skyframe.RecordingDifferencer; |
janakr | 1cde872 | 2017-10-10 03:22:21 +0200 | [diff] [blame] | 76 | import com.google.devtools.build.skyframe.SequencedRecordingDifferencer; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 77 | import com.google.devtools.build.skyframe.SequentialBuildDriver; |
| 78 | import com.google.devtools.build.skyframe.SkyFunction; |
| 79 | import com.google.devtools.build.skyframe.SkyFunctionName; |
| 80 | import com.google.devtools.build.skyframe.SkyKey; |
| 81 | import com.google.devtools.build.skyframe.SkyValue; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 82 | import java.io.IOException; |
| 83 | import java.util.ArrayList; |
| 84 | import java.util.Arrays; |
| 85 | import java.util.Collection; |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 86 | import java.util.Collections; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 87 | import java.util.HashMap; |
| 88 | import java.util.List; |
| 89 | import java.util.Map; |
| 90 | import java.util.UUID; |
| 91 | import java.util.concurrent.atomic.AtomicReference; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 92 | import javax.annotation.Nullable; |
Janak Ramakrishnan | cba1645 | 2016-07-29 02:17:02 +0000 | [diff] [blame] | 93 | import org.junit.Before; |
steinman | 7184cb3 | 2020-04-20 14:33:03 -0700 | [diff] [blame] | 94 | import org.junit.Ignore; |
Janak Ramakrishnan | cba1645 | 2016-07-29 02:17:02 +0000 | [diff] [blame] | 95 | import org.junit.Test; |
| 96 | import org.junit.runner.RunWith; |
| 97 | import org.junit.runners.JUnit4; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * Tests for {@link FilesystemValueChecker}. |
| 101 | */ |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 102 | @RunWith(JUnit4.class) |
| 103 | public class FilesystemValueCheckerTest { |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 104 | private static final EvaluationContext EVALUATION_OPTIONS = |
| 105 | EvaluationContext.newBuilder() |
| 106 | .setKeepGoing(false) |
| 107 | .setNumThreads(SkyframeExecutor.DEFAULT_THREAD_COUNT) |
| 108 | .setEventHander(NullEventHandler.INSTANCE) |
| 109 | .build(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 110 | |
| 111 | private RecordingDifferencer differencer; |
| 112 | private MemoizingEvaluator evaluator; |
| 113 | private SequentialBuildDriver driver; |
| 114 | private MockFileSystem fs; |
| 115 | private Path pkgRoot; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 116 | |
twerth | 1fa34df | 2020-04-09 03:21:02 -0700 | [diff] [blame] | 117 | private static final int FSVC_THREADS_FOR_TEST = 200; |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 118 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 119 | @Before |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 120 | public final void setUp() throws Exception { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 121 | ImmutableMap.Builder<SkyFunctionName, SkyFunction> skyFunctions = ImmutableMap.builder(); |
| 122 | |
| 123 | fs = new MockFileSystem(); |
| 124 | pkgRoot = fs.getPath("/testroot"); |
Kristina Chodorow | f9fdc8d | 2015-12-08 12:49:31 +0000 | [diff] [blame] | 125 | FileSystemUtils.createDirectoryAndParents(pkgRoot); |
| 126 | FileSystemUtils.createEmptyFile(pkgRoot.getRelative("WORKSPACE")); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 127 | |
John Cater | e0d1d0e | 2017-11-28 20:47:41 -0800 | [diff] [blame] | 128 | AtomicReference<PathPackageLocator> pkgLocator = |
| 129 | new AtomicReference<>( |
| 130 | new PathPackageLocator( |
| 131 | fs.getPath("/output_base"), |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 132 | ImmutableList.of(Root.fromPath(pkgRoot)), |
John Cater | e0d1d0e | 2017-11-28 20:47:41 -0800 | [diff] [blame] | 133 | BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); |
janakr | 3b63a4e | 2017-09-14 09:55:40 +0200 | [diff] [blame] | 134 | BlazeDirectories directories = |
| 135 | new BlazeDirectories( |
cushon | 849df36 | 2018-05-14 01:51:45 -0700 | [diff] [blame] | 136 | new ServerDirectories(pkgRoot, pkgRoot, pkgRoot), |
| 137 | pkgRoot, |
| 138 | /* defaultSystemJavabase= */ null, |
| 139 | TestConstants.PRODUCT_NAME); |
nharmata | 3fb7d34 | 2018-02-23 11:37:51 -0800 | [diff] [blame] | 140 | ExternalFilesHelper externalFilesHelper = ExternalFilesHelper.createForTesting( |
Nathan Harmata | d4f7594 | 2016-10-18 08:55:17 +0000 | [diff] [blame] | 141 | pkgLocator, ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS, directories); |
shahan | 602cc85 | 2018-06-06 20:09:57 -0700 | [diff] [blame] | 142 | skyFunctions.put( |
| 143 | FileStateValue.FILE_STATE, |
| 144 | new FileStateFunction( |
djasper | 7faa0ef | 2019-03-28 10:00:00 -0700 | [diff] [blame] | 145 | new AtomicReference<TimestampGranularityMonitor>(), |
| 146 | new AtomicReference<>(UnixGlob.DEFAULT_SYSCALLS), |
| 147 | externalFilesHelper)); |
shahan | 602cc85 | 2018-06-06 20:09:57 -0700 | [diff] [blame] | 148 | skyFunctions.put(FileValue.FILE, new FileFunction(pkgLocator)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 149 | skyFunctions.put( |
| 150 | SkyFunctions.FILE_SYMLINK_CYCLE_UNIQUENESS, new FileSymlinkCycleUniquenessFunction()); |
| 151 | skyFunctions.put( |
| 152 | SkyFunctions.FILE_SYMLINK_INFINITE_EXPANSION_UNIQUENESS, |
| 153 | new FileSymlinkInfiniteExpansionUniquenessFunction()); |
ajurkowski | 2018b87 | 2020-04-14 09:59:00 -0700 | [diff] [blame] | 154 | skyFunctions.put( |
| 155 | SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null, null)); |
John Cater | 5e9ce94 | 2016-10-12 17:23:30 +0000 | [diff] [blame] | 156 | skyFunctions.put( |
| 157 | SkyFunctions.PACKAGE_LOOKUP, |
| 158 | new PackageLookupFunction( |
| 159 | new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()), |
John Cater | 0c0735a | 2016-11-11 01:52:02 +0000 | [diff] [blame] | 160 | CrossRepositoryLabelViolationStrategy.ERROR, |
ajurkowski | 2018b87 | 2020-04-14 09:59:00 -0700 | [diff] [blame] | 161 | BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY, |
| 162 | BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER)); |
Damien Martin-Guillerez | 4ecfe51 | 2016-01-22 11:03:23 +0000 | [diff] [blame] | 163 | skyFunctions.put(SkyFunctions.WORKSPACE_AST, |
| 164 | new WorkspaceASTFunction(TestRuleClassProvider.getRuleClassProvider())); |
carmi | d6a9828 | 2018-03-13 19:19:16 -0700 | [diff] [blame] | 165 | skyFunctions.put( |
janakr | 15e15c2 | 2019-01-30 11:24:49 -0800 | [diff] [blame] | 166 | WorkspaceFileValue.WORKSPACE_FILE, |
carmi | d6a9828 | 2018-03-13 19:19:16 -0700 | [diff] [blame] | 167 | new WorkspaceFileFunction( |
| 168 | TestRuleClassProvider.getRuleClassProvider(), |
michajlo | 8083e32 | 2020-03-20 13:32:52 -0700 | [diff] [blame] | 169 | TestPackageFactoryBuilderFactory.getInstance() |
carmi | d6a9828 | 2018-03-13 19:19:16 -0700 | [diff] [blame] | 170 | .builder(directories) |
nharmata | fde0bd2f | 2018-12-21 10:17:56 -0800 | [diff] [blame] | 171 | .build(TestRuleClassProvider.getRuleClassProvider(), fs), |
mjhalupka | f0e4811 | 2019-01-14 13:01:56 -0800 | [diff] [blame] | 172 | directories, |
brandjon | 771a029 | 2020-05-26 12:04:16 -0700 | [diff] [blame] | 173 | /*bzlLoadFunctionForInlining=*/ null)); |
ajurkowski | 2018b87 | 2020-04-14 09:59:00 -0700 | [diff] [blame] | 174 | skyFunctions.put( |
| 175 | SkyFunctions.EXTERNAL_PACKAGE, |
| 176 | new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER)); |
Kristina Chodorow | f9fdc8d | 2015-12-08 12:49:31 +0000 | [diff] [blame] | 177 | |
janakr | 1cde872 | 2017-10-10 03:22:21 +0200 | [diff] [blame] | 178 | differencer = new SequencedRecordingDifferencer(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 179 | evaluator = new InMemoryMemoizingEvaluator(skyFunctions.build(), differencer); |
| 180 | driver = new SequentialBuildDriver(evaluator); |
| 181 | PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID()); |
Kristina Chodorow | f9fdc8d | 2015-12-08 12:49:31 +0000 | [diff] [blame] | 182 | PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get()); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 185 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 186 | public void testEmpty() throws Exception { |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 187 | FilesystemValueChecker checker = |
| 188 | new FilesystemValueChecker( |
| 189 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 190 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 193 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 194 | public void testSimple() throws Exception { |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 195 | FilesystemValueChecker checker = |
| 196 | new FilesystemValueChecker( |
| 197 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 198 | |
| 199 | Path path = fs.getPath("/foo"); |
| 200 | FileSystemUtils.createEmptyFile(path); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 201 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 202 | |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 203 | SkyKey skyKey = |
| 204 | FileStateValue.key( |
tomlu | 4c9fafd | 2018-01-18 10:29:11 -0800 | [diff] [blame] | 205 | RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 206 | EvaluationResult<SkyValue> result = |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 207 | driver.evaluate(ImmutableList.of(skyKey), EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 208 | assertThat(result.hasError()).isFalse(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 209 | |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 210 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 211 | |
| 212 | FileSystemUtils.writeContentAsLatin1(path, "hello"); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 213 | assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), skyKey); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 214 | |
| 215 | // The dirty bits are not reset until the FileValues are actually revalidated. |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 216 | assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), skyKey); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 217 | |
| 218 | differencer.invalidate(ImmutableList.of(skyKey)); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 219 | result = driver.evaluate(ImmutableList.of(skyKey), EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 220 | assertThat(result.hasError()).isFalse(); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 221 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Tests that an already-invalidated value can still be marked changed: symlink points at sym1. |
| 226 | * Invalidate symlink by changing sym1 from pointing at path to point to sym2. This only dirties |
| 227 | * (rather than changes) symlink because sym2 still points at path, so all symlink stats remain |
| 228 | * the same. Then do a null build, change sym1 back to point at path, and change symlink to not be |
| 229 | * a symlink anymore. The fact that it is not a symlink should be detected. |
| 230 | */ |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 231 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 232 | public void testDirtySymlink() throws Exception { |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 233 | FilesystemValueChecker checker = |
| 234 | new FilesystemValueChecker( |
| 235 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 236 | |
| 237 | Path path = fs.getPath("/foo"); |
| 238 | FileSystemUtils.writeContentAsLatin1(path, "foo contents"); |
| 239 | // We need the intermediate sym1 and sym2 so that we can dirty a child of symlink without |
| 240 | // actually changing the FileValue calculated for symlink (if we changed the contents of foo, |
Laszlo Csomor | a278aec | 2018-03-09 04:07:31 -0800 | [diff] [blame] | 241 | // the FileValue created for symlink would notice, since it stats foo). |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 242 | Path sym1 = fs.getPath("/sym1"); |
| 243 | Path sym2 = fs.getPath("/sym2"); |
| 244 | Path symlink = fs.getPath("/bar"); |
| 245 | FileSystemUtils.ensureSymbolicLink(symlink, sym1); |
| 246 | FileSystemUtils.ensureSymbolicLink(sym1, path); |
| 247 | FileSystemUtils.ensureSymbolicLink(sym2, path); |
| 248 | SkyKey fooKey = |
tomlu | 4c9fafd | 2018-01-18 10:29:11 -0800 | [diff] [blame] | 249 | FileValue.key(RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 250 | RootedPath symlinkRootedPath = |
tomlu | 4c9fafd | 2018-01-18 10:29:11 -0800 | [diff] [blame] | 251 | RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/bar")); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 252 | SkyKey symlinkKey = FileValue.key(symlinkRootedPath); |
| 253 | SkyKey symlinkFileStateKey = FileStateValue.key(symlinkRootedPath); |
| 254 | RootedPath sym1RootedPath = |
tomlu | 4c9fafd | 2018-01-18 10:29:11 -0800 | [diff] [blame] | 255 | RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/sym1")); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 256 | SkyKey sym1FileStateKey = FileStateValue.key(sym1RootedPath); |
| 257 | Iterable<SkyKey> allKeys = ImmutableList.of(symlinkKey, fooKey); |
| 258 | |
| 259 | // First build -- prime the graph. |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 260 | EvaluationResult<FileValue> result = driver.evaluate(allKeys, EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 261 | assertThat(result.hasError()).isFalse(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 262 | FileValue symlinkValue = result.get(symlinkKey); |
| 263 | FileValue fooValue = result.get(fooKey); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 264 | assertWithMessage(symlinkValue.toString()).that(symlinkValue.isSymlink()).isTrue(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 265 | // Digest is not always available, so use size as a proxy for contents. |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 266 | assertThat(symlinkValue.getSize()).isEqualTo(fooValue.getSize()); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 267 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 268 | |
| 269 | // Before second build, move sym1 to point to sym2. |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 270 | assertThat(sym1.delete()).isTrue(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 271 | FileSystemUtils.ensureSymbolicLink(sym1, sym2); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 272 | assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), sym1FileStateKey); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 273 | |
| 274 | differencer.invalidate(ImmutableList.of(sym1FileStateKey)); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 275 | result = driver.evaluate(ImmutableList.<SkyKey>of(), EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 276 | assertThat(result.hasError()).isFalse(); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 277 | assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), sym1FileStateKey); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 278 | |
| 279 | // Before third build, move sym1 back to original (so change pruning will prevent signaling of |
| 280 | // its parents, but change symlink for real. |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 281 | assertThat(sym1.delete()).isTrue(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 282 | FileSystemUtils.ensureSymbolicLink(sym1, path); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 283 | assertThat(symlink.delete()).isTrue(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 284 | FileSystemUtils.writeContentAsLatin1(symlink, "new symlink contents"); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 285 | assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), symlinkFileStateKey); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 286 | differencer.invalidate(ImmutableList.of(symlinkFileStateKey)); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 287 | result = driver.evaluate(allKeys, EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 288 | assertThat(result.hasError()).isFalse(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 289 | symlinkValue = result.get(symlinkKey); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 290 | assertWithMessage(symlinkValue.toString()).that(symlinkValue.isSymlink()).isFalse(); |
| 291 | assertThat(result.get(fooKey)).isEqualTo(fooValue); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 292 | assertThat(symlinkValue.getSize()).isNotEqualTo(fooValue.getSize()); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 293 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 296 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 297 | public void testExplicitFiles() throws Exception { |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 298 | FilesystemValueChecker checker = |
| 299 | new FilesystemValueChecker( |
| 300 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 301 | |
| 302 | Path path1 = fs.getPath("/foo1"); |
| 303 | Path path2 = fs.getPath("/foo2"); |
| 304 | FileSystemUtils.createEmptyFile(path1); |
| 305 | FileSystemUtils.createEmptyFile(path2); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 306 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 307 | |
| 308 | SkyKey key1 = |
| 309 | FileStateValue.key( |
tomlu | 4c9fafd | 2018-01-18 10:29:11 -0800 | [diff] [blame] | 310 | RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo1"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 311 | SkyKey key2 = |
| 312 | FileStateValue.key( |
tomlu | 4c9fafd | 2018-01-18 10:29:11 -0800 | [diff] [blame] | 313 | RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo2"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 314 | Iterable<SkyKey> skyKeys = ImmutableList.of(key1, key2); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 315 | EvaluationResult<SkyValue> result = driver.evaluate(skyKeys, EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 316 | assertThat(result.hasError()).isFalse(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 317 | |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 318 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 319 | |
Laszlo Csomor | a278aec | 2018-03-09 04:07:31 -0800 | [diff] [blame] | 320 | // Wait for the timestamp granularity to elapse, so updating the files will observably advance |
| 321 | // their ctime. |
laszlocsomor | 29bdf63 | 2018-03-13 02:50:46 -0700 | [diff] [blame] | 322 | TimestampGranularityUtils.waitForTimestampGranularity( |
| 323 | System.currentTimeMillis(), OutErr.SYSTEM_OUT_ERR); |
Laszlo Csomor | a278aec | 2018-03-09 04:07:31 -0800 | [diff] [blame] | 324 | // Update path1's contents and mtime. This will update the file's ctime. |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 325 | FileSystemUtils.writeContentAsLatin1(path1, "hello1"); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 326 | path1.setLastModifiedTime(27); |
Laszlo Csomor | a278aec | 2018-03-09 04:07:31 -0800 | [diff] [blame] | 327 | // Update path2's mtime but not its contents. We expect that an mtime change suffices to update |
| 328 | // the ctime. |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 329 | path2.setLastModifiedTime(42); |
Laszlo Csomor | a278aec | 2018-03-09 04:07:31 -0800 | [diff] [blame] | 330 | // Assert that both files changed. The change detection relies, among other things, on ctime |
| 331 | // change. |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 332 | assertDiffWithNewValues(getDirtyFilesystemKeys(evaluator, checker), key1, key2); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 333 | |
| 334 | differencer.invalidate(skyKeys); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 335 | result = driver.evaluate(skyKeys, EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 336 | assertThat(result.hasError()).isFalse(); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 337 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 340 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 341 | public void testFileWithIOExceptionNotConsideredDirty() throws Exception { |
| 342 | Path path = fs.getPath("/testroot/foo"); |
| 343 | path.getParentDirectory().createDirectory(); |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 344 | path.createSymbolicLink(PathFragment.create("bar")); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 345 | |
| 346 | fs.readlinkThrowsIoException = true; |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 347 | SkyKey fileKey = |
| 348 | FileStateValue.key( |
| 349 | RootedPath.toRootedPath(Root.fromPath(pkgRoot), PathFragment.create("foo"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 350 | EvaluationResult<SkyValue> result = |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 351 | driver.evaluate(ImmutableList.of(fileKey), EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 352 | assertThat(result.hasError()).isTrue(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 353 | |
| 354 | fs.readlinkThrowsIoException = false; |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 355 | FilesystemValueChecker checker = |
| 356 | new FilesystemValueChecker( |
| 357 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 358 | Diff diff = getDirtyFilesystemKeys(evaluator, checker); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 359 | assertThat(diff.changedKeysWithoutNewValues()).isEmpty(); |
| 360 | assertThat(diff.changedKeysWithNewValues()).isEmpty(); |
| 361 | } |
| 362 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 363 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 364 | public void testFilesInCycleNotConsideredDirty() throws Exception { |
| 365 | Path path1 = pkgRoot.getRelative("foo1"); |
| 366 | Path path2 = pkgRoot.getRelative("foo2"); |
| 367 | Path path3 = pkgRoot.getRelative("foo3"); |
| 368 | FileSystemUtils.ensureSymbolicLink(path1, path2); |
| 369 | FileSystemUtils.ensureSymbolicLink(path2, path3); |
| 370 | FileSystemUtils.ensureSymbolicLink(path3, path1); |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 371 | SkyKey fileKey1 = FileValue.key(RootedPath.toRootedPath(Root.fromPath(pkgRoot), path1)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 372 | |
| 373 | EvaluationResult<SkyValue> result = |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 374 | driver.evaluate(ImmutableList.of(fileKey1), EVALUATION_OPTIONS); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 375 | assertThat(result.hasError()).isTrue(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 376 | |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 377 | FilesystemValueChecker checker = |
| 378 | new FilesystemValueChecker( |
| 379 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 380 | Diff diff = getDirtyFilesystemKeys(evaluator, checker); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 381 | assertThat(diff.changedKeysWithoutNewValues()).isEmpty(); |
| 382 | assertThat(diff.changedKeysWithNewValues()).isEmpty(); |
| 383 | } |
| 384 | |
| 385 | public void checkDirtyActions(BatchStat batchStatter, boolean forceDigests) throws Exception { |
| 386 | Artifact out1 = createDerivedArtifact("fiz"); |
| 387 | Artifact out2 = createDerivedArtifact("pop"); |
| 388 | |
| 389 | FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hello"); |
| 390 | FileSystemUtils.writeContentAsLatin1(out2.getPath(), "fizzlepop"); |
| 391 | |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 392 | TimestampGranularityMonitor tsgm = new TimestampGranularityMonitor(BlazeClock.instance()); |
janakr | baf52ae | 2018-02-14 09:03:18 -0800 | [diff] [blame] | 393 | ActionLookupKey actionLookupKey = |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 394 | new ActionLookupKey() { |
| 395 | @Override |
| 396 | public SkyFunctionName functionName() { |
| 397 | return SkyFunctionName.FOR_TESTING; |
| 398 | } |
| 399 | }; |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 400 | SkyKey actionKey1 = ActionLookupData.create(actionLookupKey, 0); |
| 401 | SkyKey actionKey2 = ActionLookupData.create(actionLookupKey, 1); |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 402 | |
| 403 | pretendBuildTwoArtifacts(out1, actionKey1, out2, actionKey2, batchStatter, tsgm); |
| 404 | |
| 405 | // Change the file but not its size |
| 406 | FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hallo"); |
| 407 | checkActionDirtiedByFile(out1, actionKey1, batchStatter, tsgm); |
| 408 | pretendBuildTwoArtifacts(out1, actionKey1, out2, actionKey2, batchStatter, tsgm); |
| 409 | |
| 410 | // Now try with a different size |
| 411 | FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hallo2"); |
| 412 | checkActionDirtiedByFile(out1, actionKey1, batchStatter, tsgm); |
| 413 | } |
| 414 | |
| 415 | private void pretendBuildTwoArtifacts( |
| 416 | Artifact out1, |
| 417 | SkyKey actionKey1, |
| 418 | Artifact out2, |
| 419 | SkyKey actionKey2, |
| 420 | BatchStat batchStatter, |
| 421 | TimestampGranularityMonitor tsgm) |
| 422 | throws InterruptedException { |
| 423 | EvaluationContext evaluationContext = |
| 424 | EvaluationContext.newBuilder() |
| 425 | .setKeepGoing(false) |
| 426 | .setNumThreads(1) |
| 427 | .setEventHander(NullEventHandler.INSTANCE) |
| 428 | .build(); |
| 429 | |
| 430 | tsgm.setCommandStartTime(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 431 | differencer.inject( |
| 432 | ImmutableMap.<SkyKey, SkyValue>of( |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 433 | actionKey1, |
| 434 | actionValue( |
| 435 | new TestAction( |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 436 | Runnables.doNothing(), |
| 437 | NestedSetBuilder.emptySet(Order.STABLE_ORDER), |
| 438 | ImmutableSet.of(out1))), |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 439 | actionKey2, |
| 440 | actionValue( |
| 441 | new TestAction( |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 442 | Runnables.doNothing(), |
ulfjack | 1e1a775 | 2019-12-10 21:17:58 -0800 | [diff] [blame] | 443 | NestedSetBuilder.emptySet(Order.STABLE_ORDER), |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 444 | ImmutableSet.of(out2))))); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 445 | assertThat(driver.evaluate(ImmutableList.<SkyKey>of(), evaluationContext).hasError()).isFalse(); |
Eric Fellheimer | e659072 | 2015-11-17 17:07:48 +0000 | [diff] [blame] | 446 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 447 | new FilesystemValueChecker( |
| 448 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 449 | .getDirtyActionValues( |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 450 | evaluator.getValues(), |
| 451 | batchStatter, |
| 452 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 453 | /* trustRemoteArtifacts= */ false)) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 454 | .isEmpty(); |
| 455 | |
| 456 | tsgm.waitForTimestampGranularity(OutErr.SYSTEM_OUT_ERR); |
| 457 | } |
| 458 | |
| 459 | private void checkActionDirtiedByFile( |
| 460 | Artifact file, SkyKey actionKey, BatchStat batchStatter, TimestampGranularityMonitor tsgm) |
| 461 | throws InterruptedException { |
Ulf Adams | c73051c6 | 2016-03-23 09:18:13 +0000 | [diff] [blame] | 462 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 463 | new FilesystemValueChecker( |
| 464 | tsgm, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 465 | .getDirtyActionValues( |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 466 | evaluator.getValues(), |
| 467 | batchStatter, |
| 468 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 469 | /* trustRemoteArtifacts= */ false)) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 470 | .containsExactly(actionKey); |
| 471 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 472 | new FilesystemValueChecker( |
| 473 | tsgm, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 474 | .getDirtyActionValues( |
| 475 | evaluator.getValues(), |
| 476 | batchStatter, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 477 | new ModifiedFileSet.Builder().modify(file.getExecPath()).build(), |
| 478 | /* trustRemoteArtifacts= */ false)) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 479 | .containsExactly(actionKey); |
Ulf Adams | c73051c6 | 2016-03-23 09:18:13 +0000 | [diff] [blame] | 480 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 481 | new FilesystemValueChecker( |
| 482 | tsgm, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 483 | .getDirtyActionValues( |
| 484 | evaluator.getValues(), |
| 485 | batchStatter, |
| 486 | new ModifiedFileSet.Builder() |
| 487 | .modify(file.getExecPath().getParentDirectory()) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 488 | .build(), |
| 489 | /* trustRemoteArtifacts= */ false)) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 490 | .isEmpty(); |
Eric Fellheimer | e659072 | 2015-11-17 17:07:48 +0000 | [diff] [blame] | 491 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 492 | new FilesystemValueChecker( |
| 493 | tsgm, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 494 | .getDirtyActionValues( |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 495 | evaluator.getValues(), |
| 496 | batchStatter, |
| 497 | ModifiedFileSet.NOTHING_MODIFIED, |
| 498 | /* trustRemoteArtifacts= */ false)) |
lberki | 41cfcc7 | 2019-08-05 02:55:36 -0700 | [diff] [blame] | 499 | .isEmpty(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 500 | } |
| 501 | |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 502 | private void checkDirtyTreeArtifactActions(BatchStat batchStatter) throws Exception { |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 503 | // Normally, an Action specifies the contents of a TreeArtifact when it executes. |
| 504 | // To decouple FileSystemValueTester checking from Action execution, we inject TreeArtifact |
| 505 | // contents into ActionExecutionValues. |
| 506 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 507 | SpecialArtifact out1 = createTreeArtifact("one"); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 508 | TreeFileArtifact file11 = TreeFileArtifact.createTreeOutput(out1, "fizz"); |
| 509 | out1.getPath().createDirectoryAndParents(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 510 | FileSystemUtils.writeContentAsLatin1(file11.getPath(), "buzz"); |
| 511 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 512 | SpecialArtifact out2 = createTreeArtifact("two"); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 513 | out2.getPath().getChild("subdir").createDirectoryAndParents(); |
| 514 | TreeFileArtifact file21 = TreeFileArtifact.createTreeOutput(out2, "moony"); |
| 515 | TreeFileArtifact file22 = TreeFileArtifact.createTreeOutput(out2, "subdir/wormtail"); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 516 | FileSystemUtils.writeContentAsLatin1(file21.getPath(), "padfoot"); |
| 517 | FileSystemUtils.writeContentAsLatin1(file22.getPath(), "prongs"); |
| 518 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 519 | SpecialArtifact outEmpty = createTreeArtifact("empty"); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 520 | outEmpty.getPath().createDirectoryAndParents(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 521 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 522 | SpecialArtifact outUnchanging = createTreeArtifact("untouched"); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 523 | outUnchanging.getPath().createDirectoryAndParents(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 524 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 525 | SpecialArtifact last = createTreeArtifact("zzzzzzzzzz"); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 526 | last.getPath().createDirectoryAndParents(); |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 527 | |
janakr | baf52ae | 2018-02-14 09:03:18 -0800 | [diff] [blame] | 528 | ActionLookupKey actionLookupKey = |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 529 | new ActionLookupKey() { |
| 530 | @Override |
| 531 | public SkyFunctionName functionName() { |
| 532 | return SkyFunctionName.FOR_TESTING; |
| 533 | } |
| 534 | }; |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 535 | SkyKey actionKey1 = ActionLookupData.create(actionLookupKey, 0); |
| 536 | SkyKey actionKey2 = ActionLookupData.create(actionLookupKey, 1); |
| 537 | SkyKey actionKeyEmpty = ActionLookupData.create(actionLookupKey, 2); |
| 538 | SkyKey actionKeyUnchanging = ActionLookupData.create(actionLookupKey, 3); |
| 539 | SkyKey actionKeyLast = ActionLookupData.create(actionLookupKey, 4); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 540 | differencer.inject( |
| 541 | ImmutableMap.<SkyKey, SkyValue>of( |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 542 | actionKey1, |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 543 | actionValueWithTreeArtifacts(ImmutableList.of(file11)), |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 544 | actionKey2, |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 545 | actionValueWithTreeArtifacts(ImmutableList.of(file21, file22)), |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 546 | actionKeyEmpty, |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 547 | actionValueWithEmptyDirectory(outEmpty), |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 548 | actionKeyUnchanging, |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 549 | actionValueWithEmptyDirectory(outUnchanging), |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 550 | actionKeyLast, |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 551 | actionValueWithEmptyDirectory(last))); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 552 | |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 553 | EvaluationContext evaluationContext = |
| 554 | EvaluationContext.newBuilder() |
| 555 | .setKeepGoing(false) |
| 556 | .setNumThreads(1) |
| 557 | .setEventHander(NullEventHandler.INSTANCE) |
| 558 | .build(); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 559 | assertThat(driver.evaluate(ImmutableList.of(), evaluationContext).hasError()).isFalse(); |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 560 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 561 | new FilesystemValueChecker( |
| 562 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 563 | .getDirtyActionValues( |
| 564 | evaluator.getValues(), |
| 565 | batchStatter, |
| 566 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 567 | /* trustRemoteArtifacts= */ false)) |
| 568 | .isEmpty(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 569 | |
| 570 | // Touching the TreeArtifact directory should have no effect |
| 571 | FileSystemUtils.touchFile(out1.getPath()); |
| 572 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 573 | new FilesystemValueChecker( |
| 574 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 575 | .getDirtyActionValues( |
| 576 | evaluator.getValues(), |
| 577 | batchStatter, |
| 578 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 579 | /* trustRemoteArtifacts= */ false)) |
| 580 | .isEmpty(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 581 | // Neither should touching a subdirectory. |
| 582 | FileSystemUtils.touchFile(out2.getPath().getChild("subdir")); |
| 583 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 584 | new FilesystemValueChecker( |
| 585 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 586 | .getDirtyActionValues( |
| 587 | evaluator.getValues(), |
| 588 | batchStatter, |
| 589 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 590 | /* trustRemoteArtifacts= */ false)) |
| 591 | .isEmpty(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 592 | |
| 593 | /* **** Tests for directories **** */ |
| 594 | |
| 595 | // Removing a directory (even if empty) should have an effect |
| 596 | outEmpty.getPath().delete(); |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 597 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 598 | new FilesystemValueChecker( |
| 599 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 600 | .getDirtyActionValues( |
| 601 | evaluator.getValues(), |
| 602 | batchStatter, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 603 | new ModifiedFileSet.Builder().modify(outEmpty.getExecPath()).build(), |
| 604 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 605 | .containsExactly(actionKeyEmpty); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 606 | // Symbolic links should count as dirty |
| 607 | Path dummyEmptyDir = fs.getPath("/bin").getRelative("symlink"); |
| 608 | FileSystemUtils.createDirectoryAndParents(dummyEmptyDir); |
| 609 | FileSystemUtils.ensureSymbolicLink(outEmpty.getPath(), dummyEmptyDir); |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 610 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 611 | new FilesystemValueChecker( |
| 612 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 613 | .getDirtyActionValues( |
| 614 | evaluator.getValues(), |
| 615 | batchStatter, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 616 | new ModifiedFileSet.Builder().modify(outEmpty.getExecPath()).build(), |
| 617 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 618 | .containsExactly(actionKeyEmpty); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 619 | |
| 620 | // We're done fiddling with this... restore the original state |
| 621 | outEmpty.getPath().delete(); |
jmmv | 5cc1f65 | 2019-03-20 09:34:08 -0700 | [diff] [blame] | 622 | dummyEmptyDir.deleteTree(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 623 | FileSystemUtils.createDirectoryAndParents(outEmpty.getPath()); |
| 624 | |
| 625 | /* **** Tests for files and directory contents ****/ |
| 626 | |
| 627 | // Test that file contents matter. This is covered by existing tests already, |
| 628 | // so it's just a sanity check. |
| 629 | FileSystemUtils.writeContentAsLatin1(file11.getPath(), "goodbye"); |
Ulf Adams | c73051c6 | 2016-03-23 09:18:13 +0000 | [diff] [blame] | 630 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 631 | new FilesystemValueChecker( |
| 632 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 633 | .getDirtyActionValues( |
| 634 | evaluator.getValues(), |
| 635 | batchStatter, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 636 | new ModifiedFileSet.Builder().modify(file11.getExecPath()).build(), |
| 637 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 638 | .containsExactly(actionKey1); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 639 | |
| 640 | // Test that directory contents (and nested contents) matter |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 641 | Artifact out1new = TreeFileArtifact.createTreeOutput(out1, "julius/caesar"); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 642 | FileSystemUtils.createDirectoryAndParents(out1.getPath().getChild("julius")); |
| 643 | FileSystemUtils.writeContentAsLatin1(out1new.getPath(), "octavian"); |
| 644 | // even for empty directories |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 645 | Artifact outEmptyNew = TreeFileArtifact.createTreeOutput(outEmpty, "marcus"); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 646 | FileSystemUtils.writeContentAsLatin1(outEmptyNew.getPath(), "aurelius"); |
| 647 | // so does removing |
| 648 | file21.getPath().delete(); |
| 649 | // now, let's test our changes are actually visible |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 650 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 651 | new FilesystemValueChecker( |
| 652 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 653 | .getDirtyActionValues( |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 654 | evaluator.getValues(), |
| 655 | batchStatter, |
| 656 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 657 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 658 | .containsExactly(actionKey1, actionKey2, actionKeyEmpty); |
| 659 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 660 | new FilesystemValueChecker( |
| 661 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 662 | .getDirtyActionValues( |
| 663 | evaluator.getValues(), |
| 664 | batchStatter, |
| 665 | new ModifiedFileSet.Builder() |
| 666 | .modify(file21.getExecPath()) |
| 667 | .modify(out1new.getExecPath()) |
| 668 | .modify(outEmptyNew.getExecPath()) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 669 | .build(), |
| 670 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 671 | .containsExactly(actionKey1, actionKey2, actionKeyEmpty); |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 672 | // We also check that if the modified file set does not contain our modified files on disk, |
| 673 | // we are not going to check and return them. |
| 674 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 675 | new FilesystemValueChecker( |
| 676 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 677 | .getDirtyActionValues( |
| 678 | evaluator.getValues(), |
| 679 | batchStatter, |
| 680 | new ModifiedFileSet.Builder() |
| 681 | .modify(file21.getExecPath()) |
| 682 | .modify(outEmptyNew.getExecPath()) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 683 | .build(), |
| 684 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 685 | .containsExactly(actionKey2, actionKeyEmpty); |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 686 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 687 | new FilesystemValueChecker( |
| 688 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 689 | .getDirtyActionValues( |
| 690 | evaluator.getValues(), |
| 691 | batchStatter, |
| 692 | new ModifiedFileSet.Builder() |
| 693 | .modify(file21.getExecPath()) |
| 694 | .modify(out1new.getExecPath()) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 695 | .build(), |
| 696 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 697 | .containsExactly(actionKey1, actionKey2); |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 698 | // Check modifying the last (lexicographically) tree artifact. |
| 699 | last.getPath().delete(); |
| 700 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 701 | new FilesystemValueChecker( |
| 702 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 703 | .getDirtyActionValues( |
| 704 | evaluator.getValues(), |
| 705 | batchStatter, |
| 706 | new ModifiedFileSet.Builder() |
| 707 | .modify(file21.getExecPath()) |
| 708 | .modify(out1new.getExecPath()) |
| 709 | .modify(last.getExecPath()) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 710 | .build(), |
| 711 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 712 | .containsExactly(actionKey1, actionKey2, actionKeyLast); |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 713 | // Check ModifiedFileSet without the last (lexicographically) tree artifact. |
| 714 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 715 | new FilesystemValueChecker( |
| 716 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 717 | .getDirtyActionValues( |
| 718 | evaluator.getValues(), |
| 719 | batchStatter, |
| 720 | new ModifiedFileSet.Builder() |
| 721 | .modify(file21.getExecPath()) |
| 722 | .modify(out1new.getExecPath()) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 723 | .build(), |
| 724 | /* trustRemoteArtifacts= */ false)) |
Janak Ramakrishnan | 5d15269 | 2017-03-20 22:07:14 +0000 | [diff] [blame] | 725 | .containsExactly(actionKey1, actionKey2); |
Rumou Duan | 45e8e57 | 2016-06-17 16:43:44 +0000 | [diff] [blame] | 726 | // Restore |
| 727 | last.getPath().delete(); |
| 728 | FileSystemUtils.createDirectoryAndParents(last.getPath()); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 729 | // We add a test for NOTHING_MODIFIED, because FileSystemValueChecker doesn't |
| 730 | // pay attention to file sets for TreeArtifact directory listings. |
| 731 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 732 | new FilesystemValueChecker( |
| 733 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 734 | .getDirtyActionValues( |
| 735 | evaluator.getValues(), |
| 736 | batchStatter, |
| 737 | ModifiedFileSet.NOTHING_MODIFIED, |
| 738 | /* trustRemoteArtifacts= */ false)) |
| 739 | .isEmpty(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 742 | private Artifact createDerivedArtifact(String relPath) throws IOException { |
janakr | 448f1cf | 2020-03-30 09:12:44 -0700 | [diff] [blame] | 743 | String outSegment = "bin"; |
| 744 | Path outputPath = fs.getPath("/" + outSegment); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 745 | outputPath.createDirectory(); |
janakr | aea0560 | 2019-05-22 15:41:29 -0700 | [diff] [blame] | 746 | return ActionsTestUtil.createArtifact( |
janakr | 448f1cf | 2020-03-30 09:12:44 -0700 | [diff] [blame] | 747 | ArtifactRoot.asDerivedRoot(fs.getPath("/"), outSegment), outputPath.getRelative(relPath)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 748 | } |
| 749 | |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 750 | private SpecialArtifact createTreeArtifact(String relPath) throws IOException { |
janakr | 448f1cf | 2020-03-30 09:12:44 -0700 | [diff] [blame] | 751 | String outSegment = "bin"; |
| 752 | Path outputDir = fs.getPath("/" + outSegment); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 753 | Path outputPath = outputDir.getRelative(relPath); |
| 754 | outputDir.createDirectory(); |
janakr | 448f1cf | 2020-03-30 09:12:44 -0700 | [diff] [blame] | 755 | ArtifactRoot derivedRoot = ArtifactRoot.asDerivedRoot(fs.getPath("/"), outSegment); |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 756 | return ActionsTestUtil.createTreeArtifactWithGeneratingAction( |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 757 | derivedRoot, |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 758 | derivedRoot.getExecPath().getRelative(derivedRoot.getRoot().relativize(outputPath))); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 761 | @Test |
steinman | 7184cb3 | 2020-04-20 14:33:03 -0700 | [diff] [blame] | 762 | // TODO(b/154337187): Remove the following annotation to re-enable once this test is de-flaked. |
| 763 | @Ignore |
| 764 | public void testDirtyActions() throws Exception { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 765 | checkDirtyActions(null, false); |
| 766 | } |
| 767 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 768 | @Test |
steinman | 7184cb3 | 2020-04-20 14:33:03 -0700 | [diff] [blame] | 769 | // TODO(b/154337187): Remove the following annotation to re-enable once this test is de-flaked. |
| 770 | @Ignore |
| 771 | public void testDirtyActionsBatchStat() throws Exception { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 772 | checkDirtyActions( |
| 773 | new BatchStat() { |
| 774 | @Override |
| 775 | public List<FileStatusWithDigest> batchStat( |
| 776 | boolean useDigest, boolean includeLinks, Iterable<PathFragment> paths) |
| 777 | throws IOException { |
| 778 | List<FileStatusWithDigest> stats = new ArrayList<>(); |
| 779 | for (PathFragment pathFrag : paths) { |
| 780 | stats.add( |
| 781 | FileStatusWithDigestAdapter.adapt( |
tomlu | 6c91906 | 2018-01-11 17:32:09 -0800 | [diff] [blame] | 782 | fs.getPath("/").getRelative(pathFrag).statIfFound(Symlinks.NOFOLLOW))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 783 | } |
| 784 | return stats; |
| 785 | } |
| 786 | }, |
| 787 | false); |
| 788 | } |
| 789 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 790 | @Test |
steinman | 68e78f5 | 2020-04-23 12:30:19 -0700 | [diff] [blame] | 791 | // TODO(b/154337187): Remove the following annotation to re-enable once this test is de-flaked. |
| 792 | @Ignore |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 793 | public void testDirtyActionsBatchStatWithDigest() throws Exception { |
| 794 | checkDirtyActions( |
| 795 | new BatchStat() { |
| 796 | @Override |
| 797 | public List<FileStatusWithDigest> batchStat( |
| 798 | boolean useDigest, boolean includeLinks, Iterable<PathFragment> paths) |
| 799 | throws IOException { |
| 800 | List<FileStatusWithDigest> stats = new ArrayList<>(); |
| 801 | for (PathFragment pathFrag : paths) { |
tomlu | 6c91906 | 2018-01-11 17:32:09 -0800 | [diff] [blame] | 802 | final Path path = fs.getPath("/").getRelative(pathFrag); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 803 | stats.add(statWithDigest(path, path.statIfFound(Symlinks.NOFOLLOW))); |
| 804 | } |
| 805 | return stats; |
| 806 | } |
| 807 | }, |
| 808 | true); |
| 809 | } |
| 810 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 811 | @Test |
steinman | 68e78f5 | 2020-04-23 12:30:19 -0700 | [diff] [blame] | 812 | // TODO(b/154337187): Remove the following annotation to re-enable once this test is de-flaked. |
| 813 | @Ignore |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 814 | public void testDirtyActionsBatchStatFallback() throws Exception { |
| 815 | checkDirtyActions( |
| 816 | new BatchStat() { |
| 817 | @Override |
| 818 | public List<FileStatusWithDigest> batchStat( |
| 819 | boolean useDigest, boolean includeLinks, Iterable<PathFragment> paths) |
| 820 | throws IOException { |
| 821 | throw new IOException("try again"); |
| 822 | } |
| 823 | }, |
| 824 | false); |
| 825 | } |
| 826 | |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 827 | @Test |
| 828 | public void testDirtyTreeArtifactActions() throws Exception { |
| 829 | checkDirtyTreeArtifactActions(null); |
| 830 | } |
| 831 | |
| 832 | @Test |
| 833 | public void testDirtyTreeArtifactActionsBatchStat() throws Exception { |
| 834 | checkDirtyTreeArtifactActions( |
| 835 | new BatchStat() { |
| 836 | @Override |
| 837 | public List<FileStatusWithDigest> batchStat( |
| 838 | boolean useDigest, boolean includeLinks, Iterable<PathFragment> paths) |
| 839 | throws IOException { |
| 840 | List<FileStatusWithDigest> stats = new ArrayList<>(); |
| 841 | for (PathFragment pathFrag : paths) { |
| 842 | stats.add( |
| 843 | FileStatusWithDigestAdapter.adapt( |
tomlu | 6c91906 | 2018-01-11 17:32:09 -0800 | [diff] [blame] | 844 | fs.getPath("/").getRelative(pathFrag).statIfFound(Symlinks.NOFOLLOW))); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 845 | } |
| 846 | return stats; |
| 847 | } |
| 848 | }); |
| 849 | } |
| 850 | |
| 851 | // TODO(bazel-team): Add some tests for FileSystemValueChecker#changedKeys*() methods. |
| 852 | // Presently these appear to be untested. |
| 853 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 854 | private static ActionExecutionValue actionValue(Action action) { |
lberki | f7eee1e | 2019-07-31 05:49:10 -0700 | [diff] [blame] | 855 | Map<Artifact, FileArtifactValue> artifactData = new HashMap<>(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 856 | for (Artifact output : action.getOutputs()) { |
| 857 | try { |
| 858 | Path path = output.getPath(); |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 859 | FileArtifactValue noDigest = |
| 860 | ActionMetadataHandler.fileArtifactValueFromArtifact( |
| 861 | output, |
| 862 | FileStatusWithDigestAdapter.adapt(path.statIfFound(Symlinks.NOFOLLOW)), |
| 863 | null); |
| 864 | FileArtifactValue withDigest = |
| 865 | FileArtifactValue.createFromInjectedDigest( |
| 866 | noDigest, path.getDigest(), !output.isConstantMetadata()); |
| 867 | artifactData.put(output, withDigest); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 868 | } catch (IOException e) { |
| 869 | throw new IllegalStateException(e); |
| 870 | } |
| 871 | } |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 872 | return ActionExecutionValue.create( |
Michael Thvedt | 8d5a7bb | 2016-02-09 03:06:34 +0000 | [diff] [blame] | 873 | artifactData, |
Googler | 974879d | 2020-05-27 13:25:52 -0700 | [diff] [blame] | 874 | /*treeArtifactData=*/ ImmutableMap.of(), |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 875 | /*outputSymlinks=*/ null, |
shahan | ef6f4cf | 2018-06-26 11:24:59 -0700 | [diff] [blame] | 876 | /*discoveredModules=*/ null, |
janakr | 9f496f3 | 2018-10-24 15:08:09 -0700 | [diff] [blame] | 877 | /*actionDependsOnBuildId=*/ false); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 878 | } |
| 879 | |
Googler | 974879d | 2020-05-27 13:25:52 -0700 | [diff] [blame] | 880 | private static ActionExecutionValue actionValueWithEmptyDirectory(SpecialArtifact emptyDir) { |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 881 | return ActionExecutionValue.create( |
Googler | 974879d | 2020-05-27 13:25:52 -0700 | [diff] [blame] | 882 | /*artifactData=*/ ImmutableMap.of(), |
| 883 | ImmutableMap.of(emptyDir, TreeArtifactValue.create(ImmutableMap.of())), |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 884 | /*outputSymlinks=*/ null, |
shahan | ef6f4cf | 2018-06-26 11:24:59 -0700 | [diff] [blame] | 885 | /*discoveredModules=*/ null, |
janakr | 9f496f3 | 2018-10-24 15:08:09 -0700 | [diff] [blame] | 886 | /*actionDependsOnBuildId=*/ false); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 887 | } |
| 888 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 889 | private static ActionExecutionValue actionValueWithTreeArtifacts( |
| 890 | List<TreeFileArtifact> contents) { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 891 | Map<Artifact, Map<TreeFileArtifact, FileArtifactValue>> directoryData = new HashMap<>(); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 892 | |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 893 | for (TreeFileArtifact output : contents) { |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 894 | try { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 895 | Map<TreeFileArtifact, FileArtifactValue> dirDatum = |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 896 | directoryData.get(output.getParent()); |
| 897 | if (dirDatum == null) { |
| 898 | dirDatum = new HashMap<>(); |
| 899 | directoryData.put(output.getParent(), dirDatum); |
| 900 | } |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 901 | Path path = output.getPath(); |
| 902 | FileArtifactValue noDigest = |
| 903 | ActionMetadataHandler.fileArtifactValueFromArtifact( |
| 904 | output, |
| 905 | FileStatusWithDigestAdapter.adapt(path.statIfFound(Symlinks.NOFOLLOW)), |
| 906 | null); |
| 907 | FileArtifactValue withDigest = |
| 908 | FileArtifactValue.createFromInjectedDigest( |
| 909 | noDigest, path.getDigest(), !output.isConstantMetadata()); |
| 910 | dirDatum.put(output, withDigest); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 911 | } catch (IOException e) { |
| 912 | throw new IllegalStateException(e); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | Map<Artifact, TreeArtifactValue> treeArtifactData = new HashMap<>(); |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 917 | for (Map.Entry<Artifact, Map<TreeFileArtifact, FileArtifactValue>> dirDatum : |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 918 | directoryData.entrySet()) { |
Rumou Duan | a77f32c | 2016-04-13 21:59:21 +0000 | [diff] [blame] | 919 | treeArtifactData.put(dirDatum.getKey(), TreeArtifactValue.create(dirDatum.getValue())); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 920 | } |
| 921 | |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 922 | return ActionExecutionValue.create( |
Googler | 974879d | 2020-05-27 13:25:52 -0700 | [diff] [blame] | 923 | /*artifactData=*/ ImmutableMap.of(), |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 924 | treeArtifactData, |
janakr | b9d8d58 | 2018-06-13 21:57:19 -0700 | [diff] [blame] | 925 | /*outputSymlinks=*/ null, |
shahan | ef6f4cf | 2018-06-26 11:24:59 -0700 | [diff] [blame] | 926 | /*discoveredModules=*/ null, |
janakr | 9f496f3 | 2018-10-24 15:08:09 -0700 | [diff] [blame] | 927 | /*actionDependsOnBuildId=*/ false); |
Michael Thvedt | e4a7b079 | 2016-02-09 12:15:53 +0000 | [diff] [blame] | 928 | } |
| 929 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 930 | private static ActionExecutionValue actionValueWithRemoteTreeArtifact( |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 931 | SpecialArtifact output, Map<PathFragment, RemoteFileArtifactValue> children) { |
| 932 | ImmutableMap.Builder<TreeFileArtifact, FileArtifactValue> childFileValues = |
| 933 | ImmutableMap.builder(); |
| 934 | for (Map.Entry<PathFragment, RemoteFileArtifactValue> child : children.entrySet()) { |
| 935 | childFileValues.put( |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 936 | TreeFileArtifact.createTreeOutput(output, child.getKey()), child.getValue()); |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 937 | } |
| 938 | TreeArtifactValue treeArtifactValue = TreeArtifactValue.create(childFileValues.build()); |
| 939 | return ActionExecutionValue.create( |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 940 | ImmutableMap.of(), |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 941 | Collections.singletonMap(output, treeArtifactValue), |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 942 | /* outputSymlinks= */ null, |
| 943 | /* discoveredModules= */ null, |
| 944 | /* actionDependsOnBuildId= */ false); |
| 945 | } |
| 946 | |
ajurkowski | e298291 | 2020-04-09 10:32:08 -0700 | [diff] [blame] | 947 | private static ActionExecutionValue actionValueWithRemoteArtifact( |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 948 | Artifact output, RemoteFileArtifactValue value) { |
| 949 | return ActionExecutionValue.create( |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 950 | Collections.singletonMap(output, value), |
lberki | c35878a | 2019-08-01 02:28:54 -0700 | [diff] [blame] | 951 | ImmutableMap.of(), |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 952 | /* outputSymlinks= */ null, |
| 953 | /* discoveredModules= */ null, |
| 954 | /* actionDependsOnBuildId= */ false); |
| 955 | } |
| 956 | |
| 957 | private RemoteFileArtifactValue createRemoteFileArtifactValue(String contents) { |
| 958 | byte[] data = contents.getBytes(); |
| 959 | DigestHashFunction hashFn = fs.getDigestFunction(); |
| 960 | HashCode hash = hashFn.getHashFunction().hashBytes(data); |
George Gensure | 3ef8fb9 | 2020-05-06 09:49:48 -0700 | [diff] [blame] | 961 | return new RemoteFileArtifactValue(hash.asBytes(), data.length, -1, "action-id"); |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | @Test |
| 965 | public void testRemoteAndLocalArtifacts() throws Exception { |
| 966 | // Test that injected remote artifacts are trusted by the FileSystemValueChecker |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 967 | // if it is configured to trust remote artifacts, and that local files always take precedence |
| 968 | // over remote files. |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 969 | ActionLookupKey actionLookupKey = |
| 970 | new ActionLookupKey() { |
| 971 | @Override |
| 972 | public SkyFunctionName functionName() { |
| 973 | return SkyFunctionName.FOR_TESTING; |
| 974 | } |
| 975 | }; |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 976 | SkyKey actionKey1 = ActionLookupData.create(actionLookupKey, 0); |
| 977 | SkyKey actionKey2 = ActionLookupData.create(actionLookupKey, 1); |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 978 | |
| 979 | Artifact out1 = createDerivedArtifact("foo"); |
| 980 | Artifact out2 = createDerivedArtifact("bar"); |
| 981 | Map<SkyKey, SkyValue> metadataToInject = new HashMap<>(); |
| 982 | metadataToInject.put( |
| 983 | actionKey1, |
| 984 | actionValueWithRemoteArtifact(out1, createRemoteFileArtifactValue("foo-content"))); |
| 985 | metadataToInject.put( |
| 986 | actionKey2, |
| 987 | actionValueWithRemoteArtifact(out2, createRemoteFileArtifactValue("bar-content"))); |
| 988 | differencer.inject(metadataToInject); |
| 989 | |
| 990 | EvaluationContext evaluationContext = |
| 991 | EvaluationContext.newBuilder() |
| 992 | .setKeepGoing(false) |
| 993 | .setNumThreads(1) |
| 994 | .setEventHander(NullEventHandler.INSTANCE) |
| 995 | .build(); |
| 996 | assertThat( |
| 997 | driver.evaluate(ImmutableList.of(actionKey1, actionKey2), evaluationContext).hasError()) |
| 998 | .isFalse(); |
| 999 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 1000 | new FilesystemValueChecker( |
| 1001 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1002 | .getDirtyActionValues( |
| 1003 | evaluator.getValues(), |
| 1004 | /* batchStatter= */ null, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 1005 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 1006 | /* trustRemoteArtifacts= */ true)) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1007 | .isEmpty(); |
| 1008 | |
| 1009 | // Create the "out1" artifact on the filesystem and test that it invalidates the generating |
| 1010 | // action's SkyKey. |
| 1011 | FileSystemUtils.writeContentAsLatin1(out1.getPath(), "new-foo-content"); |
| 1012 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 1013 | new FilesystemValueChecker( |
| 1014 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1015 | .getDirtyActionValues( |
| 1016 | evaluator.getValues(), |
| 1017 | /* batchStatter= */ null, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 1018 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 1019 | /* trustRemoteArtifacts= */ true)) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1020 | .containsExactly(actionKey1); |
| 1021 | } |
| 1022 | |
| 1023 | @Test |
| 1024 | public void testRemoteAndLocalTreeArtifacts() throws Exception { |
| 1025 | // Test that injected remote tree artifacts are trusted by the FileSystemValueChecker |
| 1026 | // and that local files always takes preference over remote files. |
| 1027 | ActionLookupKey actionLookupKey = |
| 1028 | new ActionLookupKey() { |
| 1029 | @Override |
| 1030 | public SkyFunctionName functionName() { |
| 1031 | return SkyFunctionName.FOR_TESTING; |
| 1032 | } |
| 1033 | }; |
janakr | efb3f15 | 2019-06-05 17:42:34 -0700 | [diff] [blame] | 1034 | SkyKey actionKey = ActionLookupData.create(actionLookupKey, 0); |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1035 | |
| 1036 | SpecialArtifact treeArtifact = createTreeArtifact("dir"); |
| 1037 | treeArtifact.getPath().createDirectoryAndParents(); |
| 1038 | Map<PathFragment, RemoteFileArtifactValue> treeArtifactMetadata = new HashMap<>(); |
| 1039 | treeArtifactMetadata.put( |
| 1040 | PathFragment.create("foo"), createRemoteFileArtifactValue("foo-content")); |
| 1041 | treeArtifactMetadata.put( |
| 1042 | PathFragment.create("bar"), createRemoteFileArtifactValue("bar-content")); |
| 1043 | |
| 1044 | Map<SkyKey, SkyValue> metadataToInject = new HashMap<>(); |
| 1045 | metadataToInject.put( |
| 1046 | actionKey, actionValueWithRemoteTreeArtifact(treeArtifact, treeArtifactMetadata)); |
| 1047 | differencer.inject(metadataToInject); |
| 1048 | |
| 1049 | EvaluationContext evaluationContext = |
| 1050 | EvaluationContext.newBuilder() |
| 1051 | .setKeepGoing(false) |
| 1052 | .setNumThreads(1) |
| 1053 | .setEventHander(NullEventHandler.INSTANCE) |
| 1054 | .build(); |
| 1055 | assertThat(driver.evaluate(ImmutableList.of(actionKey), evaluationContext).hasError()) |
| 1056 | .isFalse(); |
| 1057 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 1058 | new FilesystemValueChecker( |
| 1059 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1060 | .getDirtyActionValues( |
| 1061 | evaluator.getValues(), |
| 1062 | /* batchStatter= */ null, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 1063 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 1064 | /* trustRemoteArtifacts= */ false)) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1065 | .isEmpty(); |
| 1066 | |
| 1067 | // Create dir/foo on the local disk and test that it invalidates the associated sky key. |
Googler | 1d8d138 | 2020-05-18 12:10:49 -0700 | [diff] [blame] | 1068 | TreeFileArtifact fooArtifact = TreeFileArtifact.createTreeOutput(treeArtifact, "foo"); |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1069 | FileSystemUtils.writeContentAsLatin1(fooArtifact.getPath(), "new-foo-content"); |
| 1070 | assertThat( |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 1071 | new FilesystemValueChecker( |
| 1072 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1073 | .getDirtyActionValues( |
| 1074 | evaluator.getValues(), |
| 1075 | /* batchStatter= */ null, |
steinman | 39c00d2 | 2020-03-20 15:23:10 -0700 | [diff] [blame] | 1076 | ModifiedFileSet.EVERYTHING_MODIFIED, |
| 1077 | /* trustRemoteArtifacts= */ false)) |
buchgr | 4992ae2 | 2019-03-20 04:23:32 -0700 | [diff] [blame] | 1078 | .containsExactly(actionKey); |
| 1079 | } |
| 1080 | |
Han-Wen Nienhuys | 3b2eae3 | 2015-10-28 16:35:08 +0000 | [diff] [blame] | 1081 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1082 | public void testPropagatesRuntimeExceptions() throws Exception { |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 1083 | Collection<SkyKey> values = |
| 1084 | ImmutableList.of( |
| 1085 | FileValue.key( |
| 1086 | RootedPath.toRootedPath(Root.fromPath(pkgRoot), PathFragment.create("foo")))); |
Googler | 1002867 | 2018-10-25 12:14:34 -0700 | [diff] [blame] | 1087 | driver.evaluate(values, EVALUATION_OPTIONS); |
twerth | 5aaceb5 | 2020-04-07 06:31:56 -0700 | [diff] [blame] | 1088 | FilesystemValueChecker checker = |
| 1089 | new FilesystemValueChecker( |
| 1090 | /* tsgm= */ null, /* lastExecutionTimeRange= */ null, FSVC_THREADS_FOR_TEST); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1091 | |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 1092 | assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1093 | |
| 1094 | fs.statThrowsRuntimeException = true; |
jcater | 83130f4 | 2019-04-30 14:29:28 -0700 | [diff] [blame] | 1095 | RuntimeException e = |
| 1096 | assertThrows(RuntimeException.class, () -> getDirtyFilesystemKeys(evaluator, checker)); |
| 1097 | assertThat(e).hasMessageThat().isEqualTo("bork"); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | private static void assertEmptyDiff(Diff diff) { |
| 1101 | assertDiffWithNewValues(diff); |
| 1102 | } |
| 1103 | |
| 1104 | private static void assertDiffWithNewValues(Diff diff, SkyKey... keysWithNewValues) { |
| 1105 | assertThat(diff.changedKeysWithoutNewValues()).isEmpty(); |
| 1106 | assertThat(diff.changedKeysWithNewValues().keySet()) |
| 1107 | .containsExactlyElementsIn(Arrays.asList(keysWithNewValues)); |
| 1108 | } |
| 1109 | |
| 1110 | private class MockFileSystem extends InMemoryFileSystem { |
| 1111 | |
| 1112 | boolean statThrowsRuntimeException; |
| 1113 | boolean readlinkThrowsIoException; |
| 1114 | |
| 1115 | MockFileSystem() { |
ccalvarin | c9efd06 | 2018-07-27 12:46:46 -0700 | [diff] [blame] | 1116 | super(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | @Override |
felly | a205ed8 | 2018-09-10 11:52:34 -0700 | [diff] [blame] | 1120 | public FileStatus statIfFound(Path path, boolean followSymlinks) throws IOException { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1121 | if (statThrowsRuntimeException) { |
| 1122 | throw new RuntimeException("bork"); |
| 1123 | } |
felly | a205ed8 | 2018-09-10 11:52:34 -0700 | [diff] [blame] | 1124 | return super.statIfFound(path, followSymlinks); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | @Override |
aehlig | c801c39 | 2017-12-19 07:12:25 -0800 | [diff] [blame] | 1128 | protected PathFragment readSymbolicLink(Path path) throws IOException { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1129 | if (readlinkThrowsIoException) { |
| 1130 | throw new IOException("readlink failed"); |
| 1131 | } |
| 1132 | return super.readSymbolicLink(path); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | private static FileStatusWithDigest statWithDigest(final Path path, final FileStatus stat) { |
| 1137 | return new FileStatusWithDigest() { |
| 1138 | @Nullable |
| 1139 | @Override |
| 1140 | public byte[] getDigest() throws IOException { |
olaola | bfd1d33 | 2017-06-19 16:55:24 -0400 | [diff] [blame] | 1141 | return path.getDigest(); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | @Override |
| 1145 | public boolean isFile() { |
| 1146 | return stat.isFile(); |
| 1147 | } |
| 1148 | |
| 1149 | @Override |
| 1150 | public boolean isSpecialFile() { |
| 1151 | return stat.isSpecialFile(); |
| 1152 | } |
| 1153 | |
| 1154 | @Override |
| 1155 | public boolean isDirectory() { |
| 1156 | return stat.isDirectory(); |
| 1157 | } |
| 1158 | |
| 1159 | @Override |
| 1160 | public boolean isSymbolicLink() { |
| 1161 | return stat.isSymbolicLink(); |
| 1162 | } |
| 1163 | |
| 1164 | @Override |
| 1165 | public long getSize() throws IOException { |
| 1166 | return stat.getSize(); |
| 1167 | } |
| 1168 | |
| 1169 | @Override |
| 1170 | public long getLastModifiedTime() throws IOException { |
| 1171 | return stat.getLastModifiedTime(); |
| 1172 | } |
| 1173 | |
| 1174 | @Override |
| 1175 | public long getLastChangeTime() throws IOException { |
| 1176 | return stat.getLastChangeTime(); |
| 1177 | } |
| 1178 | |
| 1179 | @Override |
| 1180 | public long getNodeId() throws IOException { |
| 1181 | return stat.getNodeId(); |
| 1182 | } |
| 1183 | }; |
| 1184 | } |
| 1185 | |
Nathan Harmata | 8cd2978 | 2015-11-10 03:24:01 +0000 | [diff] [blame] | 1186 | private static Diff getDirtyFilesystemKeys(MemoizingEvaluator evaluator, |
| 1187 | FilesystemValueChecker checker) throws InterruptedException { |
| 1188 | return checker.getDirtyKeys(evaluator.getValues(), new BasicFilesystemDirtinessChecker()); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1189 | } |
| 1190 | } |