comparison mx/mx_graal_makefile.py @ 21917:0df6a0cb4b5f

Cleanup code in mx_graal_makefile.py, add comments
author Stefan Anzinger <stefan.anzinger@oracle.com>
date Thu, 11 Jun 2015 11:35:27 +0200
parents 3df76a0300f3
children 62da3906ab7f
comparison
equal deleted inserted replaced
21916:3df76a0300f3 21917:0df6a0cb4b5f
76 def update_list(li, elements): 76 def update_list(li, elements):
77 for e in elements: 77 for e in elements:
78 if e not in li: 78 if e not in li:
79 li.append(e) 79 li.append(e)
80 80
81 def make_dist_rule(dist, mf, bootClassPath=None): 81 def make_dist_rule(dist, mf):
82 def path_dist_relative(p): 82 def path_dist_relative(p):
83 return os.path.relpath(p, dist.suite.dir) 83 return os.path.relpath(p, dist.suite.dir)
84 def short_dist_name(name): 84 def short_dist_name(name):
85 return name.replace("COM_ORACLE_", "") 85 return name.replace("COM_ORACLE_", "")
86 shortName = short_dist_name(dist.name) 86 shortName = short_dist_name(dist.name)
127 apDistVariableNames.append("$(" + name + "_JAR)") 127 apDistVariableNames.append("$(" + name + "_JAR)")
128 shouldExport = dist.name in jdkDeployedDists 128 shouldExport = dist.name in jdkDeployedDists
129 props = { 129 props = {
130 "name": shortName, 130 "name": shortName,
131 "jarPath": targetPathPrefix + jarPath, 131 "jarPath": targetPathPrefix + jarPath,
132 "depends": "",
133 "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "", 132 "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "",
134 "depJarsVariable": depJarVariableName, 133 "depJarsVariable": depJarVariableName,
135 "sourceLines": sourceLines, 134 "sourceLines": sourceLines,
136 "sourcesVariableName": sourcesVariableName, 135 "sourcesVariableName": sourcesVariableName,
137 "annotationProcessors": " ".join(apDistVariableNames), 136 "annotationProcessors": " ".join(apDistVariableNames),
138 "cpAnnotationProcessors": "-processorpath " + ":".join(apDistVariableNames) if len(apDistVariableNames) > 0 else "", 137 "cpAnnotationProcessors": ":".join(apDistVariableNames),
139 "cpAnnotationProcessors2": ":".join(apDistVariableNames),
140 "bootCp": ("-bootclasspath " + bootClassPath) if bootClassPath != None else "",
141 "cpDeps": ("-cp $(shell echo $(" + depJarVariableName + ") | tr ' ' ':')") if len(classPath) > 0 else "",
142 "jarDeps": " ".join(classPath), 138 "jarDeps": " ".join(classPath),
143 "copyResources": " ".join(resources), 139 "copyResources": " ".join(resources)
144 "targetPathPrefix": targetPathPrefix,
145 "shouldExport": shouldExport,
146 } 140 }
147 141
148 mf.add_definition(sourceLines) 142 mf.add_definition(sourceLines)
149 mf.add_definition("{name}_JAR = {jarPath}".format(**props)) 143 mf.add_definition("{name}_JAR = {jarPath}".format(**props))
150 if len(classPath) > 0: mf.add_definition("{depJarsVariable} = {jarDeps}".format(**props)) 144 if len(classPath) > 0: mf.add_definition("{depJarsVariable} = {jarDeps}".format(**props))
151 if shouldExport: mf.add_definition("EXPORTED_FILES += $({name}_JAR)".format(**props)) 145 if shouldExport: mf.add_definition("EXPORTED_FILES += $({name}_JAR)".format(**props))
152 mf.add_rule("""$({name}_JAR): $({sourcesVariableName}) {annotationProcessors} {depJarsVariableAccess} 146 mf.add_rule("""$({name}_JAR): $({sourcesVariableName}) {annotationProcessors} {depJarsVariableAccess}
153 \t$(call build_and_jar,{cpAnnotationProcessors2},$(shell echo {depJarsVariableAccess} | tr ' ' ':'),{copyResources},$({name}_JAR)) 147 \t$(call build_and_jar,{cpAnnotationProcessors},$(shell echo {depJarsVariableAccess} | tr ' ' ':'),{copyResources},$({name}_JAR))
154 """.format(**props)) 148 """.format(**props))
155 return 149 return
156 150
157 151
158 152
185 endif 179 endif
186 ifeq ($(MAKE_VERBOSE),) 180 ifeq ($(MAKE_VERBOSE),)
187 QUIETLY=@ 181 QUIETLY=@
188 endif 182 endif
189 183
184 # Takes the option files of the options annotation processor and merges them into a single file
185 # Arguments:
186 # 1: directory with contents of the JAR file
190 define process_options 187 define process_options
191 $(eval providers=$(1)/$(PROVIDERS_INF)) 188 $(eval providers=$(1)/$(PROVIDERS_INF))
192 $(eval services=$(1)/$(SERVICES_INF)) 189 $(eval services=$(1)/$(SERVICES_INF))
193 $(eval options=$(1)/$(OPTIONS_INF)) 190 $(eval options=$(1)/$(OPTIONS_INF))
194 $(QUIETLY) test -d $(services) || mkdir -p $(services) 191 $(QUIETLY) test -d $(services) || mkdir -p $(services)
199 $(eval vmconfig=$(1)/hotspot/HotSpotVMConfig.inline.hpp) 196 $(eval vmconfig=$(1)/hotspot/HotSpotVMConfig.inline.hpp)
200 $(eval vmconfigDest=$(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot) 197 $(eval vmconfigDest=$(HS_COMMON_SRC)/../jvmci/com.oracle.jvmci.hotspot/src_gen/hotspot)
201 $(QUIETLY) test ! -f $(vmconfig) || (mkdir -p $(vmconfigDest) && cp $(vmconfig) $(vmconfigDest)) 198 $(QUIETLY) test ! -f $(vmconfig) || (mkdir -p $(vmconfigDest) && cp $(vmconfig) $(vmconfigDest))
202 endef 199 endef
203 200
201 # Extracts META-INF/services and META-INF/options of a JAR file into a given directory
202 # Arguments:
203 # 1: JAR file to extract
204 # 2: target directory
204 define extract 205 define extract
205 $(eval TMP := $(shell mktemp -d $(TARGET)/tmp_XXXXX)) 206 $(eval TMP := $(shell mktemp -d $(TARGET)/tmp_XXXXX))
206 $(QUIETLY) mkdir -p $(2); 207 $(QUIETLY) mkdir -p $(2);
207 $(QUIETLY) cd $(TMP) && $(JAR) xf $(abspath $(1)) && \\ 208 $(QUIETLY) cd $(TMP) && $(JAR) xf $(abspath $(1)) && \\
208 ((test ! -d .$(SERVICES_INF) || cp -r .$(SERVICES_INF) $(abspath $(2))) && (test ! -d .$(OPTIONS_INF) || cp -r .$(OPTIONS_INF) $(abspath $(2)))); 209 ((test ! -d .$(SERVICES_INF) || cp -r .$(SERVICES_INF) $(abspath $(2))) && (test ! -d .$(OPTIONS_INF) || cp -r .$(OPTIONS_INF) $(abspath $(2))));
209 $(QUIETLY) rm -r $(TMP); 210 $(QUIETLY) rm -r $(TMP);
210 $(QUIETLY) cp $(1) $(2); 211 $(QUIETLY) cp $(1) $(2);
211 endef 212 endef
212 213
214 # Calls $(JAVAC) with the bootclasspath $(JDK_BOOTCLASSPATH); sources are taken from the automatic variable $?
215 # Arguments:
216 # 1: processorpath
217 # 2: classpath
218 # 3: resources to copy
219 # 4: target JAR file
213 define build_and_jar 220 define build_and_jar
214 $(info Building $(4)) 221 $(info Building $(4))
215 $(eval TMP := $(shell mkdir -p $(TARGET) && mktemp -d $(TARGET)/tmp_XXXXX)) 222 $(eval TMP := $(shell mkdir -p $(TARGET) && mktemp -d $(TARGET)/tmp_XXXXX))
216 $(QUIETLY) $(JAVAC) -d $(TMP) -processorpath :$(1) -bootclasspath $(JDK_BOOTCLASSPATH) -cp :$(2) $(filter %.java,$?); 223 $(QUIETLY) $(JAVAC) -d $(TMP) -processorpath :$(1) -bootclasspath $(JDK_BOOTCLASSPATH) -cp :$(2) $(filter %.java,$?);
217 $(QUIETLY) test "$(3)" = "" || cp -r $(3) $(TMP); 224 $(QUIETLY) test "$(3)" = "" || cp -r $(3) $(TMP);
246 apd = d.definedAnnotationProcessorsDist 253 apd = d.definedAnnotationProcessorsDist
247 update_list(ap, [apd]) 254 update_list(ap, [apd])
248 255
249 if len(dists) > 0: 256 if len(dists) > 0:
250 mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath) 257 mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath)
251 bootClassPathVarAccess = "$(" + jdkBootClassPathVariableName + ")" 258 for d in ap: make_dist_rule(d, mf)
252 for d in ap: make_dist_rule(d, mf, bootClassPathVarAccess) 259 for d in dists: make_dist_rule(d, mf)
253 for d in dists: make_dist_rule(d, mf, bootClassPathVarAccess)
254 mf.add_rule("default: $({}_JAR)\n.PHONY: default".format("_JAR) $(".join([d.name for d in dists]))) 260 mf.add_rule("default: $({}_JAR)\n.PHONY: default".format("_JAR) $(".join([d.name for d in dists])))
255 return True 261 return True
256 else: 262 else:
257 for d in dists: 263 for d in dists:
258 selectedDists.remove(d.name) 264 selectedDists.remove(d.name)