aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java
diff options
context:
space:
mode:
authorGravatar Kush Chakraborty <kush@google.com>2016-12-08 19:53:41 +0000
committerGravatar Irina Iancu <elenairina@google.com>2016-12-09 15:32:55 +0000
commit25120df651ae7d0ac9e85cbbea54921d1f2c4ae4 (patch)
treef0938c8db71c6e4b2684befdb88fa6023cc85155 /src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java
parent38edc5dc9d1fd58ffcb3223a1c194e04eb066437 (diff)
Initial code for Persistent Java Test Runner.
At this point this does nothing more than re-run the exact same test without having to re-start the test runner. In future iterations the aim is to be able to re-run tests with modified code, without having to re-start the test runner. To test out the WorkerTestStrategy simply use --test_strategy=experimental_worker for a test with bazel. -- PiperOrigin-RevId: 141465929 MOS_MIGRATED_REVID=141465929
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java
new file mode 100644
index 0000000000..08ab7f5e88
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerFilesHash.java
@@ -0,0 +1,41 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.worker;
+
+import com.google.common.hash.HashCode;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+import com.google.devtools.build.lib.actions.ActionExecutionContext;
+import com.google.devtools.build.lib.actions.ActionInput;
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+/**
+ * Calculates the hash based on the files, which should be unchanged on disk for a worker to get
+ * reused.
+ */
+public class WorkerFilesHash {
+
+ public static HashCode getWorkerFilesHash(
+ Iterable<? extends ActionInput> toolFiles, ActionExecutionContext actionExecutionContext)
+ throws IOException {
+ Hasher hasher = Hashing.sha256().newHasher();
+ for (ActionInput tool : toolFiles) {
+ hasher.putString(tool.getExecPathString(), Charset.defaultCharset());
+ hasher.putBytes(actionExecutionContext.getActionInputFileCache().getDigest(tool));
+ }
+ return hasher.hash();
+ }
+}