Mercurial > hg > graal-jvmci-8
comparison mx.jvmci/mx_jvmci_makefile.py @ 22176:fb1a9390cdcf
fixed mx_jvmci_makefile.py
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 21 Jul 2015 01:53:46 +0200 |
parents | f9ddf6b6dd6b |
children | 706aa848a8d7 |
comparison
equal
deleted
inserted
replaced
22175:c09467f52cf7 | 22176:fb1a9390cdcf |
---|---|
50 parser = ArgumentParser(prog='mx makefile') | 50 parser = ArgumentParser(prog='mx makefile') |
51 parser.add_argument('-o', action='store', dest='output', help='Write contents to this file.') | 51 parser.add_argument('-o', action='store', dest='output', help='Write contents to this file.') |
52 parser.add_argument('selectedDists', help="Selected distribution names which are going to be built with make.", nargs=REMAINDER) | 52 parser.add_argument('selectedDists', help="Selected distribution names which are going to be built with make.", nargs=REMAINDER) |
53 opts = parser.parse_args(args) | 53 opts = parser.parse_args(args) |
54 | 54 |
55 if opts.selectedDists == None or len(opts.selectedDists) == 0: | 55 if not opts.selectedDists: |
56 opts.selectedDists = [d.name for d in mx_jvmci.jdkDeployedDists if d.partOfHotSpot] | 56 opts.selectedDists = [d.name for d in mx_jvmci.jdkDeployedDists if d.partOfHotSpot] |
57 mf = Makefile() | 57 mf = Makefile() |
58 commandline = " ".join(["mx.sh", "makefile"] + args) | 58 commandline = " ".join(["mx.sh", "makefile"] + args) |
59 if do_build_makefile(mf, opts.selectedDists, commandline): | 59 if do_build_makefile(mf, opts.selectedDists, commandline): |
60 contents = mf.generate() | 60 contents = mf.generate() |
63 else: | 63 else: |
64 if mx.update_file(opts.output, contents, showDiff=True): | 64 if mx.update_file(opts.output, contents, showDiff=True): |
65 return 1 | 65 return 1 |
66 return 0 | 66 return 0 |
67 | 67 |
68 def short_dist_name(name): | |
69 return name.replace("COM_ORACLE_", "") | |
70 | |
71 def filter_projects(deps, t): | |
72 def typeFilter(project): # filters | |
73 if isinstance(project, str): | |
74 project = mx.dependency(project, True) | |
75 return isinstance(project, t) | |
76 return [d for d in deps if typeFilter(d)] | |
77 | |
78 def get_jdk_deployed_dists(): | 68 def get_jdk_deployed_dists(): |
79 return [d.name for d in mx_jvmci.jdkDeployedDists] | 69 return [d.name for d in mx_jvmci.jdkDeployedDists] |
80 | |
81 def update_list(li, elements): | |
82 for e in elements: | |
83 if e not in li: | |
84 li.append(e) | |
85 | 70 |
86 def make_dist_rule(dist, mf): | 71 def make_dist_rule(dist, mf): |
87 def path_dist_relative(p): | 72 def path_dist_relative(p): |
88 return os.path.relpath(p, dist.suite.dir) | 73 return os.path.relpath(p, dist.suite.dir) |
89 shortName = short_dist_name(dist.name) | |
90 jdkDeployedDists = get_jdk_deployed_dists() | 74 jdkDeployedDists = get_jdk_deployed_dists() |
91 jarName = os.path.basename(dist.path) | 75 jarName = os.path.basename(dist.path) |
92 sourcesVariableName = shortName + "_SRC" | 76 sourcesVariableName = dist.name + "_SRC" |
93 depJarVariableName = shortName + "_DEP_JARS" | 77 depJarVariableName = dist.name + "_DEP_JARS" |
94 sources = [] | 78 sources = [] |
95 resources = [] | 79 resources = [] |
96 sortedDeps = dist.sorted_deps(True, transitive=False, includeAnnotationProcessors=True) | 80 projects = [p for p in dist.archived_deps() if p.isJavaProject()] |
97 projects = filter_projects(sortedDeps, mx.Project) | |
98 targetPathPrefix = "$(TARGET)/" | 81 targetPathPrefix = "$(TARGET)/" |
99 libraryDeps = [path_dist_relative(l.get_path(False)) for l in filter_projects(sortedDeps, mx.Library)] | 82 libraryDeps = [path_dist_relative(l.get_path(False)) for l in [l for l in dist.archived_deps() if l.isLibrary()]] |
100 | 83 |
101 annotationProcessorDeps = [] | 84 annotationProcessorDeps = set() |
102 distDeps = dist.get_dist_deps(includeSelf=False, transitive=True) | 85 distDeps = [dep for dep in dist.deps if dep.isDistribution()] |
103 distDepProjects = [] | |
104 for d in distDeps: | |
105 update_list(distDepProjects, d.sorted_deps(includeLibs=False, transitive=True)) | |
106 | 86 |
107 classPath = [targetPathPrefix + os.path.basename(d.path) for d in distDeps] + libraryDeps \ | 87 classPath = [targetPathPrefix + os.path.basename(d.path) for d in distDeps] + libraryDeps \ |
108 + [path_dist_relative(mx.dependency(name).path) for name in dist.excludedDependencies] | 88 + [path_dist_relative(exclLib.path) for exclLib in dist.excludedLibs] |
109 for p in projects: | |
110 if p.definedAnnotationProcessors != None and p.definedAnnotationProcessorsDist != dist: | |
111 update_list(annotationProcessorDeps, [p]) | |
112 for p in projects: | 89 for p in projects: |
113 projectDir = path_dist_relative(p.dir) | 90 projectDir = path_dist_relative(p.dir) |
114 if p not in distDepProjects and p not in annotationProcessorDeps: | 91 annotationProcessorDeps.update(p.declaredAnnotationProcessors) |
115 for src in [projectDir + '/' + d for d in p.srcDirs]: | 92 for src in [projectDir + '/' + d for d in p.srcDirs]: |
116 sources.append("$(shell find {} -type f 2> /dev/null)".format(src)) | 93 sources.append("$(shell find {} -type f 2> /dev/null)".format(src)) |
117 metaInf = src + "/META-INF" | 94 metaInf = src + "/META-INF" |
118 if os.path.exists(os.path.join(dist.suite.dir, metaInf)): | 95 if os.path.exists(os.path.join(dist.suite.dir, metaInf)): |
119 resources.append(metaInf) | 96 resources.append(metaInf) |
120 | |
121 | 97 |
122 sourceLines = sourcesVariableName + " = " + ("\n" + sourcesVariableName + " += ").join(sources) | 98 sourceLines = sourcesVariableName + " = " + ("\n" + sourcesVariableName + " += ").join(sources) |
123 apPaths = [] | 99 apPaths = [] |
124 apDistNames = [] | 100 apDistNames = [] |
125 apDistVariableNames = [] | 101 apDistVariableNames = [] |
126 for p in annotationProcessorDeps: | 102 for apd in sorted(annotationProcessorDeps): |
127 apPaths.append(path_dist_relative(p.definedAnnotationProcessorsDist.path)) | 103 apPaths.append(path_dist_relative(apd.path)) |
128 name = short_dist_name(p.definedAnnotationProcessorsDist.name) | 104 apDistNames.append(apd.name) |
129 apDistNames.append(name) | 105 apDistVariableNames.append("$(" + apd.name + "_JAR)") |
130 apDistVariableNames.append("$(" + name + "_JAR)") | |
131 shouldExport = dist.name in jdkDeployedDists | 106 shouldExport = dist.name in jdkDeployedDists |
132 props = { | 107 props = { |
133 "name": shortName, | 108 "name": dist.name, |
134 "jarName": targetPathPrefix + jarName, | 109 "jarName": targetPathPrefix + jarName, |
135 "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "", | 110 "depJarsVariableAccess": "$(" + depJarVariableName + ")" if len(classPath) > 0 else "", |
136 "depJarsVariable": depJarVariableName, | 111 "depJarsVariable": depJarVariableName, |
137 "sourceLines": sourceLines, | 112 "sourceLines": sourceLines, |
138 "sourcesVariableName": sourcesVariableName, | 113 "sourcesVariableName": sourcesVariableName, |
278 \t$(QUIETLY) rm $(JARS) 2> /dev/null || true | 253 \t$(QUIETLY) rm $(JARS) 2> /dev/null || true |
279 \t$(QUIETLY) rmdir -p $(dir $(JARS)) 2> /dev/null || true | 254 \t$(QUIETLY) rmdir -p $(dir $(JARS)) 2> /dev/null || true |
280 .PHONY: export clean | 255 .PHONY: export clean |
281 | 256 |
282 """) | 257 """) |
283 s = mx_jvmci._suite | 258 assert selectedDists |
259 selectedDists = [mx.dependency(s) for s in selectedDists] | |
284 dists = [] | 260 dists = [] |
285 ap = [] | 261 |
286 projects = [] | 262 def _visit(dep, edge): |
287 for d in s.dists: | 263 if dep.isDistribution(): |
288 if d.name in selectedDists: | 264 dists.append(dep) |
289 update_list(dists, d.get_dist_deps(True, True)) | 265 |
290 update_list(projects, d.sorted_deps(includeLibs=False, transitive=True)) | 266 mx.walk_deps(roots=selectedDists, visit=_visit, ignoredEdges=[mx.DEP_EXCLUDED]) |
291 | 267 |
292 for p in projects: | 268 mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath) |
293 deps = p.all_deps([], False, includeSelf=True, includeJreLibs=False, includeAnnotationProcessors=True) | 269 for dist in dists: make_dist_rule(dist, mf) |
294 for d in deps: | 270 mf.add_definition("DISTRIBUTIONS = " + ' '.join([dist.name for dist in dists])) |
295 if d.definedAnnotationProcessorsDist is not None: | 271 mf.add_rule("default: $({}_JAR)\n.PHONY: default\n".format("_JAR) $(".join([d.name for d in selectedDists]))) |
296 apd = d.definedAnnotationProcessorsDist | 272 return True |
297 update_list(ap, [apd]) | |
298 | |
299 if len(dists) > 0: | |
300 mf.add_definition(jdkBootClassPathVariableName + " = " + bootClassPath) | |
301 for d in ap: make_dist_rule(d, mf) | |
302 for d in dists: make_dist_rule(d, mf) | |
303 mf.add_definition("DISTRIBUTIONS = " + " ".join([short_dist_name(d.name) for d in dists+ap])) | |
304 mf.add_rule("default: $({}_JAR)\n.PHONY: default\n".format("_JAR) $(".join([short_dist_name(d.name) for d in dists]))) | |
305 return True | |
306 else: | |
307 for d in dists: | |
308 selectedDists.remove(d.name) | |
309 print "Distribution(s) '" + "', '".join(selectedDists) + "' does not exist." |