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