Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 22041:56c50504d60d
mx: removed JVMCI code from Distribution.make_archive
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 20 Jun 2015 12:37:01 +0200 |
parents | 434fbaaf53d7 |
children | db48a62aba36 |
comparison
equal
deleted
inserted
replaced
22040:0751fdae4e7a | 22041:56c50504d60d |
---|---|
125 self.path = path.replace('/', os.sep) | 125 self.path = path.replace('/', os.sep) |
126 self.path = _make_absolute(self.path, suite.dir) | 126 self.path = _make_absolute(self.path, suite.dir) |
127 self.sourcesPath = _make_absolute(sourcesPath.replace('/', os.sep), suite.dir) if sourcesPath else None | 127 self.sourcesPath = _make_absolute(sourcesPath.replace('/', os.sep), suite.dir) if sourcesPath else None |
128 self.deps = deps | 128 self.deps = deps |
129 self.update_listeners = set() | 129 self.update_listeners = set() |
130 self.archiveparticipant = None | |
130 self.mainClass = mainClass | 131 self.mainClass = mainClass |
131 self.excludedDependencies = excludedDependencies | 132 self.excludedDependencies = excludedDependencies |
132 self.distDependencies = distDependencies | 133 self.distDependencies = distDependencies |
133 self.javaCompliance = JavaCompliance(javaCompliance) if javaCompliance else None | 134 self.javaCompliance = JavaCompliance(javaCompliance) if javaCompliance else None |
134 self.isProcessorDistribution = isProcessorDistribution | 135 self.isProcessorDistribution = isProcessorDistribution |
149 def __str__(self): | 150 def __str__(self): |
150 return self.name | 151 return self.name |
151 | 152 |
152 def add_update_listener(self, listener): | 153 def add_update_listener(self, listener): |
153 self.update_listeners.add(listener) | 154 self.update_listeners.add(listener) |
155 | |
156 def set_archiveparticipant(self, archiveparticipant): | |
157 """ | |
158 Adds an object that participates in the make_archive method of this distribution by defining the following methods: | |
159 | |
160 __opened__(arc, srcArc, services) | |
161 Called when archiving starts. The 'arc' and 'srcArc' Archiver objects are for writing to the | |
162 binary and source jars for the distribution. The 'services' dict is for collating the files | |
163 that will be written to META-INF/services in the binary jar. It's a map from service names | |
164 to a list of providers for the named service. | |
165 __add__(arcname, contents) | |
166 Submits an entry for addition to the binary archive (via the 'zf' ZipFile field of the 'arc' object). | |
167 Returns True if this object writes to the archive or wants to exclude the entry from the archive, | |
168 False if the caller should add the entry. | |
169 __addsrc__(arcname, contents) | |
170 Same as __add__ except if targets the source archive. | |
171 __closing__() | |
172 Called just before the 'services' are written to the binary archive and both archives are | |
173 written to their underlying files. | |
174 """ | |
175 self.archiveparticipant = archiveparticipant | |
154 | 176 |
155 def get_dist_deps(self, includeSelf=True, transitive=False): | 177 def get_dist_deps(self, includeSelf=True, transitive=False): |
156 deps = [] | 178 deps = [] |
157 if includeSelf: | 179 if includeSelf: |
158 deps.append(self) | 180 deps.append(self) |
188 | 210 |
189 with Archiver(self.path) as arc: | 211 with Archiver(self.path) as arc: |
190 with Archiver(None if unified else self.sourcesPath) as srcArcRaw: | 212 with Archiver(None if unified else self.sourcesPath) as srcArcRaw: |
191 srcArc = arc if unified else srcArcRaw | 213 srcArc = arc if unified else srcArcRaw |
192 services = {} | 214 services = {} |
193 jvmciServices = {} | 215 |
216 if self.archiveparticipant: | |
217 self.archiveparticipant.__opened__(arc, srcArc, services) | |
218 | |
194 def overwriteCheck(zf, arcname, source): | 219 def overwriteCheck(zf, arcname, source): |
195 if os.path.basename(arcname).startswith('.'): | 220 if os.path.basename(arcname).startswith('.'): |
196 logv('Excluding dotfile: ' + source) | 221 logv('Excluding dotfile: ' + source) |
197 return True | 222 return True |
198 if not hasattr(zf, '_provenance'): | 223 if not hasattr(zf, '_provenance'): |
235 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/': | 260 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/': |
236 service = arcname[len('META-INF/services/'):] | 261 service = arcname[len('META-INF/services/'):] |
237 assert '/' not in service | 262 assert '/' not in service |
238 services.setdefault(service, []).extend(lp.read(arcname).splitlines()) | 263 services.setdefault(service, []).extend(lp.read(arcname).splitlines()) |
239 else: | 264 else: |
240 assert not arcname.startswith('META-INF/jvmci.services/'), 'did not expect to see jvmci.services in ' + lpath | |
241 assert not arcname.startswith('META-INF/jvmci.options/'), 'did not expect to see jvmci.options in ' + lpath | |
242 if not overwriteCheck(arc.zf, arcname, lpath + '!' + arcname): | 265 if not overwriteCheck(arc.zf, arcname, lpath + '!' + arcname): |
243 arc.zf.writestr(arcname, lp.read(arcname)) | 266 contents = lp.read(arcname) |
267 if not self.archiveparticipant or not self.archiveparticipant.__add__(arcname, contents): | |
268 arc.zf.writestr(arcname, contents) | |
244 if srcArc.zf and libSourcePath: | 269 if srcArc.zf and libSourcePath: |
245 with zipfile.ZipFile(libSourcePath, 'r') as lp: | 270 with zipfile.ZipFile(libSourcePath, 'r') as lp: |
246 for arcname in lp.namelist(): | 271 for arcname in lp.namelist(): |
247 if not overwriteCheck(srcArc.zf, arcname, lpath + '!' + arcname): | 272 if not overwriteCheck(srcArc.zf, arcname, lpath + '!' + arcname): |
248 srcArc.zf.writestr(arcname, lp.read(arcname)) | 273 contents = lp.read(arcname) |
274 if not self.archiveparticipant or not self.archiveparticipant.__addsrc__(arcname, contents): | |
275 srcArc.zf.writestr(arcname, contents) | |
249 elif dep.isProject(): | 276 elif dep.isProject(): |
250 p = dep | 277 p = dep |
251 | 278 |
252 if self.javaCompliance: | 279 if self.javaCompliance: |
253 if p.javaCompliance > self.javaCompliance: | 280 if p.javaCompliance > self.javaCompliance: |
259 relpath = root[len(outputDir) + 1:] | 286 relpath = root[len(outputDir) + 1:] |
260 if relpath == join('META-INF', 'services'): | 287 if relpath == join('META-INF', 'services'): |
261 for service in files: | 288 for service in files: |
262 with open(join(root, service), 'r') as fp: | 289 with open(join(root, service), 'r') as fp: |
263 services.setdefault(service, []).extend([provider.strip() for provider in fp.readlines()]) | 290 services.setdefault(service, []).extend([provider.strip() for provider in fp.readlines()]) |
264 elif relpath == join('META-INF', 'jvmci.services'): | |
265 for service in files: | |
266 with open(join(root, service), 'r') as fp: | |
267 jvmciServices.setdefault(service, []).extend([provider.strip() for provider in fp.readlines()]) | |
268 elif relpath == join('META-INF', 'jvmci.providers'): | |
269 for provider in files: | |
270 with open(join(root, provider), 'r') as fp: | |
271 for service in fp: | |
272 jvmciServices.setdefault(service.strip(), []).append(provider) | |
273 else: | 291 else: |
274 if relpath == join('META-INF', 'jvmci.options'): | |
275 # Need to create service files for the providers of the | |
276 # com.oracle.jvmci.options.Options service created by | |
277 # com.oracle.jvmci.options.processor.OptionProcessor. | |
278 for optionsOwner in files: | |
279 provider = optionsOwner + '_Options' | |
280 providerClassfile = join(outputDir, provider.replace('.', os.sep) + '.class') | |
281 assert exists(providerClassfile), 'missing generated Options provider ' + providerClassfile | |
282 services.setdefault('com.oracle.jvmci.options.Options', []).append(provider) | |
283 for f in files: | 292 for f in files: |
284 arcname = join(relpath, f).replace(os.sep, '/') | 293 arcname = join(relpath, f).replace(os.sep, '/') |
285 if not overwriteCheck(arc.zf, arcname, join(root, f)): | 294 with open(join(root, f), 'r') as fp: |
286 arc.zf.write(join(root, f), arcname) | 295 contents = fp.read() |
296 if not self.archiveparticipant or not self.archiveparticipant.__add__(arcname, contents): | |
297 arc.zf.writestr(arcname, contents) | |
287 if srcArc.zf: | 298 if srcArc.zf: |
288 sourceDirs = p.source_dirs() | 299 sourceDirs = p.source_dirs() |
289 if p.source_gen_dir(): | 300 if p.source_gen_dir(): |
290 sourceDirs.append(p.source_gen_dir()) | 301 sourceDirs.append(p.source_gen_dir()) |
291 for srcDir in sourceDirs: | 302 for srcDir in sourceDirs: |
293 relpath = root[len(srcDir) + 1:] | 304 relpath = root[len(srcDir) + 1:] |
294 for f in files: | 305 for f in files: |
295 if f.endswith('.java'): | 306 if f.endswith('.java'): |
296 arcname = join(relpath, f).replace(os.sep, '/') | 307 arcname = join(relpath, f).replace(os.sep, '/') |
297 if not overwriteCheck(srcArc.zf, arcname, join(root, f)): | 308 if not overwriteCheck(srcArc.zf, arcname, join(root, f)): |
298 srcArc.zf.write(join(root, f), arcname) | 309 with open(join(root, f), 'r') as fp: |
310 contents = fp.read() | |
311 if not self.archiveparticipant or not self.archiveparticipant.__addsrc__(arcname, contents): | |
312 srcArc.zf.writestr(arcname, contents) | |
313 | |
314 if self.archiveparticipant: | |
315 self.archiveparticipant.__closing__() | |
299 | 316 |
300 for service, providers in services.iteritems(): | 317 for service, providers in services.iteritems(): |
301 arcname = 'META-INF/services/' + service | 318 arcname = 'META-INF/services/' + service |
302 arc.zf.writestr(arcname, '\n'.join(providers)) | |
303 for service, providers in jvmciServices.iteritems(): | |
304 arcname = 'META-INF/jvmci.services/' + service | |
305 arc.zf.writestr(arcname, '\n'.join(providers)) | 319 arc.zf.writestr(arcname, '\n'.join(providers)) |
306 | 320 |
307 self.notify_updated() | 321 self.notify_updated() |
308 | 322 |
309 def notify_updated(self): | 323 def notify_updated(self): |