|
| 1 | +diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/FileWriteAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/FileWriteAction.java |
| 2 | +index c7aa4cb63..e084bc27c 100644 |
| 3 | +--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/FileWriteAction.java |
| 4 | ++++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/FileWriteAction.java |
| 5 | +@@ -28,6 +28,7 @@ import java.io.ByteArrayInputStream; |
| 6 | + import java.io.ByteArrayOutputStream; |
| 7 | + import java.io.IOException; |
| 8 | + import java.io.OutputStream; |
| 9 | ++import java.io.PrintWriter; |
| 10 | + import java.util.zip.GZIPInputStream; |
| 11 | + import java.util.zip.GZIPOutputStream; |
| 12 | + |
| 13 | +@@ -73,6 +74,8 @@ public final class FileWriteAction extends AbstractFileWriteAction { |
| 14 | + */ |
| 15 | + private final CharSequence fileContents; |
| 16 | + |
| 17 | ++ private final Artifact output; |
| 18 | ++ |
| 19 | + /** Minimum length (in chars) for content to be eligible for compression. */ |
| 20 | + private static final int COMPRESS_CHARS_THRESHOLD = 256; |
| 21 | + |
| 22 | +@@ -90,6 +93,7 @@ public final class FileWriteAction extends AbstractFileWriteAction { |
| 23 | + fileContents = new CompressedString((String) fileContents); |
| 24 | + } |
| 25 | + this.fileContents = fileContents; |
| 26 | ++ this.output = output; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | +@@ -230,11 +234,32 @@ public final class FileWriteAction extends AbstractFileWriteAction { |
| 31 | + */ |
| 32 | + @Override |
| 33 | + protected String computeKey() { |
| 34 | ++ // System.err.println("src/main/java/com/google/devtools/build/lib/analysis/actions/FileWriteAction.java => output: " + output.getExecPath()); |
| 35 | ++ // ".ckd" Compute Key Debug |
| 36 | ++ PrintWriter computeKeyDebugWriter = null; |
| 37 | ++ String computeKeyDebugFile = output.getExecPath() + ".FileWriteAction.ckd"; |
| 38 | ++ try { |
| 39 | ++ computeKeyDebugWriter = new PrintWriter(computeKeyDebugFile, "UTF-8"); |
| 40 | ++ } catch (java.io.FileNotFoundException ex) { |
| 41 | ++ System.err.println("Unable to create " + computeKeyDebugFile); |
| 42 | ++ } catch (java.io.UnsupportedEncodingException ex) { |
| 43 | ++ System.err.println("Unsupported encoding"); |
| 44 | ++ } |
| 45 | ++ |
| 46 | + Fingerprint f = new Fingerprint(); |
| 47 | + f.addString(GUID); |
| 48 | ++ computeKeyDebugWriter.println("GUID: " + GUID); |
| 49 | ++ |
| 50 | + f.addString(String.valueOf(makeExecutable)); |
| 51 | ++ computeKeyDebugWriter.println("MAKEEXECUTABLE: " + String.valueOf(makeExecutable)); |
| 52 | ++ |
| 53 | + f.addString(getFileContents()); |
| 54 | +- return f.hexDigestAndReset(); |
| 55 | ++ computeKeyDebugWriter.println("FILECONTENTS: " + getFileContents()); |
| 56 | ++ |
| 57 | ++ String rv = f.hexDigestAndReset(); |
| 58 | ++ computeKeyDebugWriter.println("KEY: " + rv); |
| 59 | ++ computeKeyDebugWriter.close(); |
| 60 | ++ return rv; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | +diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java |
| 65 | +index 580788160..26883eb92 100644 |
| 66 | +--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java |
| 67 | ++++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java |
| 68 | +@@ -60,6 +60,7 @@ import com.google.devtools.build.lib.util.ShellEscaper; |
| 69 | + import com.google.devtools.build.lib.vfs.PathFragment; |
| 70 | + import com.google.protobuf.GeneratedMessage.GeneratedExtension; |
| 71 | + import java.nio.charset.Charset; |
| 72 | ++import java.io.PrintWriter; |
| 73 | + import java.util.ArrayList; |
| 74 | + import java.util.Collections; |
| 75 | + import java.util.LinkedHashMap; |
| 76 | +@@ -91,6 +92,9 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie |
| 77 | + |
| 78 | + private final CommandLine argv; |
| 79 | + |
| 80 | ++ private final Iterable<Artifact> inputs; |
| 81 | ++ private final Iterable<Artifact> outputs; |
| 82 | ++ |
| 83 | + private final boolean executeUnconditionally; |
| 84 | + private final boolean isShellCommand; |
| 85 | + private final String progressMessage; |
| 86 | +@@ -197,6 +201,9 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie |
| 87 | + this.mnemonic = mnemonic; |
| 88 | + this.executeUnconditionally = executeUnconditionally; |
| 89 | + this.extraActionInfoSupplier = extraActionInfoSupplier; |
| 90 | ++ |
| 91 | ++ this.inputs = inputs; |
| 92 | ++ this.outputs = outputs; |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | +@@ -312,23 +319,89 @@ public class SpawnAction extends AbstractAction implements ExecutionInfoSpecifie |
| 97 | + |
| 98 | + @Override |
| 99 | + protected String computeKey() { |
| 100 | ++ boolean genruleSetup = String.valueOf(Iterables.get(inputs, 0).getExecPath()).contains("genrule/genrule-setup.sh"); |
| 101 | ++ boolean validGenrule = genruleSetup && (Iterables.size(inputs) > 1); |
| 102 | ++ |
| 103 | ++ String genruleScript = null; |
| 104 | ++ if (validGenrule) { |
| 105 | ++ genruleScript = String.valueOf(Iterables.get(inputs, 1).getExecPath()); |
| 106 | ++ } |
| 107 | ++ |
| 108 | ++ // ".ckd" Compute Key Debug |
| 109 | ++ PrintWriter computeKeyDebugWriter = null; |
| 110 | ++ if (validGenrule) { |
| 111 | ++ String computeKeyDebugFile = genruleScript + ".SpawnAction.ckd"; |
| 112 | ++ try { |
| 113 | ++ computeKeyDebugWriter = new PrintWriter(computeKeyDebugFile, "UTF-8"); |
| 114 | ++ } catch (java.io.FileNotFoundException ex) { |
| 115 | ++ System.err.println("Unable to create " + computeKeyDebugFile); |
| 116 | ++ } catch (java.io.UnsupportedEncodingException ex) { |
| 117 | ++ System.err.println("Unsupported encoding"); |
| 118 | ++ } |
| 119 | ++ } |
| 120 | ++ |
| 121 | ++ validGenrule = validGenrule && (computeKeyDebugWriter != null); |
| 122 | ++ |
| 123 | + Fingerprint f = new Fingerprint(); |
| 124 | + f.addString(GUID); |
| 125 | ++ if (validGenrule) { computeKeyDebugWriter.println("GUID: " + GUID); } |
| 126 | ++ |
| 127 | + f.addStrings(argv.arguments()); |
| 128 | ++ if (validGenrule) { |
| 129 | ++ for (String input : argv.arguments()) { |
| 130 | ++ computeKeyDebugWriter.println("ARGUMENTS: " + input); |
| 131 | ++ } |
| 132 | ++ } |
| 133 | ++ |
| 134 | + f.addString(getMnemonic()); |
| 135 | ++ if (validGenrule) { computeKeyDebugWriter.println("MNEMONIC: " + getMnemonic()); } |
| 136 | ++ |
| 137 | + // We don't need the toolManifests here, because they are a subset of the inputManifests by |
| 138 | + // definition and the output of an action shouldn't change whether something is considered a |
| 139 | + // tool or not. |
| 140 | + f.addPaths(getRunfilesSupplier().getRunfilesDirs()); |
| 141 | ++ if (validGenrule) { |
| 142 | ++ for (PathFragment path : getRunfilesSupplier().getRunfilesDirs()) { |
| 143 | ++ computeKeyDebugWriter.println("RUNFILESDIRS: " + path.getPathString()); |
| 144 | ++ } |
| 145 | ++ } |
| 146 | ++ |
| 147 | + ImmutableList<Artifact> runfilesManifests = getRunfilesSupplier().getManifests(); |
| 148 | + f.addInt(runfilesManifests.size()); |
| 149 | ++ if (validGenrule) { computeKeyDebugWriter.println("RUNFILESMANIFESTSSIZE: " + runfilesManifests.size()); } |
| 150 | ++ |
| 151 | + for (Artifact runfilesManifest : runfilesManifests) { |
| 152 | + f.addPath(runfilesManifest.getExecPath()); |
| 153 | ++ if (validGenrule) { computeKeyDebugWriter.println("RUNFILESMANIFEST: " + runfilesManifest.getExecPath().getPathString()); } |
| 154 | + } |
| 155 | ++ |
| 156 | + f.addStringMap(getEnvironment()); |
| 157 | ++ if (validGenrule) { |
| 158 | ++ for (Map.Entry<String, String> entry : getEnvironment().entrySet()) { |
| 159 | ++ computeKeyDebugWriter.println("ENV: " + entry.getKey() + "=" + entry.getValue()); |
| 160 | ++ } |
| 161 | ++ } |
| 162 | ++ |
| 163 | + f.addStrings(getClientEnvironmentVariables()); |
| 164 | ++ if (validGenrule) { |
| 165 | ++ for (String input : argv.arguments()) { |
| 166 | ++ computeKeyDebugWriter.println("CLIENTENV: " + input); |
| 167 | ++ } |
| 168 | ++ } |
| 169 | ++ |
| 170 | + f.addStringMap(getExecutionInfo()); |
| 171 | +- return f.hexDigestAndReset(); |
| 172 | ++ if (validGenrule) { |
| 173 | ++ for (Map.Entry<String, String> entry : executionInfo.entrySet()) { |
| 174 | ++ computeKeyDebugWriter.println("EXECINFO: " + entry.getKey() + "=" + entry.getValue()); |
| 175 | ++ } |
| 176 | ++ } |
| 177 | ++ |
| 178 | ++ String rv = f.hexDigestAndReset(); |
| 179 | ++ if (validGenrule) { |
| 180 | ++ computeKeyDebugWriter.println("KEY: " + rv); |
| 181 | ++ computeKeyDebugWriter.close(); |
| 182 | ++ } |
| 183 | ++ return rv; |
| 184 | + } |
| 185 | + |
| 186 | + @Override |
| 187 | +diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java |
| 188 | +index 3559fffde..3ba39617c 100644 |
| 189 | +--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java |
| 190 | ++++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java |
| 191 | +@@ -1111,10 +1111,30 @@ public class CppCompileAction extends AbstractAction |
| 192 | + |
| 193 | + @Override |
| 194 | + public String computeKey() { |
| 195 | ++ // ".ckd" Compute Key Debug |
| 196 | ++ PrintWriter computeKeyDebugWriter = null; |
| 197 | ++ String computeKeyDebugFile = getInternalOutputFile() + ".CppCompileAction.ckd"; |
| 198 | ++ try { |
| 199 | ++ computeKeyDebugWriter = new PrintWriter(computeKeyDebugFile, "UTF-8"); |
| 200 | ++ } catch (java.io.FileNotFoundException ex) { |
| 201 | ++ System.err.println("Unable to create " + computeKeyDebugFile); |
| 202 | ++ } catch (java.io.UnsupportedEncodingException ex) { |
| 203 | ++ System.err.println("Unsupported encoding"); |
| 204 | ++ } |
| 205 | ++ |
| 206 | + Fingerprint f = new Fingerprint(); |
| 207 | + f.addUUID(actionClassId); |
| 208 | ++ computeKeyDebugWriter.println("UUID: " + actionClassId); |
| 209 | ++ |
| 210 | + f.addStringMap(getEnvironment()); |
| 211 | ++ for (Map.Entry<String, String> entry : getEnvironment().entrySet()) { |
| 212 | ++ computeKeyDebugWriter.println("ENV: " + entry.getKey() + "=" + entry.getValue()); |
| 213 | ++ } |
| 214 | ++ |
| 215 | + f.addStringMap(executionInfo); |
| 216 | ++ for (Map.Entry<String, String> entry : executionInfo.entrySet()) { |
| 217 | ++ computeKeyDebugWriter.println("EXECINFO: " + entry.getKey() + "=" + entry.getValue()); |
| 218 | ++ } |
| 219 | + |
| 220 | + // For the argv part of the cache key, ignore all compiler flags that explicitly denote module |
| 221 | + // file (.pcm) inputs. Depending on input discovery, some of the unused ones are removed from |
| 222 | +@@ -1124,6 +1144,9 @@ public class CppCompileAction extends AbstractAction |
| 223 | + // A better long-term solution would be to make the compiler to find them automatically and |
| 224 | + // never hand in the .pcm files explicitly on the command line in the first place. |
| 225 | + f.addStrings(compileCommandLine.getArgv(getInternalOutputFile(), null)); |
| 226 | ++ for (String input : compileCommandLine.getArgv(getInternalOutputFile(), null)) { |
| 227 | ++ computeKeyDebugWriter.println("COMMAND: " + input); |
| 228 | ++ } |
| 229 | + |
| 230 | + /* |
| 231 | + * getArgv() above captures all changes which affect the compilation |
| 232 | +@@ -1133,19 +1156,31 @@ public class CppCompileAction extends AbstractAction |
| 233 | + * have changed, otherwise we might miss some errors. |
| 234 | + */ |
| 235 | + f.addPaths(context.getDeclaredIncludeDirs()); |
| 236 | ++ for (PathFragment path : context.getDeclaredIncludeDirs()) { |
| 237 | ++ computeKeyDebugWriter.println("DECLAREDINCLUDEDIRS: " + path.getPathString()); |
| 238 | ++ } |
| 239 | + f.addPaths(context.getDeclaredIncludeWarnDirs()); |
| 240 | ++ for (PathFragment path : context.getDeclaredIncludeWarnDirs()) { |
| 241 | ++ computeKeyDebugWriter.println("DECLAREDINCLUDEWARNDIRS: " + path.getPathString()); |
| 242 | ++ } |
| 243 | + for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) { |
| 244 | + f.addPath(declaredIncludeSrc.getExecPath()); |
| 245 | ++ computeKeyDebugWriter.println("DECLAREDINCLUDESRCS: " + declaredIncludeSrc.getExecPath().getPathString()); |
| 246 | + } |
| 247 | + f.addInt(0); // mark the boundary between input types |
| 248 | + for (Artifact input : getMandatoryInputs()) { |
| 249 | + f.addPath(input.getExecPath()); |
| 250 | ++ computeKeyDebugWriter.println("MANDATORYINPUTS: " + input.getExecPath().getPathString()); |
| 251 | + } |
| 252 | + f.addInt(0); |
| 253 | + for (Artifact input : prunableInputs) { |
| 254 | + f.addPath(input.getExecPath()); |
| 255 | ++ computeKeyDebugWriter.println("PRUNABLEINPUTS: " + input.getExecPath().getPathString()); |
| 256 | + } |
| 257 | +- return f.hexDigestAndReset(); |
| 258 | ++ String rv = f.hexDigestAndReset(); |
| 259 | ++ computeKeyDebugWriter.println("KEY: " + rv); |
| 260 | ++ computeKeyDebugWriter.close(); |
| 261 | ++ return rv; |
| 262 | + } |
| 263 | + |
| 264 | + @Override |
0 commit comments