Mercurial > hg > truffle
comparison mxtool/mx.py @ 14937:3de340bdb8d3
added support for adding sources to distribution
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 02 Apr 2014 10:04:27 +0200 |
parents | 31a9c79399c8 |
children | dd5095578b79 |
comparison
equal
deleted
inserted
replaced
14936:159b21f41915 | 14937:3de340bdb8d3 |
---|---|
59 | 59 |
60 """ | 60 """ |
61 A distribution is a jar or zip file containing the output from one or more Java projects. | 61 A distribution is a jar or zip file containing the output from one or more Java projects. |
62 """ | 62 """ |
63 class Distribution: | 63 class Distribution: |
64 def __init__(self, suite, name, path, deps, excludedLibs): | 64 def __init__(self, suite, name, path, sourcesPath, deps, excludedLibs): |
65 self.suite = suite | 65 self.suite = suite |
66 self.name = name | 66 self.name = name |
67 self.path = path.replace('/', os.sep) | 67 self.path = path.replace('/', os.sep) |
68 self.sourcesPath = sourcesPath.replace('/', os.sep) if sourcesPath else None | |
68 if not isabs(self.path): | 69 if not isabs(self.path): |
69 self.path = join(suite.dir, self.path) | 70 self.path = join(suite.dir, self.path) |
70 self.deps = deps | 71 self.deps = deps |
71 self.update_listeners = set() | 72 self.update_listeners = set() |
72 self.excludedLibs = excludedLibs | 73 self.excludedLibs = excludedLibs |
619 l.__dict__.update(attrs) | 620 l.__dict__.update(attrs) |
620 self.libs.append(l) | 621 self.libs.append(l) |
621 | 622 |
622 for name, attrs in distsMap.iteritems(): | 623 for name, attrs in distsMap.iteritems(): |
623 path = attrs.pop('path') | 624 path = attrs.pop('path') |
625 sourcesPath = attrs.pop('sourcesPath', None) | |
624 deps = pop_list(attrs, 'dependencies') | 626 deps = pop_list(attrs, 'dependencies') |
625 exclLibs = pop_list(attrs, 'excludeLibs') | 627 exclLibs = pop_list(attrs, 'excludeLibs') |
626 d = Distribution(self, name, path, deps, exclLibs) | 628 d = Distribution(self, name, path, sourcesPath, deps, exclLibs) |
627 d.__dict__.update(attrs) | 629 d.__dict__.update(attrs) |
628 self.dists.append(d) | 630 self.dists.append(d) |
629 | 631 |
630 if self.name is None: | 632 if self.name is None: |
631 abort('Missing "suite=<name>" in ' + projectsFile) | 633 abort('Missing "suite=<name>" in ' + projectsFile) |
2166 for name in args.names: | 2168 for name in args.names: |
2167 if name.startswith('@'): | 2169 if name.startswith('@'): |
2168 dname = name[1:] | 2170 dname = name[1:] |
2169 d = distribution(dname) | 2171 d = distribution(dname) |
2170 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) | 2172 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) |
2173 if d.sourcesPath: | |
2174 sourcesFd, sourcesTmp = tempfile.mkstemp(suffix='', prefix=basename(d.sourcesPath) + '.', dir=dirname(d.sourcesPath)) | |
2175 else: | |
2176 sourcesTmp = None | |
2171 services = tempfile.mkdtemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) | 2177 services = tempfile.mkdtemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) |
2172 | 2178 |
2173 def overwriteCheck(zf, arcname, source): | 2179 def overwriteCheck(zf, arcname, source): |
2174 if arcname in zf.namelist(): | 2180 if arcname in zf.namelist(): |
2175 log('warning: ' + d.path + ': overwriting ' + arcname + ' [source: ' + source + ']') | 2181 log('warning: ' + d.path + ': overwriting ' + arcname + ' [source: ' + source + ']') |
2176 | 2182 |
2177 try: | 2183 try: |
2178 zf = zipfile.ZipFile(tmp, 'w') | 2184 zf = zipfile.ZipFile(tmp, 'w') |
2185 szf = zipfile.ZipFile(sourcesTmp, 'w') if sourcesTmp else None | |
2179 for dep in d.sorted_deps(includeLibs=True): | 2186 for dep in d.sorted_deps(includeLibs=True): |
2180 if dep.isLibrary(): | 2187 if dep.isLibrary(): |
2181 l = dep | 2188 l = dep |
2182 # merge library jar into distribution jar | 2189 # merge library jar into distribution jar |
2183 logv('[' + d.path + ': adding library ' + l.name + ']') | 2190 logv('[' + d.path + ': adding library ' + l.name + ']') |
2184 lpath = l.get_path(resolve=True) | 2191 lpath = l.get_path(resolve=True) |
2192 libSourcePath = l.get_source_path(resolve=True) | |
2185 if lpath: | 2193 if lpath: |
2186 with zipfile.ZipFile(lpath, 'r') as lp: | 2194 with zipfile.ZipFile(lpath, 'r') as lp: |
2187 for arcname in lp.namelist(): | 2195 for arcname in lp.namelist(): |
2188 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/': | 2196 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/': |
2189 f = arcname[len('META-INF/services/'):].replace('/', os.sep) | 2197 f = arcname[len('META-INF/services/'):].replace('/', os.sep) |
2191 for line in lp.read(arcname).splitlines(): | 2199 for line in lp.read(arcname).splitlines(): |
2192 outfile.write(line) | 2200 outfile.write(line) |
2193 else: | 2201 else: |
2194 overwriteCheck(zf, arcname, lpath + '!' + arcname) | 2202 overwriteCheck(zf, arcname, lpath + '!' + arcname) |
2195 zf.writestr(arcname, lp.read(arcname)) | 2203 zf.writestr(arcname, lp.read(arcname)) |
2204 if szf and libSourcePath: | |
2205 with zipfile.ZipFile(libSourcePath, 'r') as lp: | |
2206 for arcname in lp.namelist(): | |
2207 overwriteCheck(szf, arcname, lpath + '!' + arcname) | |
2208 szf.writestr(arcname, lp.read(arcname)) | |
2196 else: | 2209 else: |
2197 p = dep | 2210 p = dep |
2198 # skip a Java project if its Java compliance level is "higher" than the configured JDK | 2211 # skip a Java project if its Java compliance level is "higher" than the configured JDK |
2199 jdk = java(p.javaCompliance) | 2212 jdk = java(p.javaCompliance) |
2200 if not jdk: | 2213 if not jdk: |
2220 else: | 2233 else: |
2221 for f in files: | 2234 for f in files: |
2222 arcname = join(relpath, f).replace(os.sep, '/') | 2235 arcname = join(relpath, f).replace(os.sep, '/') |
2223 overwriteCheck(zf, arcname, join(root, f)) | 2236 overwriteCheck(zf, arcname, join(root, f)) |
2224 zf.write(join(root, f), arcname) | 2237 zf.write(join(root, f), arcname) |
2238 if szf: | |
2239 for srcDir in p.source_dirs(): | |
2240 for root, _, files in os.walk(srcDir): | |
2241 relpath = root[len(srcDir) + 1:] | |
2242 for f in files: | |
2243 if f.endswith('.java'): | |
2244 arcname = join(relpath, f).replace(os.sep, '/') | |
2245 overwriteCheck(szf, arcname, join(root, f)) | |
2246 szf.write(join(root, f), arcname) | |
2247 | |
2225 for f in os.listdir(services): | 2248 for f in os.listdir(services): |
2226 arcname = join('META-INF', 'services', f).replace(os.sep, '/') | 2249 arcname = join('META-INF', 'services', f).replace(os.sep, '/') |
2227 zf.write(join(services, f), arcname) | 2250 zf.write(join(services, f), arcname) |
2228 zf.close() | 2251 zf.close() |
2229 os.close(fd) | 2252 os.close(fd) |
2231 # Atomic on Unix | 2254 # Atomic on Unix |
2232 shutil.move(tmp, d.path) | 2255 shutil.move(tmp, d.path) |
2233 # Correct the permissions on the temporary file which is created with restrictive permissions | 2256 # Correct the permissions on the temporary file which is created with restrictive permissions |
2234 os.chmod(d.path, 0o666 & ~currentUmask) | 2257 os.chmod(d.path, 0o666 & ~currentUmask) |
2235 archives.append(d.path) | 2258 archives.append(d.path) |
2236 # print time.time(), 'move:', tmp, '->', d.path | 2259 |
2260 if szf: | |
2261 szf.close() | |
2262 os.close(sourcesFd) | |
2263 shutil.move(sourcesTmp, d.sourcesPath) | |
2264 os.chmod(d.sourcesPath, 0o666 & ~currentUmask) | |
2265 | |
2237 d.notify_updated() | 2266 d.notify_updated() |
2238 finally: | 2267 finally: |
2239 if exists(tmp): | 2268 if exists(tmp): |
2240 os.remove(tmp) | 2269 os.remove(tmp) |
2241 if exists(services): | 2270 if exists(services): |
3258 if name == 'item': | 3287 if name == 'item': |
3259 if ps.current_ws is None: | 3288 if ps.current_ws is None: |
3260 target.element(name, attributes) | 3289 target.element(name, attributes) |
3261 elif not attributes.has_key('elementID') and attributes.has_key('factoryID') and attributes.has_key('path') and attributes.has_key('type'): | 3290 elif not attributes.has_key('elementID') and attributes.has_key('factoryID') and attributes.has_key('path') and attributes.has_key('type'): |
3262 target.element(name, attributes) | 3291 target.element(name, attributes) |
3263 p_name = attributes['path'][1:] # strip off the leading '/' | 3292 p_name = attributes['path'][1:] # strip off the leading '/' |
3264 ps.seen_projects.append(p_name) | 3293 ps.seen_projects.append(p_name) |
3265 else: | 3294 else: |
3266 p_name = attributes['elementID'][1:] # strip off the leading '=' | 3295 p_name = attributes['elementID'][1:] # strip off the leading '=' |
3267 _workingset_element(target, p_name) | 3296 _workingset_element(target, p_name) |
3268 ps.seen_projects.append(p_name) | 3297 ps.seen_projects.append(p_name) |