common/makefiles/JavaCompilation.gmk

Print this page




  25 
  26 # This makefile is much simpler now that it can use the smart javac wrapper
  27 # for dependency tracking between java packages and incremental compiles.
  28 # It could be even more simple if we added support for incremental jar updates
  29 # directly from the smart javac wrapper.
  30 
  31 # Cleaning/copying properties here is not a good solution. The properties
  32 # should be cleaned/copied by a annotation processor in sjavac.
  33 
  34 # When you read this source. Remember that $(sort ...) has the side effect
  35 # of removing duplicates. It is actually this side effect that is
  36 # desired whenever sort is used below!
  37 
  38 ifeq  (,$(_MAKEBASE_GMK))
  39     $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
  40 endif
  41 
  42 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
  43 
  44 define SetupJavaCompiler
  45     # param 1 is for example BOOT_JAVAC or NEW_JAVAC
  46     # This is the name later used to decide which java compiler to use.
  47     # param 2-9 are named args.
  48     #   JVM:=The jvm used to run the javac/javah command
  49     #   JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
  50     #   FLAGS:=Flags to be supplied to javac
  51     #   SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
  52     #   SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
  53     $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
  54     $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
  55     $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
  56 
  57     # The port file contains the tcp/ip on which the server listens
  58     # and the cookie necessary to talk to the server.
  59     $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
  60     # You can use a different JVM to run the background javac server.
  61     ifeq ($$($1_SERVER_JVM),)
  62         # It defaults to the same JVM that is used to start the javac command.
  63         $1_SERVER_JVM:=$$($1_JVM)
  64     endif
  65 endef
  66 


 470 
 471     # Prep the source paths.
 472     ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),)
 473       $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE)))
 474     else
 475       $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
 476     endif
 477 
 478     # Create a sed expression to remove the source roots and to replace / with .
 479     # and remove .java at the end. 
 480     $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
 481 
 482     ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
 483         ifneq (,$$($1_HEADERS))
 484             $1_HEADERS_ARG := -h $$($1_HEADERS)
 485         endif
 486 
 487         # Using sjavac to compile. 
 488         $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state
 489 
 490         # Create SJAVAC variable,
 491         # expects $1_JAVAC to be "bootclasspathprepend -jar ...javac.jar"
 492         # and it is rewritten into "bootclasspathprepend com.sun.tools.sjavac.Main"
 493         $1_SJAVAC:=$$(word 1,$$($1_JAVAC)) -cp $$(word 3,$$($1_JAVAC)) com.sun.tools.sjavac.Main
 494 
 495         # Set the $1_REMOTE to spawn a background javac server.
 496         $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
 497 
 498         $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
 499                 $(MKDIR) -p $$(@D)
 500                 $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
 501                 $(ECHO) Compiling $1
 502                 ($$($1_JVM) $$($1_SJAVAC) \
 503                         $$($1_REMOTE) \
 504                         -j $(NUM_CORES) \
 505                         --permit-unidentified-artifacts \
 506                         --permit-sources-without-package \
 507                         --compare-found-sources $$($1_BIN)/_the.batch.tmp \
 508                         --log=$(LOG) \
 509                         $$($1_SJAVAC_ARGS) \
 510                         $$($1_FLAGS) \
 511                         $$($1_HEADERS_ARG) \
 512                         -d $$($1_BIN) && \
 513                         $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch)




  25 
  26 # This makefile is much simpler now that it can use the smart javac wrapper
  27 # for dependency tracking between java packages and incremental compiles.
  28 # It could be even more simple if we added support for incremental jar updates
  29 # directly from the smart javac wrapper.
  30 
  31 # Cleaning/copying properties here is not a good solution. The properties
  32 # should be cleaned/copied by a annotation processor in sjavac.
  33 
  34 # When you read this source. Remember that $(sort ...) has the side effect
  35 # of removing duplicates. It is actually this side effect that is
  36 # desired whenever sort is used below!
  37 
  38 ifeq  (,$(_MAKEBASE_GMK))
  39     $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
  40 endif
  41 
  42 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
  43 
  44 define SetupJavaCompiler
  45     # param 1 is for example GENERATE_OLD_BYTECODE or GENERATE_NEW_JDKBYTECODE
  46     # This is the name of the compiler setup.
  47     # param 2-9 are named args.
  48     #   JVM:=The jvm used to run the javac/javah command
  49     #   JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
  50     #   FLAGS:=Flags to be supplied to javac
  51     #   SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
  52     #   SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
  53     $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
  54     $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
  55     $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
  56 
  57     # The port file contains the tcp/ip on which the server listens
  58     # and the cookie necessary to talk to the server.
  59     $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
  60     # You can use a different JVM to run the background javac server.
  61     ifeq ($$($1_SERVER_JVM),)
  62         # It defaults to the same JVM that is used to start the javac command.
  63         $1_SERVER_JVM:=$$($1_JVM)
  64     endif
  65 endef
  66 


 470 
 471     # Prep the source paths.
 472     ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),)
 473       $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE)))
 474     else
 475       $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
 476     endif
 477 
 478     # Create a sed expression to remove the source roots and to replace / with .
 479     # and remove .java at the end. 
 480     $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
 481 
 482     ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
 483         ifneq (,$$($1_HEADERS))
 484             $1_HEADERS_ARG := -h $$($1_HEADERS)
 485         endif
 486 
 487         # Using sjavac to compile. 
 488         $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state
 489 
 490         # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be 
 491         # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
 492         # and javac is simply replaced with sjavac.
 493         $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
 494 
 495         # Set the $1_REMOTE to spawn a background javac server.
 496         $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
 497 
 498         $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
 499                 $(MKDIR) -p $$(@D)
 500                 $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
 501                 $(ECHO) Compiling $1
 502                 ($$($1_JVM) $$($1_SJAVAC) \
 503                         $$($1_REMOTE) \
 504                         -j $(NUM_CORES) \
 505                         --permit-unidentified-artifacts \
 506                         --permit-sources-without-package \
 507                         --compare-found-sources $$($1_BIN)/_the.batch.tmp \
 508                         --log=$(LOG) \
 509                         $$($1_SJAVAC_ARGS) \
 510                         $$($1_FLAGS) \
 511                         $$($1_HEADERS_ARG) \
 512                         -d $$($1_BIN) && \
 513                         $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch)