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