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