comparison mxtool/mx.py @ 17262:b641450c19ce

mx: rename helper functions for cygwin support and update comments
author Bernhard Urban <bernhard.urban@jku.at>
date Tue, 30 Sep 2014 10:05:30 +0200
parents eff18e262a13
children 83bbc0e5891a
comparison
equal deleted inserted replaced
17261:d4fe68441072 17262:b641450c19ce
1343 elif sys.platform.startswith('cygwin'): 1343 elif sys.platform.startswith('cygwin'):
1344 return 'cygwin' 1344 return 'cygwin'
1345 else: 1345 else:
1346 abort('Unknown operating system ' + sys.platform) 1346 abort('Unknown operating system ' + sys.platform)
1347 1347
1348 def _tpU2W(p): 1348 def _cygpathU2W(p):
1349 """ 1349 """
1350 Translate a path from unix-style to windows-style 1350 Translate a path from unix-style to windows-style.
1351 This method has no effects on other platforms than cygwin.
1351 """ 1352 """
1352 if p is None or get_os() != "cygwin": 1353 if p is None or get_os() != "cygwin":
1353 return p 1354 return p
1354 return subprocess.check_output(['cygpath', '-w', p]).strip() 1355 return subprocess.check_output(['cygpath', '-w', p]).strip()
1355 1356
1356 def _tpW2U(p): 1357 def _cygpathW2U(p):
1357 """ 1358 """
1358 Translate a path from windows-style to unix-style 1359 Translate a path from windows-style to unix-style.
1360 This method has no effects on other platforms than cygwin.
1359 """ 1361 """
1360 if p is None or get_os() != "cygwin": 1362 if p is None or get_os() != "cygwin":
1361 return p 1363 return p
1362 return subprocess.check_output(['cygpath', '-u', p]).strip() 1364 return subprocess.check_output(['cygpath', '-u', p]).strip()
1363 1365
1364 def _tspU2W(p): 1366 def _separatedCygpathU2W(p):
1365 """ 1367 """
1366 Translate a group of paths, seperated by a path seperator. 1368 Translate a group of paths, separated by a path separator.
1367 unix-style to windows-style. 1369 unix-style to windows-style.
1370 This method has no effects on other platforms than cygwin.
1368 """ 1371 """
1369 if p is None or p == "" or get_os() != "cygwin": 1372 if p is None or p == "" or get_os() != "cygwin":
1370 return p 1373 return p
1371 return ';'.join(map(_tpU2W, p.split(os.pathsep))) 1374 return ';'.join(map(_cygpathU2W, p.split(os.pathsep)))
1372 1375
1373 def _tspW2U(p): 1376 def _separatedCygpathW2U(p):
1374 """ 1377 """
1375 Translate a group of paths, seperated by a path seperator. 1378 Translate a group of paths, separated by a path separator.
1376 windows-style to unix-style. 1379 windows-style to unix-style.
1380 This method has no effects on other platforms than cygwin.
1377 """ 1381 """
1378 if p is None or p == "" or get_os() != "cygwin": 1382 if p is None or p == "" or get_os() != "cygwin":
1379 return p 1383 return p
1380 return os.pathsep.join(map(_tpW2U, p.split(';'))) 1384 return os.pathsep.join(map(_cygpathW2U, p.split(';')))
1381 1385
1382 def get_arch(): 1386 def get_arch():
1383 machine = platform.uname()[4] 1387 machine = platform.uname()[4]
1384 if machine in ['amd64', 'AMD64', 'x86_64', 'i86pc']: 1388 if machine in ['amd64', 'AMD64', 'x86_64', 'i86pc']:
1385 return 'amd64' 1389 return 'amd64'
1566 result = distsCp 1570 result = distsCp
1567 1571
1568 if includeBootClasspath: 1572 if includeBootClasspath:
1569 result = os.pathsep.join([java().bootclasspath(), result]) 1573 result = os.pathsep.join([java().bootclasspath(), result])
1570 1574
1571 return _tspU2W(result) 1575 return _separatedCygpathU2W(result)
1572 1576
1573 def classpath_walk(names=None, resolve=True, includeSelf=True, includeBootClasspath=False): 1577 def classpath_walk(names=None, resolve=True, includeSelf=True, includeBootClasspath=False):
1574 """ 1578 """
1575 Walks the resources available in a given classpath, yielding a tuple for each resource 1579 Walks the resources available in a given classpath, yielding a tuple for each resource
1576 where the first member of the tuple is a directory path or ZipFile object for a 1580 where the first member of the tuple is a directory path or ZipFile object for a
2034 2038
2035 def __cmp__(self, other): 2039 def __cmp__(self, other):
2036 return cmp(self.parts, other.parts) 2040 return cmp(self.parts, other.parts)
2037 2041
2038 def _filter_non_existant_paths(paths): 2042 def _filter_non_existant_paths(paths):
2039 return os.pathsep.join([path for path in _tspW2U(paths).split(os.pathsep) if exists(path)]) 2043 return os.pathsep.join([path for path in _separatedCygpathW2U(paths).split(os.pathsep) if exists(path)])
2040 2044
2041 """ 2045 """
2042 A JavaConfig object encapsulates info on how Java commands are run. 2046 A JavaConfig object encapsulates info on how Java commands are run.
2043 """ 2047 """
2044 class JavaConfig: 2048 class JavaConfig:
2099 outDir = join(dirname(__file__), '.jdk' + str(self.version)) 2103 outDir = join(dirname(__file__), '.jdk' + str(self.version))
2100 if not exists(outDir): 2104 if not exists(outDir):
2101 os.makedirs(outDir) 2105 os.makedirs(outDir)
2102 javaSource = join(myDir, 'ClasspathDump.java') 2106 javaSource = join(myDir, 'ClasspathDump.java')
2103 if not exists(join(outDir, 'ClasspathDump.class')): 2107 if not exists(join(outDir, 'ClasspathDump.class')):
2104 subprocess.check_call([self.javac, '-d', _tpU2W(outDir), _tpU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE) 2108 subprocess.check_call([self.javac, '-d', _cygpathU2W(outDir), _cygpathU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
2105 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('|')] 2109 self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', _separatedCygpathU2W(outDir), 'ClasspathDump'], stderr=subprocess.PIPE).split('|')]
2106 if not self._bootclasspath or not self._extdirs or not self._endorseddirs: 2110 if not self._bootclasspath or not self._extdirs or not self._endorseddirs:
2107 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'") 2111 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'")
2108 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath) 2112 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath)
2109 self._extdirs = _filter_non_existant_paths(self._extdirs) 2113 self._extdirs = _filter_non_existant_paths(self._extdirs)
2110 self._endorseddirs = _filter_non_existant_paths(self._endorseddirs) 2114 self._endorseddirs = _filter_non_existant_paths(self._endorseddirs)
2127 return self.java_args_pfx + self.java_args + self.java_args_sfx + args 2131 return self.java_args_pfx + self.java_args + self.java_args_sfx + args
2128 2132
2129 def bootclasspath(self): 2133 def bootclasspath(self):
2130 if self._bootclasspath is None: 2134 if self._bootclasspath is None:
2131 self._init_classpaths() 2135 self._init_classpaths()
2132 return _tspU2W(self._bootclasspath) 2136 return _separatedCygpathU2W(self._bootclasspath)
2133 2137
2134 def extdirs(self): 2138 def extdirs(self):
2135 if self._extdirs is None: 2139 if self._extdirs is None:
2136 self._init_classpaths() 2140 self._init_classpaths()
2137 return _tspU2W(self._extdirs) 2141 return _separatedCygpathU2W(self._extdirs)
2138 2142
2139 def endorseddirs(self): 2143 def endorseddirs(self):
2140 if self._endorseddirs is None: 2144 if self._endorseddirs is None:
2141 self._init_classpaths() 2145 self._init_classpaths()
2142 return _tspU2W(self._endorseddirs) 2146 return _separatedCygpathU2W(self._endorseddirs)
2143 2147
2144 def containsJar(self, jar): 2148 def containsJar(self, jar):
2145 if self._bootclasspath is None: 2149 if self._bootclasspath is None:
2146 self._init_classpaths() 2150 self._init_classpaths()
2147 2151
2283 2287
2284 myDir = dirname(__file__) 2288 myDir = dirname(__file__)
2285 javaSource = join(myDir, 'URLConnectionDownload.java') 2289 javaSource = join(myDir, 'URLConnectionDownload.java')
2286 javaClass = join(myDir, 'URLConnectionDownload.class') 2290 javaClass = join(myDir, 'URLConnectionDownload.class')
2287 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): 2291 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
2288 subprocess.check_call([java().javac, '-d', _tpU2W(myDir), _tpU2W(javaSource)]) 2292 subprocess.check_call([java().javac, '-d', _cygpathU2W(myDir), _cygpathU2W(javaSource)])
2289 verbose = [] 2293 verbose = []
2290 if sys.stderr.isatty(): 2294 if sys.stderr.isatty():
2291 verbose.append("-v") 2295 verbose.append("-v")
2292 if run([java().java, '-cp', _tpU2W(myDir), 'URLConnectionDownload', _tpU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: 2296 if run([java().java, '-cp', _cygpathU2W(myDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0:
2293 return 2297 return
2294 2298
2295 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + 2299 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' +
2296 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') 2300 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually')
2297 2301
2342 log('Compiling Java sources for {} with {}... [{}]'.format(self.proj.name, compiler, self.reason)) 2346 log('Compiling Java sources for {} with {}... [{}]'.format(self.proj.name, compiler, self.reason))
2343 2347
2344 def execute(self): 2348 def execute(self):
2345 argfileName = join(self.proj.dir, 'javafilelist.txt') 2349 argfileName = join(self.proj.dir, 'javafilelist.txt')
2346 argfile = open(argfileName, 'wb') 2350 argfile = open(argfileName, 'wb')
2347 argfile.write('\n'.join(map(_tpU2W, self.javafilelist))) 2351 argfile.write('\n'.join(map(_cygpathU2W, self.javafilelist)))
2348 argfile.close() 2352 argfile.close()
2349 2353
2350 processorArgs = [] 2354 processorArgs = []
2351 processorPath = self.proj.annotation_processors_path() 2355 processorPath = self.proj.annotation_processors_path()
2352 if processorPath: 2356 if processorPath:
2353 genDir = self.proj.source_gen_dir() 2357 genDir = self.proj.source_gen_dir()
2354 if exists(genDir): 2358 if exists(genDir):
2355 shutil.rmtree(genDir) 2359 shutil.rmtree(genDir)
2356 os.mkdir(genDir) 2360 os.mkdir(genDir)
2357 processorArgs += ['-processorpath', _tspU2W(join(processorPath)), '-s', _tpU2W(genDir)] 2361 processorArgs += ['-processorpath', _separatedCygpathU2W(join(processorPath)), '-s', _cygpathU2W(genDir)]
2358 else: 2362 else:
2359 processorArgs += ['-proc:none'] 2363 processorArgs += ['-proc:none']
2360 2364
2361 args = self.args 2365 args = self.args
2362 jdk = self.jdk 2366 jdk = self.jdk
2363 outputDir = _tpU2W(self.outputDir) 2367 outputDir = _cygpathU2W(self.outputDir)
2364 compliance = str(jdk.javaCompliance) 2368 compliance = str(jdk.javaCompliance)
2365 cp = classpath(self.proj.name, includeSelf=True) 2369 cp = classpath(self.proj.name, includeSelf=True)
2366 toBeDeleted = [argfileName] 2370 toBeDeleted = [argfileName]
2367 2371
2368 try: 2372 try:
2373 self.logCompilation('javac' if not args.alt_javac else args.alt_javac) 2377 self.logCompilation('javac' if not args.alt_javac else args.alt_javac)
2374 javacCmd = [javac, '-g', '-J-Xmx1g', '-source', compliance, '-target', compliance, '-classpath', cp, '-d', outputDir, '-bootclasspath', jdk.bootclasspath(), '-endorseddirs', jdk.endorseddirs(), '-extdirs', jdk.extdirs()] 2378 javacCmd = [javac, '-g', '-J-Xmx1g', '-source', compliance, '-target', compliance, '-classpath', cp, '-d', outputDir, '-bootclasspath', jdk.bootclasspath(), '-endorseddirs', jdk.endorseddirs(), '-extdirs', jdk.extdirs()]
2375 if jdk.debug_port is not None: 2379 if jdk.debug_port is not None:
2376 javacCmd += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(jdk.debug_port)] 2380 javacCmd += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(jdk.debug_port)]
2377 javacCmd += processorArgs 2381 javacCmd += processorArgs
2378 javacCmd += ['@' + _tpU2W(argfile.name)] 2382 javacCmd += ['@' + _cygpathU2W(argfile.name)]
2379 2383
2380 if not args.warnAPI: 2384 if not args.warnAPI:
2381 javacCmd.append('-XDignore.symbol.file') 2385 javacCmd.append('-XDignore.symbol.file')
2382 run(javacCmd) 2386 run(javacCmd)
2383 else: 2387 else:
2390 javacArgs.append('-XDignore.symbol.file') 2394 javacArgs.append('-XDignore.symbol.file')
2391 run_java(javaArgs + ['-cp', os.pathsep.join([mainJava.toolsjar, args.error_prone]), 'com.google.errorprone.ErrorProneCompiler'] + javacArgs) 2395 run_java(javaArgs + ['-cp', os.pathsep.join([mainJava.toolsjar, args.error_prone]), 'com.google.errorprone.ErrorProneCompiler'] + javacArgs)
2392 else: 2396 else:
2393 self.logCompilation('JDT') 2397 self.logCompilation('JDT')
2394 2398
2395 jdtVmArgs = ['-Xmx1g', '-jar', _tpU2W(self.jdtJar)] 2399 jdtVmArgs = ['-Xmx1g', '-jar', _cygpathU2W(self.jdtJar)]
2396 2400
2397 jdtArgs = ['-' + compliance, 2401 jdtArgs = ['-' + compliance,
2398 '-cp', cp, '-g', '-enableJavadoc', 2402 '-cp', cp, '-g', '-enableJavadoc',
2399 '-d', outputDir, 2403 '-d', outputDir,
2400 '-bootclasspath', jdk.bootclasspath(), 2404 '-bootclasspath', jdk.bootclasspath(),
2420 if origContent != content: 2424 if origContent != content:
2421 jdtPropertiesTmp = jdtProperties + '.tmp' 2425 jdtPropertiesTmp = jdtProperties + '.tmp'
2422 with open(jdtPropertiesTmp, 'w') as fp: 2426 with open(jdtPropertiesTmp, 'w') as fp:
2423 fp.write(content) 2427 fp.write(content)
2424 toBeDeleted.append(jdtPropertiesTmp) 2428 toBeDeleted.append(jdtPropertiesTmp)
2425 jdtArgs += ['-properties', _tpU2W(jdtPropertiesTmp)] 2429 jdtArgs += ['-properties', _cygpathU2W(jdtPropertiesTmp)]
2426 else: 2430 else:
2427 jdtArgs += ['-properties', _tpU2W(jdtProperties)] 2431 jdtArgs += ['-properties', _cygpathU2W(jdtProperties)]
2428 jdtArgs.append('@' + _tpU2W(argfile.name)) 2432 jdtArgs.append('@' + _cygpathU2W(argfile.name))
2429 2433
2430 run_java(jdtVmArgs + jdtArgs) 2434 run_java(jdtVmArgs + jdtArgs)
2431 2435
2432 # Create annotation processor jar for a project that defines annotation processors 2436 # Create annotation processor jar for a project that defines annotation processors
2433 if self.proj.definedAnnotationProcessorsDist: 2437 if self.proj.definedAnnotationProcessorsDist: