comparison mx/mx_graal_makefile.py @ 21790:6db6070d30b9

Make jvmci.make stable; add header for building the jvmci.make; default to use the jvmci.make file when running mx.build
author Stefan Anzinger <stefan.anzinger@oracle.com>
date Fri, 05 Jun 2015 16:28:19 +0200
parents 6c3c21d9b5ef
children 44bad469bec2
comparison
equal deleted inserted replaced
21789:5b9adb645217 21790:6db6070d30b9
46 def build_makefile(args): 46 def build_makefile(args):
47 """Creates a Makefile which is able to build distributions without mx""" 47 """Creates a Makefile which is able to build distributions without mx"""
48 parser = ArgumentParser(prog='mx makefile') 48 parser = ArgumentParser(prog='mx makefile')
49 parser.add_argument('-o', action='store', dest='output', help='Write contents to this file.') 49 parser.add_argument('-o', action='store', dest='output', help='Write contents to this file.')
50 parser.add_argument('selectedDists', help="Selected distribution names which are going to be built with make.", nargs=REMAINDER) 50 parser.add_argument('selectedDists', help="Selected distribution names which are going to be built with make.", nargs=REMAINDER)
51 args = parser.parse_args(args) 51 opts = parser.parse_args(args)
52 52
53 if args.selectedDists == None or len(args.selectedDists) == 0: 53 if opts.selectedDists == None or len(opts.selectedDists) == 0:
54 args.selectedDists = [d.name for d in mx_graal._jdkDeployedDists if d.partOfHotSpot] 54 opts.selectedDists = [d.name for d in mx_graal._jdkDeployedDists if d.partOfHotSpot]
55 mf = Makefile() 55 mf = Makefile()
56 if do_build_makefile(mf, args.selectedDists): 56 commandline = " ".join(["mx.sh", "makefile"] + args)
57 if do_build_makefile(mf, opts.selectedDists, commandline):
57 contents = mf.generate() 58 contents = mf.generate()
58 if args.output == None: 59 if opts.output == None:
59 print contents 60 print contents
60 else: 61 else:
61 with open(args.output, "w") as f: 62 with open(opts.output, "w") as f:
62 f.write(contents) 63 f.write(contents)
63 64
64 65
65 def filter_projects(deps, t): 66 def filter_projects(deps, t):
66 def typeFilter(project): # filters 67 def typeFilter(project): # filters
70 return [d for d in deps if typeFilter(d)] 71 return [d for d in deps if typeFilter(d)]
71 72
72 def get_jdk_deployed_dists(): 73 def get_jdk_deployed_dists():
73 return [d.name for d in mx_graal._jdkDeployedDists] 74 return [d.name for d in mx_graal._jdkDeployedDists]
74 75
76 def update_list(li, elements):
77 for e in elements:
78 if e not in li:
79 li.append(e)
80
75 def make_dist_rule(dist, mf, bootClassPath=None): 81 def make_dist_rule(dist, mf, bootClassPath=None):
76 def path_dist_relative(p): 82 def path_dist_relative(p):
77 return os.path.relpath(p, dist.suite.dir) 83 return os.path.relpath(p, dist.suite.dir)
84 def short_dist_name(name):
85 return name.replace("COM_ORACLE_", "")
86 shortName = short_dist_name(dist.name)
78 jdkDeployedDists = get_jdk_deployed_dists() 87 jdkDeployedDists = get_jdk_deployed_dists()
79 jarPath = path_dist_relative(dist.path) 88 jarPath = path_dist_relative(dist.path)
80 sourcesVariableName = dist.name + "_SRC" 89 sourcesVariableName = shortName + "_SRC"
81 depJarVariableName = dist.name + "_DEP_JARS" 90 depJarVariableName = shortName + "_DEP_JARS"
82 sources = [] 91 sources = []
83 resources = [] 92 resources = []
84 sortedDeps = dist.sorted_deps(True, transitive=False, includeAnnotationProcessors=True) 93 sortedDeps = dist.sorted_deps(True, transitive=False, includeAnnotationProcessors=True)
85 projects = filter_projects(sortedDeps, mx.Project) 94 projects = filter_projects(sortedDeps, mx.Project)
86 targetPathPrefix = "$(TARGET)" + os.path.sep 95 targetPathPrefix = "$(TARGET)" + os.path.sep
87 libraryDeps = [path_dist_relative(l.get_path(False)) for l in filter_projects(sortedDeps, mx.Library)] 96 libraryDeps = [path_dist_relative(l.get_path(False)) for l in filter_projects(sortedDeps, mx.Library)]
88 97
89 annotationProcessorDeps = set() 98 annotationProcessorDeps = []
90 distDeps = dist.get_dist_deps(includeSelf=False, transitive=True) 99 distDeps = dist.get_dist_deps(includeSelf=False, transitive=True)
91 distDepProjects = set() 100 distDepProjects = []
92 for d in distDeps: 101 for d in distDeps:
93 distDepProjects.update(d.sorted_deps(includeLibs=False, transitive=True)) 102 update_list(distDepProjects, d.sorted_deps(includeLibs=False, transitive=True))
94 103
95 classPath = [targetPathPrefix + path_dist_relative(d.path) for d in distDeps] + libraryDeps \ 104 classPath = [targetPathPrefix + path_dist_relative(d.path) for d in distDeps] + libraryDeps \
96 + [path_dist_relative(mx.dependency(name).path) for name in dist.excludedDependencies] 105 + [path_dist_relative(mx.dependency(name).path) for name in dist.excludedDependencies]
97 for p in projects: 106 for p in projects:
98 if p.definedAnnotationProcessors != None and p.definedAnnotationProcessorsDist != dist: 107 if p.definedAnnotationProcessors != None and p.definedAnnotationProcessorsDist != dist:
99 annotationProcessorDeps.add(p) 108 update_list(annotationProcessorDeps, [p])
100 for p in projects: 109 for p in projects:
101 projectDir = path_dist_relative(p.dir) 110 projectDir = path_dist_relative(p.dir)
102 if p not in distDepProjects and p not in annotationProcessorDeps: 111 if p not in distDepProjects and p not in annotationProcessorDeps:
103 generatedSource = [path_dist_relative(p.source_gen_dir())] if len(annotationProcessorDeps) > 0 else [] 112 generatedSource = [path_dist_relative(p.source_gen_dir())] if len(annotationProcessorDeps) > 0 else []
104 113
114 apPaths = [] 123 apPaths = []
115 apDistNames = [] 124 apDistNames = []
116 apDistVariableNames = [] 125 apDistVariableNames = []
117 for p in annotationProcessorDeps: 126 for p in annotationProcessorDeps:
118 apPaths.append(path_dist_relative(p.definedAnnotationProcessorsDist.path)) 127 apPaths.append(path_dist_relative(p.definedAnnotationProcessorsDist.path))
119 name = p.definedAnnotationProcessorsDist.name 128 name = short_dist_name(p.definedAnnotationProcessorsDist.name)
120 apDistNames.append(name) 129 apDistNames.append(name)
121 apDistVariableNames.append("$(" + name + "_JAR)") 130 apDistVariableNames.append("$(" + name + "_JAR)")
122 shouldExport = dist.name in jdkDeployedDists 131 shouldExport = dist.name in jdkDeployedDists
123 props = { 132 props = {
124 "name": dist.name, 133 "name": shortName,
125 "jarPath": targetPathPrefix + jarPath, 134 "jarPath": targetPathPrefix + jarPath,
126 "depends": "", 135 "depends": "",
127 "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "", 136 "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "",
128 "depJarsVariable": depJarVariableName, 137 "depJarsVariable": depJarVariableName,
129 "sourceLines": sourceLines, 138 "sourceLines": sourceLines,
130 "sourcesVariableName": sourcesVariableName, 139 "sourcesVariableName": sourcesVariableName,
131 "annotationProcessors": " ".join(apDistVariableNames), 140 "annotationProcessors": " ".join(apDistVariableNames),
132 "cpAnnotationProcessors": "-processorpath " + ":".join(apDistVariableNames) if len(apDistVariableNames) > 0 else "", 141 "cpAnnotationProcessors": "-processorpath " + ":".join(apDistVariableNames) if len(apDistVariableNames) > 0 else "",
133 "bootCp": ("-bootclasspath " + bootClassPath) if bootClassPath != None else "", 142 "bootCp": ("-bootclasspath " + bootClassPath) if bootClassPath != None else "",
134 "cpDeps": ("-cp " + ":".join(classPath)) if len(classPath) > 0 else "", 143 "cpDeps": ("-cp $(shell echo $(" + depJarVariableName + ") | tr ' ' ':')") if len(classPath) > 0 else "",
135 "jarDeps": " ".join(classPath), 144 "jarDeps": " ".join(classPath),
136 "copyResources": "cp -r {} $(TMP)".format(" ".join(resources)) if len(resources) > 0 else "", 145 "copyResources": "cp -r {} $(TMP)".format(" ".join(resources)) if len(resources) > 0 else "",
137 "targetPathPrefix": targetPathPrefix, 146 "targetPathPrefix": targetPathPrefix,
138 "shouldExport": shouldExport, 147 "shouldExport": shouldExport,
139 } 148 }
152 \trm -r $(TMP)""".format(**props)) 161 \trm -r $(TMP)""".format(**props))
153 return 162 return
154 163
155 164
156 165
157 def do_build_makefile(mf, selectedDists): 166 def do_build_makefile(mf, selectedDists, commandline):
158 java = mx.java() 167 java = mx.java()
159 bootClassPath = java.bootclasspath() 168 bootClassPath = java.bootclasspath()
160 bootClassPath = bootClassPath.replace(java.jdk, "$(JDK)") 169 bootClassPath = bootClassPath.replace(java.jdk, "$(ABS_BOOTDIR)")
161 jdkBootClassPathVariableName = "JDK_BOOTCLASSPATH" 170 jdkBootClassPathVariableName = "JDK_BOOTCLASSPATH"
162 171
163 mf.add_definition("""VERBOSE= 172 mf.add_definition("""# This Makefile is generated automatically, do not edit
173 # This file was build with command: """ + commandline + """
174
175 VERBOSE=
164 TARGET=. 176 TARGET=.
165 JDK= 177 # Bootstrap JDK to be used (for javac and jar)
166 178 ABS_BOOTDIR=
167 WGET=wget 179
168 JAVAC=$(JDK)/bin/javac -g -target """ + str(java.javaCompliance) + """ 180 JAVAC=$(ABS_BOOTDIR)/bin/javac -g -target """ + str(java.javaCompliance) + """
169 JAR=$(JDK)/bin/jar 181 JAR=$(ABS_BOOTDIR)/bin/jar
170 182
171 EXPORT_DIR=export 183 EXPORT_DIR=export
172 EXPORTED_FILES_ADDITIONAL=$(TARGET)/options $(TARGET)/services 184 EXPORTED_FILES_ADDITIONAL=$(TARGET)/options $(TARGET)/services
173 HS_COMMON_SRC=. 185 HS_COMMON_SRC=.
174 # where all other stuff built by mx (graal.jar) resides 186
175 MX_TARGET=. 187 # Directories, where the generated property-files reside within the JAR files
176 PROVIDERS_INF=/META-INF/providers/ 188 PROVIDERS_INF=/META-INF/providers/
177 SERVICES_INF=/META-INF/services/ 189 SERVICES_INF=/META-INF/services/
178 OPTIONS_INF=/META-INF/options/ 190 OPTIONS_INF=/META-INF/options/
179 191
180 ifeq ($(JDK),) 192 ifeq ($(ABS_BOOTDIR),)
181 $(error Variable JDK must be set to a JDK installation.) 193 $(error Variable ABS_BOOTDIR must be set to a JDK installation.)
182 endif 194 endif
183 ifneq ($(VERBOSE),) 195 ifneq ($(VERBOSE),)
184 SHELL=sh -x 196 SHELL=sh -x
185 endif 197 endif
186 198
187 define process_options = 199 define process_options =
188 $(eval providers=$(1)/$(PROVIDERS_INF)) 200 $(eval providers=$(1)/$(PROVIDERS_INF))
214 \t$(foreach export,$(EXPORTED_FILES),$(call extract,$(export),$(EXPORT_DIR))) 226 \t$(foreach export,$(EXPORTED_FILES),$(call extract,$(export),$(EXPORT_DIR)))
215 .PHONY: export 227 .PHONY: export
216 228
217 """) 229 """)
218 s = mx.suite("graal") 230 s = mx.suite("graal")
219 dists = set() 231 dists = []
220 ap = set() 232 ap = []
221 projects = set() 233 projects = []
222 for d in s.dists: 234 for d in s.dists:
223 if d.name in selectedDists: 235 if d.name in selectedDists:
224 dists.update(d.get_dist_deps(True, True)) 236 update_list(dists, d.get_dist_deps(True, True))
225 projects.update(d.sorted_deps(includeLibs=False, transitive=True)) 237 update_list(projects, d.sorted_deps(includeLibs=False, transitive=True))
226 238
227 for p in projects: 239 for p in projects:
228 deps = p.all_deps([], False, includeSelf=True, includeJreLibs=False, includeAnnotationProcessors=True) 240 deps = p.all_deps([], False, includeSelf=True, includeJreLibs=False, includeAnnotationProcessors=True)
229 for d in deps: 241 for d in deps:
230 if d.definedAnnotationProcessorsDist != None: 242 if d.definedAnnotationProcessorsDist != None:
231 apd = d.definedAnnotationProcessorsDist 243 apd = d.definedAnnotationProcessorsDist
232 ap.add(apd) 244 update_list(ap, [apd])
233 245
234 if len(dists) > 0: 246 if len(dists) > 0:
235 mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath) 247 mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath)
236 bootClassPathVarAccess = "$(" + jdkBootClassPathVariableName + ")" 248 bootClassPathVarAccess = "$(" + jdkBootClassPathVariableName + ")"
237 for d in ap: make_dist_rule(d, mf, bootClassPathVarAccess) 249 for d in ap: make_dist_rule(d, mf, bootClassPathVarAccess)