comparison mx/commands.py @ 3732:3e2e8b8abdaf

Updated mxtool to allow projects in subdirectories.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 17 Dec 2011 19:58:27 +0100
parents 4e3851bab8d0
children d3ec27ea1b20
comparison
equal deleted inserted replaced
3731:71f1f6fd32f7 3732:3e2e8b8abdaf
24 # or visit www.oracle.com if you need additional information or have any 24 # or visit www.oracle.com if you need additional information or have any
25 # questions. 25 # questions.
26 # 26 #
27 # ---------------------------------------------------------------------------------------------------- 27 # ----------------------------------------------------------------------------------------------------
28 28
29 import os, sys, shutil, tarfile 29 import os, sys, shutil, tarfile, StringIO
30 from os.path import join, exists, dirname, isfile, isdir 30 from os.path import join, exists, dirname, isfile, isdir
31 31
32 graal_home = dirname(dirname(__file__)) 32 graal_home = dirname(dirname(__file__))
33 33
34 def clean(env, args): 34 def clean(env, args):
246 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args 246 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args
247 os.environ['MAXINE'] = env.check_get_env('GRAAL_HOME') 247 os.environ['MAXINE'] = env.check_get_env('GRAAL_HOME')
248 exe = join(_jdk7(env, build), 'bin', env.exe_suffix('java')) 248 exe = join(_jdk7(env, build), 'bin', env.exe_suffix('java'))
249 return env.run([exe, vm] + args) 249 return env.run([exe, vm] + args)
250 250
251 def eclipseprojects(env, args):
252 """(re)generate Eclipse project configurations
253
254 The exit code of this command reflects how many files were updated."""
255
256 def println(out, obj):
257 out.write(str(obj) + '\n')
258
259 pdb = env.pdb
260 for p in pdb.projects.values():
261 if p.native:
262 continue
263
264 d = join(p.baseDir, p.name)
265 if not exists(d):
266 os.makedirs(d)
267
268 changedFiles = 0
269
270 out = StringIO.StringIO()
271
272 println(out, '<?xml version="1.0" encoding="UTF-8"?>')
273 println(out, '<classpath>')
274 for src in p.srcDirs:
275 srcDir = join(d, src)
276 if not exists(srcDir):
277 os.mkdir(srcDir)
278 println(out, '\t<classpathentry kind="src" path="' + src + '"/>')
279
280 # Every Java program depends on the JRE
281 println(out, '\t<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>')
282
283 for dep in p.all_deps([], pdb, True):
284 if dep == p:
285 continue;
286
287 if dep.isLibrary():
288 if hasattr(dep, 'eclipse.container'):
289 println(out, '\t<classpathentry exported="true" kind="con" path="' + getattr(dep, 'eclipse.container') + '"/>')
290 elif hasattr(dep, 'eclipse.project'):
291 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + getattr(dep, 'eclipse.project') + '"/>')
292 else:
293 path = dep.path
294 if dep.mustExist:
295 if os.path.isabs(path):
296 println(out, '\t<classpathentry exported="true" kind="lib" path="' + path + '"/>')
297 else:
298 println(out, '\t<classpathentry exported="true" kind="lib" path="/' + path + '"/>')
299 else:
300 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>')
301
302 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>')
303 println(out, '</classpath>')
304
305 if env.update_file(join(p.baseDir, p.name, '.classpath'), out.getvalue()):
306 changedFiles += 1
307
308 out.close()
309
310 csConfig = join(p.baseDir, p.checkstyleProj, '.checkstyle_checks.xml')
311 if exists(csConfig):
312 out = StringIO.StringIO()
313
314 dotCheckstyle = join(d, ".checkstyle")
315 checkstyleConfigPath = '/' + p.checkstyleProj + '/.checkstyle_checks.xml'
316 println(out, '<?xml version="1.0" encoding="UTF-8"?>')
317 println(out, '<fileset-config file-format-version="1.2.0" simple-config="true">')
318 println(out, '\t<local-check-config name="Maxine Checks" location="' + checkstyleConfigPath + '" type="project" description="">')
319 println(out, '\t\t<additional-data name="protect-config-file" value="false"/>')
320 println(out, '\t</local-check-config>')
321 println(out, '\t<fileset name="all" enabled="true" check-config-name="Maxine Checks" local="true">')
322 println(out, '\t\t<file-match-pattern match-pattern="." include-pattern="true"/>')
323 println(out, '\t</fileset>')
324 println(out, '\t<filter name="FileTypesFilter" enabled="true">')
325 println(out, '\t\t<filter-data value="java"/>')
326 println(out, '\t</filter>')
327
328 exclude = join(d, '.checkstyle.exclude')
329 if exists(exclude):
330 println(out, '\t<filter name="FilesFromPackage" enabled="true">')
331 with open(exclude) as f:
332 for line in f:
333 if not line.startswith('#'):
334 line = line.strip()
335 exclDir = join(d, line)
336 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir
337 println(out, '\t\t<filter-data value="' + line + '"/>')
338 println(out, '\t</filter>')
339
340 println(out, '</fileset-config>')
341
342 if env.update_file(dotCheckstyle, out.getvalue()):
343 changedFiles += 1
344
345 out.close()
346
347
348 out = StringIO.StringIO()
349
350 println(out, '<?xml version="1.0" encoding="UTF-8"?>')
351 println(out, '<projectDescription>')
352 println(out, '\t<name>' + p.name + '</name>')
353 println(out, '\t<comment></comment>')
354 println(out, '\t<projects>')
355 println(out, '\t</projects>')
356 println(out, '\t<buildSpec>')
357 println(out, '\t\t<buildCommand>')
358 println(out, '\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>')
359 println(out, '\t\t\t<arguments>')
360 println(out, '\t\t\t</arguments>')
361 println(out, '\t\t</buildCommand>')
362 if exists(csConfig):
363 println(out, '\t\t<buildCommand>')
364 println(out, '\t\t\t<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>')
365 println(out, '\t\t\t<arguments>')
366 println(out, '\t\t\t</arguments>')
367 println(out, '\t\t</buildCommand>')
368 println(out, '\t</buildSpec>')
369 println(out, '\t<natures>')
370 println(out, '\t\t<nature>org.eclipse.jdt.core.javanature</nature>')
371 if exists(csConfig):
372 println(out, '\t\t<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>')
373 println(out, '\t</natures>')
374 println(out, '</projectDescription>')
375
376 if env.update_file(join(d, '.project'), out.getvalue()):
377 changedFiles += 1
378
379 out.close()
380
381 out = StringIO.StringIO()
382
383 settingsDir = join(d, ".settings")
384 if not exists(settingsDir):
385 os.mkdir(settingsDir)
386
387 myDir = dirname(__file__)
388
389 with open(join(myDir, 'org.eclipse.jdt.core.prefs')) as f:
390 content = f.read()
391 if env.update_file(join(settingsDir, 'org.eclipse.jdt.core.prefs'), content):
392 changedFiles += 1
393
394 with open(join(myDir, 'org.eclipse.jdt.ui.prefs')) as f:
395 content = f.read()
396 if env.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content):
397 changedFiles += 1
398
399 if changedFiles != 0:
400 env.abort(changedFiles)
401
251 def mx_init(env): 402 def mx_init(env):
252 env.vmbuild = 'product' 403 env.vmbuild = 'product'
253 env.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') 404 env.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM')
254 env.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM') 405 env.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM')
255 env.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM') 406 env.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM')
259 'example': [example, '[-v] example names...'], 410 'example': [example, '[-v] example names...'],
260 'clean': [clean, ''], 411 'clean': [clean, ''],
261 'make': [make, '[product|debug|fastdebug|optimized]'], 412 'make': [make, '[product|debug|fastdebug|optimized]'],
262 'tests': [tests, ''], 413 'tests': [tests, ''],
263 'vm': [vm, '[-options] class [args...]'], 414 'vm': [vm, '[-options] class [args...]'],
415 'eclipseprojects': [eclipseprojects, ''],
264 } 416 }
265 env.commands.update(commands) 417 env.commands.update(commands)