Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 17233:a02c295218aa
mx: add support for cygwin
* use `cygpath' to translate paths
* pay attention when passing paths from unix world to windows world (e.g., when calling out to `javac')
* adapt _runInDebugShell to avoid quoting issues
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Fri, 26 Sep 2014 04:53:13 -0700 |
parents | ca13853abf0d |
children | fa8210d2ff06 |
comparison
equal
deleted
inserted
replaced
17226:5b8f316bdb9e | 17233:a02c295218aa |
---|---|
637 return self.jar == other.jar | 637 return self.jar == other.jar |
638 else: | 638 else: |
639 return NotImplemented | 639 return NotImplemented |
640 | 640 |
641 def is_present_in_jdk(self, jdk): | 641 def is_present_in_jdk(self, jdk): |
642 for e in jdk.bootclasspath().split(os.pathsep): | 642 return jdk.containsJar(self.jar) |
643 if basename(e) == self.jar: | |
644 return True | |
645 for d in jdk.extdirs().split(os.pathsep): | |
646 if len(d) and self.jar in os.listdir(d): | |
647 return True | |
648 for d in jdk.endorseddirs().split(os.pathsep): | |
649 if len(d) and self.jar in os.listdir(d): | |
650 return True | |
651 return False | |
652 | 643 |
653 def all_deps(self, deps, includeLibs, includeSelf=True, includeJreLibs=False, includeAnnotationProcessors=False): | 644 def all_deps(self, deps, includeLibs, includeSelf=True, includeJreLibs=False, includeAnnotationProcessors=False): |
654 """ | 645 """ |
655 Add the transitive set of dependencies for this JRE library to the 'deps' list. | 646 Add the transitive set of dependencies for this JRE library to the 'deps' list. |
656 """ | 647 """ |
1335 return 'darwin' | 1326 return 'darwin' |
1336 elif sys.platform.startswith('linux'): | 1327 elif sys.platform.startswith('linux'): |
1337 return 'linux' | 1328 return 'linux' |
1338 elif sys.platform.startswith('sunos'): | 1329 elif sys.platform.startswith('sunos'): |
1339 return 'solaris' | 1330 return 'solaris' |
1340 elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): | 1331 elif sys.platform.startswith('win32'): |
1341 return 'windows' | 1332 return 'windows' |
1333 elif sys.platform.startswith('cygwin'): | |
1334 return 'cygwin' | |
1342 else: | 1335 else: |
1343 abort('Unknown operating system ' + sys.platform) | 1336 abort('Unknown operating system ' + sys.platform) |
1337 | |
1338 def _tpU2W(p): | |
1339 """ | |
1340 Translate a path from unix-style to windows-style | |
1341 """ | |
1342 if p is None or get_os() != "cygwin": | |
1343 return p | |
1344 return subprocess.check_output(['cygpath', '-w', p]).strip() | |
1345 | |
1346 def _tpW2U(p): | |
1347 """ | |
1348 Translate a path from windows-style to unix-style | |
1349 """ | |
1350 if p is None or get_os() != "cygwin": | |
1351 return p | |
1352 return subprocess.check_output(['cygpath', '-u', p]).strip() | |
1353 | |
1354 def _tspU2W(p): | |
1355 """ | |
1356 Translate a group of paths, seperated by a path seperator. | |
1357 unix-style to windows-style. | |
1358 """ | |
1359 if p is None or p == "" or get_os() != "cygwin": | |
1360 return p | |
1361 return ';'.join(map(_tpU2W, p.split(os.pathsep))) | |
1362 | |
1363 def _tspW2U(p): | |
1364 """ | |
1365 Translate a group of paths, seperated by a path seperator. | |
1366 windows-style to unix-style. | |
1367 """ | |
1368 if p is None or p == "" or get_os() != "cygwin": | |
1369 return p | |
1370 return os.pathsep.join(map(_tpW2U, p.split(';'))) | |
1344 | 1371 |
1345 def get_arch(): | 1372 def get_arch(): |
1346 machine = platform.uname()[4] | 1373 machine = platform.uname()[4] |
1347 if machine in ['amd64', 'AMD64', 'x86_64', 'i86pc']: | 1374 if machine in ['amd64', 'AMD64', 'x86_64', 'i86pc']: |
1348 return 'amd64' | 1375 return 'amd64' |
1528 else: | 1555 else: |
1529 result = distsCp | 1556 result = distsCp |
1530 | 1557 |
1531 if includeBootClasspath: | 1558 if includeBootClasspath: |
1532 result = os.pathsep.join([java().bootclasspath(), result]) | 1559 result = os.pathsep.join([java().bootclasspath(), result]) |
1533 return result | 1560 |
1561 return _tspU2W(result) | |
1534 | 1562 |
1535 def classpath_walk(names=None, resolve=True, includeSelf=True, includeBootClasspath=False): | 1563 def classpath_walk(names=None, resolve=True, includeSelf=True, includeBootClasspath=False): |
1536 """ | 1564 """ |
1537 Walks the resources available in a given classpath, yielding a tuple for each resource | 1565 Walks the resources available in a given classpath, yielding a tuple for each resource |
1538 where the first member of the tuple is a directory path or ZipFile object for a | 1566 where the first member of the tuple is a directory path or ZipFile object for a |
1996 | 2024 |
1997 def __cmp__(self, other): | 2025 def __cmp__(self, other): |
1998 return cmp(self.parts, other.parts) | 2026 return cmp(self.parts, other.parts) |
1999 | 2027 |
2000 def _filter_non_existant_paths(paths): | 2028 def _filter_non_existant_paths(paths): |
2001 return os.pathsep.join([path for path in paths.split(os.pathsep) if exists(path)]) | 2029 return os.pathsep.join([path for path in _tspW2U(paths).split(os.pathsep) if exists(path)]) |
2002 | 2030 |
2003 """ | 2031 """ |
2004 A JavaConfig object encapsulates info on how Java commands are run. | 2032 A JavaConfig object encapsulates info on how Java commands are run. |
2005 """ | 2033 """ |
2006 class JavaConfig: | 2034 class JavaConfig: |
2061 outDir = join(dirname(__file__), '.jdk' + str(self.version)) | 2089 outDir = join(dirname(__file__), '.jdk' + str(self.version)) |
2062 if not exists(outDir): | 2090 if not exists(outDir): |
2063 os.makedirs(outDir) | 2091 os.makedirs(outDir) |
2064 javaSource = join(myDir, 'ClasspathDump.java') | 2092 javaSource = join(myDir, 'ClasspathDump.java') |
2065 if not exists(join(outDir, 'ClasspathDump.class')): | 2093 if not exists(join(outDir, 'ClasspathDump.class')): |
2066 subprocess.check_call([self.javac, '-d', outDir, javaSource], stderr=subprocess.PIPE, stdout=subprocess.PIPE) | 2094 subprocess.check_call([self.javac, '-d', _tpU2W(outDir), _tpU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
2067 self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', outDir, 'ClasspathDump'], stderr=subprocess.PIPE).split('|')] | 2095 self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', _tspU2W(outDir), 'ClasspathDump'], stderr=subprocess.PIPE).split('|')] |
2068 if not self._bootclasspath or not self._extdirs or not self._endorseddirs: | 2096 if not self._bootclasspath or not self._extdirs or not self._endorseddirs: |
2069 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'") | 2097 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'") |
2070 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath) | 2098 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath) |
2071 self._extdirs = _filter_non_existant_paths(self._extdirs) | 2099 self._extdirs = _filter_non_existant_paths(self._extdirs) |
2072 self._endorseddirs = _filter_non_existant_paths(self._endorseddirs) | 2100 self._endorseddirs = _filter_non_existant_paths(self._endorseddirs) |
2089 return self.java_args_pfx + self.java_args + self.java_args_sfx + args | 2117 return self.java_args_pfx + self.java_args + self.java_args_sfx + args |
2090 | 2118 |
2091 def bootclasspath(self): | 2119 def bootclasspath(self): |
2092 if self._bootclasspath is None: | 2120 if self._bootclasspath is None: |
2093 self._init_classpaths() | 2121 self._init_classpaths() |
2094 return self._bootclasspath | 2122 return _tspU2W(self._bootclasspath) |
2095 | 2123 |
2096 def extdirs(self): | 2124 def extdirs(self): |
2097 if self._extdirs is None: | 2125 if self._extdirs is None: |
2098 self._init_classpaths() | 2126 self._init_classpaths() |
2099 return self._extdirs | 2127 return _tspU2W(self._extdirs) |
2100 | 2128 |
2101 def endorseddirs(self): | 2129 def endorseddirs(self): |
2102 if self._endorseddirs is None: | 2130 if self._endorseddirs is None: |
2103 self._init_classpaths() | 2131 self._init_classpaths() |
2104 return self._endorseddirs | 2132 return _tspU2W(self._endorseddirs) |
2133 | |
2134 def containsJar(self, jar): | |
2135 if self._bootclasspath is None: | |
2136 self._init_classpaths() | |
2137 | |
2138 for e in self._bootclasspath.split(os.pathsep): | |
2139 if basename(e) == self.jar: | |
2140 return True | |
2141 for d in self._extdirs.split(os.pathsep): | |
2142 if len(d) and self.jar in os.listdir(d): | |
2143 return True | |
2144 for d in self._endorseddirs.split(os.pathsep): | |
2145 if len(d) and self.jar in os.listdir(d): | |
2146 return True | |
2147 return False | |
2105 | 2148 |
2106 def check_get_env(key): | 2149 def check_get_env(key): |
2107 """ | 2150 """ |
2108 Gets an environment variable, aborting with a useful message if it is not set. | 2151 Gets an environment variable, aborting with a useful message if it is not set. |
2109 """ | 2152 """ |
2230 | 2273 |
2231 myDir = dirname(__file__) | 2274 myDir = dirname(__file__) |
2232 javaSource = join(myDir, 'URLConnectionDownload.java') | 2275 javaSource = join(myDir, 'URLConnectionDownload.java') |
2233 javaClass = join(myDir, 'URLConnectionDownload.class') | 2276 javaClass = join(myDir, 'URLConnectionDownload.class') |
2234 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): | 2277 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): |
2235 subprocess.check_call([java().javac, '-d', myDir, javaSource]) | 2278 subprocess.check_call([java().javac, '-d', _tpU2W(myDir), _tpU2W(javaSource)]) |
2236 verbose = [] | 2279 verbose = [] |
2237 if sys.stderr.isatty(): | 2280 if sys.stderr.isatty(): |
2238 verbose.append("-v") | 2281 verbose.append("-v") |
2239 if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + verbose + urls, nonZeroIsFatal=False) == 0: | 2282 if run([java().java, '-cp', _tpU2W(myDir), 'URLConnectionDownload', _tpU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: |
2240 return | 2283 return |
2241 | 2284 |
2242 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + | 2285 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + |
2243 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') | 2286 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') |
2244 | 2287 |
2289 log('Compiling Java sources for {} with {}... [{}]'.format(self.proj.name, compiler, self.reason)) | 2332 log('Compiling Java sources for {} with {}... [{}]'.format(self.proj.name, compiler, self.reason)) |
2290 | 2333 |
2291 def execute(self): | 2334 def execute(self): |
2292 argfileName = join(self.proj.dir, 'javafilelist.txt') | 2335 argfileName = join(self.proj.dir, 'javafilelist.txt') |
2293 argfile = open(argfileName, 'wb') | 2336 argfile = open(argfileName, 'wb') |
2294 argfile.write('\n'.join(self.javafilelist)) | 2337 argfile.write('\n'.join(map(_tpU2W, self.javafilelist))) |
2295 argfile.close() | 2338 argfile.close() |
2296 | 2339 |
2297 processorArgs = [] | 2340 processorArgs = [] |
2298 | |
2299 processorPath = self.proj.annotation_processors_path() | 2341 processorPath = self.proj.annotation_processors_path() |
2300 if processorPath: | 2342 if processorPath: |
2301 genDir = self.proj.source_gen_dir() | 2343 genDir = self.proj.source_gen_dir() |
2302 if exists(genDir): | 2344 if exists(genDir): |
2303 shutil.rmtree(genDir) | 2345 shutil.rmtree(genDir) |
2304 os.mkdir(genDir) | 2346 os.mkdir(genDir) |
2305 processorArgs += ['-processorpath', join(processorPath), '-s', genDir] | 2347 processorArgs += ['-processorpath', _tspU2W(join(processorPath)), '-s', _tpU2W(genDir)] |
2306 else: | 2348 else: |
2307 processorArgs += ['-proc:none'] | 2349 processorArgs += ['-proc:none'] |
2308 | 2350 |
2309 args = self.args | 2351 args = self.args |
2310 jdk = self.jdk | 2352 jdk = self.jdk |
2311 outputDir = self.outputDir | 2353 outputDir = _tpU2W(self.outputDir) |
2312 compliance = str(jdk.javaCompliance) | 2354 compliance = str(jdk.javaCompliance) |
2313 cp = classpath(self.proj.name, includeSelf=True) | 2355 cp = classpath(self.proj.name, includeSelf=True) |
2314 toBeDeleted = [argfileName] | 2356 toBeDeleted = [argfileName] |
2315 | 2357 |
2316 try: | 2358 try: |
2321 self.logCompilation('javac' if not args.alt_javac else args.alt_javac) | 2363 self.logCompilation('javac' if not args.alt_javac else args.alt_javac) |
2322 javacCmd = [javac, '-g', '-J-Xmx1g', '-source', compliance, '-target', compliance, '-classpath', cp, '-d', outputDir, '-bootclasspath', jdk.bootclasspath(), '-endorseddirs', jdk.endorseddirs(), '-extdirs', jdk.extdirs()] | 2364 javacCmd = [javac, '-g', '-J-Xmx1g', '-source', compliance, '-target', compliance, '-classpath', cp, '-d', outputDir, '-bootclasspath', jdk.bootclasspath(), '-endorseddirs', jdk.endorseddirs(), '-extdirs', jdk.extdirs()] |
2323 if jdk.debug_port is not None: | 2365 if jdk.debug_port is not None: |
2324 javacCmd += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(jdk.debug_port)] | 2366 javacCmd += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(jdk.debug_port)] |
2325 javacCmd += processorArgs | 2367 javacCmd += processorArgs |
2326 javacCmd += ['@' + argfile.name] | 2368 javacCmd += ['@' + _tpU2W(argfile.name)] |
2327 | 2369 |
2328 if not args.warnAPI: | 2370 if not args.warnAPI: |
2329 javacCmd.append('-XDignore.symbol.file') | 2371 javacCmd.append('-XDignore.symbol.file') |
2330 run(javacCmd) | 2372 run(javacCmd) |
2331 else: | 2373 else: |