Skip to content

Commit eb4a3b7

Browse files
brad4dcopybara-github
authored andcommitted
Print config more reliably
The config printing was only happening when compile() or compileModules() was called or when executed by AbstractCommandLineRunner::doRun(), but that is sometimes redundant, and sometimes doesn't happen at all. I've moved this action to the end of the `initModules()` method, which must always be executed right before performing a compilation action. This CL also disables debug logging for CompilerTestCase tests by default. Without that part of the change I was having test timeouts for some tests. I believe that was because those tests started wasting time printing out configuration information to debug log files. PiperOrigin-RevId: 552964960
1 parent ebb54d1 commit eb4a3b7

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,10 +1301,6 @@ protected int doRun() throws IOException {
13011301
externs = null;
13021302
sources = null;
13031303

1304-
if (options.printConfig) {
1305-
compiler.printConfig();
1306-
}
1307-
13081304
Result result;
13091305
// We won't want to process results for cases where compilation is only partially done.
13101306
boolean shouldProcessResults = true;

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,14 @@ public void initModules(
758758

759759
initAST();
760760

761+
if (isDebugLoggingEnabled() || options.printConfig) {
762+
// Always print configuration logs when debug logging is enabled.
763+
// NOTE: initModules() is called by every execution path through the compiler code that
764+
// actually performs a compilation action. That's what makes this a good place to put this
765+
// logging.
766+
printConfig();
767+
}
768+
761769
// If debug logging is enabled, write out the module / chunk graph in GraphViz format.
762770
// This graph is often too big to reasonably render.
763771
// Using gvpr(1) is recommended to extract the parts of the graph that are of interest.
@@ -892,9 +900,6 @@ public Result compile(
892900

893901
try {
894902
init(externs, inputs, options);
895-
if (options.printConfig) {
896-
printConfig();
897-
}
898903
if (!hasErrors()) {
899904
parseForCompilation();
900905
}
@@ -951,9 +956,6 @@ public Result compileModules(
951956

952957
try {
953958
initModules(externs, modules, options);
954-
if (options.printConfig) {
955-
printConfig();
956-
}
957959
if (!hasErrors()) {
958960
parseForCompilation();
959961
}

test/com/google/javascript/jscomp/CompilerTestCase.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ protected void tearDown() throws Exception {
726726
*/
727727
protected abstract CompilerPass getProcessor(Compiler compiler);
728728

729+
/** Enable debug logging for this test run */
730+
private boolean debugLoggingEnabled = false;
731+
732+
public void enableDebugLogging(boolean debugLoggingEnabled) {
733+
this.debugLoggingEnabled = debugLoggingEnabled;
734+
}
735+
729736
/**
730737
* Gets the compiler options to use for this test. Use getProcessor to determine what passes
731738
* should be run.
@@ -759,7 +766,9 @@ protected CompilerOptions getOptions() {
759766
}
760767
options.setCodingConvention(getCodingConvention());
761768
options.setPolymerVersion(1);
762-
CompilerTestCaseUtils.setDebugLogDirectoryOn(options);
769+
if (debugLoggingEnabled) {
770+
CompilerTestCaseUtils.setDebugLogDirectoryOn(options);
771+
}
763772

764773
return options;
765774
}

test/com/google/javascript/jscomp/disambiguate/DisambiguatePropertiesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void setUp() throws Exception {
7373
this.enableTypeCheck();
7474
replaceTypesWithColors();
7575
disableCompareJsDoc();
76+
enableDebugLogging(true);
7677
}
7778

7879
@Override

test/com/google/javascript/jscomp/serialization/SerializeTypedAstPassTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void setUp() throws Exception {
6969
enableTypeCheck();
7070
this.typesToForwardDeclare = ImmutableSet.of();
7171
enableSourceInformationAnnotator();
72+
enableDebugLogging(true);
7273
}
7374

7475
@Override

0 commit comments

Comments
 (0)