make/common/JavaCompilation.gmk

Print this page




 547     endif
 548   endif
 549 
 550   # Prep the source paths.
 551   ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),)
 552     $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE)))
 553   else
 554     $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
 555   endif
 556 
 557   # Create a sed expression to remove the source roots and to replace / with .
 558   # and remove .java at the end.
 559   $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
 560 
 561   ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
 562     ifneq (,$$($1_HEADERS))
 563       $1_HEADERS_ARG := -h $$($1_HEADERS)
 564     endif
 565 
 566     # Using sjavac to compile.
 567     $1_COMPILE_TARGETS := $$($1_BIN)/javac_state
 568 
 569     # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
 570     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
 571     # and javac is simply replaced with sjavac.
 572     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
 573 
 574     # Set the $1_REMOTE to spawn a background javac server.
 575     $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
 576 
 577     $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
 578         $(MKDIR) -p $$(@D)




 579         $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
 580         $(ECHO) Compiling $1
 581         ($$($1_JVM) $$($1_SJAVAC) \
 582             $$($1_REMOTE) \
 583             -j 1 \
 584             --permit-unidentified-artifacts \
 585             --permit-sources-without-package \
 586             --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
 587             --log=$(LOG_LEVEL) \
 588             $$($1_SJAVAC_ARGS) \
 589             $$($1_FLAGS) \
 590             $$($1_HEADERS_ARG) \
 591             -d $$($1_BIN) && \
 592         $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
 593         # sjavac doesn't touch this if nothing has changed
 594         $(TOUCH) $$@








 595   else
 596     # Using plain javac to batch compile everything.
 597     $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
 598 
 599     # When building in batch, put headers in a temp dir to filter out those that actually
 600     # changed before copying them to the real header dir.
 601     ifneq (,$$($1_HEADERS))
 602       $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
 603 
 604       $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
 605                 $(MKDIR) -p $$(@D)
 606                 if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
 607                   for f in `ls $$($1_HEADERS).$1.tmp`; do \
 608                     if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
 609                         || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
 610                     $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
 611                   fi; \
 612                   done; \
 613                 fi
 614                 $(RM) -r $$($1_HEADERS).$1.tmp


 664   # Check if a srczip was specified, then setup the rules for the srczip.
 665   ifneq (,$$($1_SRCZIP))
 666     $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
 667         SRC:=$$($1_SRC), \
 668         ZIP:=$$($1_SRCZIP), \
 669         INCLUDES:=$$($1_INCLUDES), \
 670         EXCLUDES:=$$($1_EXCLUDES), \
 671         EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
 672 
 673     # Add zip to target list
 674     $1 += $$($1_SRCZIP)
 675   endif
 676 endef
 677 
 678 # Use this macro to find the correct target to depend on when the original
 679 # SetupJavaCompilation is declared in a different makefile, to avoid having
 680 # to declare and evaluate it again.
 681 # param 1 is for example BUILD_MYPACKAGE
 682 # param 2 is the output directory (BIN)
 683 define SetupJavaCompilationCompileTarget
 684   $(if $(findsring yes, $(ENABLE_SJAVAC)), $(strip $2)/javac_state, \
 685       $(strip $2)/_the.$(strip $1)_batch)
 686 endef
 687 endif


 547     endif
 548   endif
 549 
 550   # Prep the source paths.
 551   ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),)
 552     $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE)))
 553   else
 554     $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
 555   endif
 556 
 557   # Create a sed expression to remove the source roots and to replace / with .
 558   # and remove .java at the end.
 559   $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
 560 
 561   ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
 562     ifneq (,$$($1_HEADERS))
 563       $1_HEADERS_ARG := -h $$($1_HEADERS)
 564     endif
 565 
 566     # Using sjavac to compile.
 567     $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
 568 
 569     # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
 570     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
 571     # and javac is simply replaced with sjavac.
 572     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
 573 
 574     # Set the $1_REMOTE to spawn a background javac server.
 575     $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
 576 
 577     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
 578         $(MKDIR) -p $$(@D)
 579         # As a workaround for sjavac not tracking api from the classpath, force full
 580         # recompile if an external dependency, which is something other than a source
 581         # change, triggered this compilation.
 582         $$(if $$(filter-out $$($1_SRCS), $$?), $(FIND) $$(@D) -name "*.class" $(FIND_DELETE))
 583         $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
 584         $(ECHO) Compiling $1
 585         ($$($1_JVM) $$($1_SJAVAC) \
 586             $$($1_REMOTE) \
 587             -j 1 \
 588             --permit-unidentified-artifacts \
 589             --permit-sources-without-package \
 590             --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
 591             --log=$(LOG_LEVEL) \
 592             $$($1_SJAVAC_ARGS) \
 593             $$($1_FLAGS) \
 594             $$($1_HEADERS_ARG) \
 595             -d $$($1_BIN) && \
 596         $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
 597         # Create a pubapi file that only changes when the pubapi changes. Dependent
 598         # compilations can use this file to only get recompiled when pubapi has changed.
 599         # Grep returns 1 if no matching lines are found. Do not fail for this.
 600         $(GREP) -e "^I" $$($1_BIN)/javac_state > $$($1_BIN)/_the.$1_pubapi.tmp \
 601             || test "$$$$?" = "1"
 602         if [ ! -f $$($1_BIN)/_the.$1_pubapi ] \
 603             || [ "`$(DIFF) $$($1_BIN)/_the.$1_pubapi $$($1_BIN)/_the.$1_pubapi.tmp`" != "" ]; then \
 604           $(MV) $$($1_BIN)/_the.$1_pubapi.tmp $$($1_BIN)/_the.$1_pubapi; \
 605         fi
 606 
 607   else
 608     # Using plain javac to batch compile everything.
 609     $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
 610 
 611     # When building in batch, put headers in a temp dir to filter out those that actually
 612     # changed before copying them to the real header dir.
 613     ifneq (,$$($1_HEADERS))
 614       $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
 615 
 616       $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
 617                 $(MKDIR) -p $$(@D)
 618                 if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
 619                   for f in `ls $$($1_HEADERS).$1.tmp`; do \
 620                     if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
 621                         || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
 622                     $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
 623                   fi; \
 624                   done; \
 625                 fi
 626                 $(RM) -r $$($1_HEADERS).$1.tmp


 676   # Check if a srczip was specified, then setup the rules for the srczip.
 677   ifneq (,$$($1_SRCZIP))
 678     $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
 679         SRC:=$$($1_SRC), \
 680         ZIP:=$$($1_SRCZIP), \
 681         INCLUDES:=$$($1_INCLUDES), \
 682         EXCLUDES:=$$($1_EXCLUDES), \
 683         EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
 684 
 685     # Add zip to target list
 686     $1 += $$($1_SRCZIP)
 687   endif
 688 endef
 689 
 690 # Use this macro to find the correct target to depend on when the original
 691 # SetupJavaCompilation is declared in a different makefile, to avoid having
 692 # to declare and evaluate it again.
 693 # param 1 is for example BUILD_MYPACKAGE
 694 # param 2 is the output directory (BIN)
 695 define SetupJavaCompilationCompileTarget
 696   $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
 697       $(strip $2)/_the.$(strip $1)_batch)
 698 endef
 699 endif