Skip to content

Commit 9d74698

Browse files
lauraharkercopybara-github
authored andcommitted
Log "inputs_pruned.json" during parsing when debug logging is enabled
We already log "inputs.json", which includes *all* JS files passed to JSCompiler. Sometimes JSCompiler will prune unreachable input JS files. "inputs_pruned.json" prints only the JS files still present after pruning. Also resolve TODO about using better JSON printing, now that we don't support compiling JSCompiler -> JS via J2CL. PiperOrigin-RevId: 890454847
1 parent 848f929 commit 9d74698

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

src/com/google/javascript/jscomp/Compiler.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.google.errorprone.annotations.CanIgnoreReturnValue;
4242
import com.google.errorprone.annotations.FormatMethod;
4343
import com.google.errorprone.annotations.MustBeClosed;
44+
import com.google.gson.GsonBuilder;
4445
import com.google.javascript.jscomp.CodePrinter.LicenseTracker;
4546
import com.google.javascript.jscomp.CompilerInput.ModuleType;
4647
import com.google.javascript.jscomp.CompilerOptions.DevMode;
@@ -497,13 +498,9 @@ public void printConfig() {
497498
if (this.isDebugLoggingEnabled()) {
498499
// Log to separate files for convenience.
499500
logToFile("externs.log", externs::toString);
500-
// To get a pretty-printed JSON chunk graph, change the string generation expression to
501-
//
502-
// new GsonBuilder().setPrettyPrinting().create().toJson(chunkGraph.toJson())
503-
//
504-
// TODO(bradfordcsmith): Come up with a JSON-printing version that will work when this code is
505-
// compiled with J2CL, so we can permanently improve this.
506-
logToFile("inputs.json", () -> Iterables.toString(chunkGraph.getAllInputs()));
501+
logToFile(
502+
"inputs.json",
503+
new GsonBuilder().setPrettyPrinting().create().toJson(chunkGraph.toJson())::toString);
507504
logToFile("options.log", () -> options.toString());
508505
logToFile("warningsGuard.log", () -> warningsGuard.toString());
509506
} else {
@@ -512,21 +509,22 @@ public void printConfig() {
512509
err.println("==== Externs ====");
513510
err.println(externs);
514511
err.println("==== Inputs ====");
515-
// To get a pretty-printed JSON chunk graph, change this line to
516-
//
517-
// err.println(
518-
// new GsonBuilder().setPrettyPrinting().create().toJson(chunkGraph.toJson()));
519-
//
520-
// TODO(bradfordcsmith): Come up with a JSON-printing version that will work when this code is
521-
// compiled with J2CL, so we can permanently improve this.
522-
err.println(Iterables.toString(chunkGraph.getAllInputs()));
512+
err.println(new GsonBuilder().setPrettyPrinting().create().toJson(chunkGraph.toJson()));
523513
err.println("==== CompilerOptions ====");
524514
err.println(options);
525515
err.println("==== WarningsGuard ====");
526516
err.println(warningsGuard);
527517
}
528518
}
529519

520+
private void maybeLogPrunedInputs() {
521+
if (this.isDebugLoggingEnabled()) {
522+
logToFile(
523+
"inputs_pruned.json",
524+
new GsonBuilder().setPrettyPrinting().create().toJson(chunkGraph.toJson())::toString);
525+
}
526+
}
527+
530528
private void logToFile(String logFileName, Supplier<String> logStringSupplier) {
531529
try (LogFile log = this.createOrReopenLog(this.getClass(), logFileName)) {
532530
log.log(logStringSupplier);
@@ -2290,6 +2288,7 @@ void orderInputs() {
22902288
if (staleInputs) {
22912289
repartitionInputs();
22922290
}
2291+
maybeLogPrunedInputs();
22932292
}
22942293

22952294
/**

src/com/google/javascript/jscomp/JSChunkGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public final class JSChunkGraph implements Serializable {
9696
*
9797
* <p>If the cache returns null, then the entry hasn't been filled in for that chunk.
9898
*
99-
* <p>NOTE: JSChunk has identity semantics so this map implementation is safe
99+
* <p>NOTE: JSChunk has identity semantics so this map implementation is safe.
100100
*/
101-
private final LinkedIdentityHashMap<JSChunk, Set<JSChunk>> dependencyMap =
101+
private final transient LinkedIdentityHashMap<JSChunk, Set<JSChunk>> dependencyMap =
102102
new LinkedIdentityHashMap<>();
103103

104104
/** Creates a chunk graph from a list of chunks in dependency order. */

0 commit comments

Comments
 (0)