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