please review fix for 7116322, enhance javac make rule with a little bit of instrumentation

Stuart Marks stuart.marks at oracle.com
Tue Nov 29 04:00:23 UTC 2011



On 11/28/11 7:00 PM, David Holmes wrote:
> On 29/11/2011 10:42 AM, Stuart Marks wrote:
>> Please review this change to add to the javac make rule some messages
>> about the number of files being compiled, the current working directory,
>> and a new message to demarcate the end of javac output.
>>
>> This will help capture and analyze javac output, in particular, warning
>> messages.
>> diff -r 6fbd69f8e3ab make/common/Rules.gmk
>> --- a/make/common/Rules.gmk Fri Nov 18 09:03:43 2011 +0000
>> +++ b/make/common/Rules.gmk Mon Nov 28 16:34:34 2011 -0800
>> @@ -236,9 +236,10 @@
>> @if [ `$(CAT) $<.filtered | $(WC) -l` -ge 1 ] ; then \
>> $(ECHO) "# Java sources to be compiled: (listed in file $<)"; \
>> $(CAT) $<.filtered; \
>> - $(ECHO) "# Running javac:"; \
>> + $(ECHO) "# Running javac: `$(WC) -l < $<.filtered` files; in `pwd`"; \
>
> Can we do this without running wc a second time?
>
> Also shouldn't the current working directory be known from when the current
> sub-dir is entered by make?

We can store the result of wc in a shell variable, but it has to be part of the 
same command as the if-statement that uses it, since successive lines of a make 
rule are executed by different shells. I've done this; see below.

The current directory can probably be deduced, but it's not as simple as 
tracking the current subdirectory. Often the current directory is arrived at 
after having left a subdirectory. For example, this rule is invoked after this 
fragment of enter/leave messages from make have occurred:

make[2]: Entering directory `/home/smarks/src/jdk8-jdk/make/java/java'
make[3]: Entering directory `/home/smarks/src/jdk8-jdk/make/java/nio'
make[3]: Leaving directory `/home/smarks/src/jdk8-jdk/make/java/nio'

The current directory is now ..../make/java/java which isn't from the most 
recent "Entering" message, nor is it the parent of the most recent "Leaving" 
message. In this case make/java/java/Makefile calls a recursive make in 
../nio! So, a script would have to track all the enter/leave messages and keep 
a stack of directories entered and left in order to determine the current one. 
I could enhance the parsing scripts to do this, but it seems complex and 
error-prone.

If you're concerned about build performance, it *might* save a fork to replace 
a call to `pwd` with a make variable reference to $(CURDIR). The wc refactoring 
also saves a fork of the cat command. (Though I admit I don't know whether 
these actually speed things up or whether any change is measurable.)

Revised diff below. Note that I've indented the entire if-statement as well as 
its contents, which is why so many more lines are changed.

s'marks



diff -r 6fbd69f8e3ab make/common/Rules.gmk
--- a/make/common/Rules.gmk     Fri Nov 18 09:03:43 2011 +0000
+++ b/make/common/Rules.gmk     Mon Nov 28 19:40:34 2011 -0800
@@ -233,13 +233,15 @@
         @$(MKDIR) -p $(CLASSDESTDIR)
         @$(RM) $<.filtered
         @$(CAT) $< | $(NAWK) 'length>0' | $(SORT) -u > $<.filtered
-       @if [ `$(CAT) $<.filtered | $(WC) -l` -ge 1 ] ; then \
-         $(ECHO) "# Java sources to be compiled: (listed in file $<)"; \
-         $(CAT) $<.filtered; \
-         $(ECHO) "# Running javac:"; \
-         $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) 
@$<.filtered; \
-         $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) 
@$<.filtered; \
-       fi
+       @numfiles=`$(WC) -l < $<.filtered` ; \
+         if [ $$numfiles -ge 1 ] ; then \
+           $(ECHO) "# Java sources to be compiled: (listed in file $<)"; \
+           $(CAT) $<.filtered; \
+           $(ECHO) "# Running javac: $$numfiles files; in $(CURDIR)"; \
+           $(ECHO) $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) 
@$<.filtered; \
+           $(JAVAC_CMD) -sourcepath "$(SOURCEPATH)" -d $(CLASSDESTDIR) 
@$<.filtered; \
+           $(ECHO) "# javac finished"; \
+         fi
         @$(java-vm-cleanup)

  clobber clean::



More information about the build-dev mailing list