comparison mxtool/mx.py @ 18647:beb33138029c

Clean bin directory before compiling to remove stale classfiles
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 08 Dec 2014 17:45:19 -0800
parents dcf5cd3c6da9
children 4836c2abc884
comparison
equal deleted inserted replaced
18646:290dc460feb3 18647:beb33138029c
2470 sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True) 2470 sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True)
2471 2471
2472 if args.java: 2472 if args.java:
2473 ideinit([], refreshOnly=True, buildProcessorJars=False) 2473 ideinit([], refreshOnly=True, buildProcessorJars=False)
2474 2474
2475 def prepareOutputDirs(p, clean):
2476 outputDir = p.output_dir()
2477 if exists(outputDir):
2478 if clean:
2479 log('Cleaning {0}...'.format(outputDir))
2480 shutil.rmtree(outputDir)
2481 os.mkdir(outputDir)
2482 else:
2483 os.mkdir(outputDir)
2484 genDir = p.source_gen_dir()
2485 if genDir != '' and exists(genDir) and clean:
2486 log('Cleaning {0}...'.format(genDir))
2487 for f in os.listdir(genDir):
2488 shutil.rmtree(join(genDir, f))
2489 return outputDir
2490
2491 tasks = {} 2475 tasks = {}
2492 updatedAnnotationProcessorDists = set() 2476 updatedAnnotationProcessorDists = set()
2493 for p in sortedProjects: 2477 for p in sortedProjects:
2494 if p.native: 2478 if p.native:
2495 if args.native: 2479 if args.native:
2509 # skip building this Java project if its Java compliance level is "higher" than the configured JDK 2493 # skip building this Java project if its Java compliance level is "higher" than the configured JDK
2510 requiredCompliance = p.javaCompliance if p.javaCompliance else JavaCompliance(args.compliance) if args.compliance else None 2494 requiredCompliance = p.javaCompliance if p.javaCompliance else JavaCompliance(args.compliance) if args.compliance else None
2511 jdk = java(requiredCompliance) 2495 jdk = java(requiredCompliance)
2512 assert jdk 2496 assert jdk
2513 2497
2514 outputDir = prepareOutputDirs(p, args.clean) 2498 outputDir = p.output_dir()
2515 2499
2516 sourceDirs = p.source_dirs() 2500 sourceDirs = p.source_dirs()
2517 buildReason = 'forced build' if args.force else None 2501 buildReason = None
2502 if args.force:
2503 buildReason = 'forced build'
2504 elif args.clean:
2505 buildReason = 'clean'
2506
2518 taskDeps = [] 2507 taskDeps = []
2519 for dep in p.all_deps([], includeLibs=False, includeAnnotationProcessors=True): 2508 for dep in p.all_deps([], includeLibs=False, includeAnnotationProcessors=True):
2520 taskDep = tasks.get(dep.name) 2509 taskDep = tasks.get(dep.name)
2521 if taskDep: 2510 if taskDep:
2522 if not buildReason: 2511 if not buildReason:
2523 buildReason = dep.name + ' rebuilt' 2512 buildReason = dep.name + ' rebuilt'
2524 taskDeps.append(taskDep) 2513 taskDeps.append(taskDep)
2525 2514
2526 jasminAvailable = None
2527 javafilelist = [] 2515 javafilelist = []
2516 nonjavafiletuples = []
2528 for sourceDir in sourceDirs: 2517 for sourceDir in sourceDirs:
2529 for root, _, files in os.walk(sourceDir): 2518 for root, _, files in os.walk(sourceDir):
2530 javafiles = [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] 2519 javafiles = [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java']
2531 javafilelist += javafiles 2520 javafilelist += javafiles
2532 2521
2533 # Copy all non Java resources or assemble Jasmin files 2522 nonjavafiletuples += [(sourceDir, [join(root, name) for name in files if not name.endswith('.java')])]
2534 nonjavafilelist = [join(root, name) for name in files if not name.endswith('.java')]
2535 for src in nonjavafilelist:
2536 if src.endswith('.jasm'):
2537 className = None
2538 with open(src) as f:
2539 for line in f:
2540 if line.startswith('.class '):
2541 className = line.split()[-1]
2542 break
2543
2544 if className is not None:
2545 jasminOutputDir = p.jasmin_output_dir()
2546 classFile = join(jasminOutputDir, className.replace('/', os.sep) + '.class')
2547 if exists(dirname(classFile)) and (not exists(classFile) or os.path.getmtime(classFile) < os.path.getmtime(src)):
2548 if jasminAvailable is None:
2549 try:
2550 with open(os.devnull) as devnull:
2551 subprocess.call('jasmin', stdout=devnull, stderr=subprocess.STDOUT)
2552 jasminAvailable = True
2553 except OSError:
2554 jasminAvailable = False
2555
2556 if jasminAvailable:
2557 log('Assembling Jasmin file ' + src)
2558 run(['jasmin', '-d', jasminOutputDir, src])
2559 else:
2560 log('The jasmin executable could not be found - skipping ' + src)
2561 with file(classFile, 'a'):
2562 os.utime(classFile, None)
2563
2564 else:
2565 log('could not file .class directive in Jasmin source: ' + src)
2566 else:
2567 dst = join(outputDir, src[len(sourceDir) + 1:])
2568 if not exists(dirname(dst)):
2569 os.makedirs(dirname(dst))
2570 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)):
2571 shutil.copyfile(src, dst)
2572 2523
2573 if not buildReason: 2524 if not buildReason:
2574 for javafile in javafiles: 2525 for javafile in javafiles:
2575 classfile = TimeStampFile(outputDir + javafile[len(sourceDir):-len('java')] + 'class') 2526 classfile = TimeStampFile(outputDir + javafile[len(sourceDir):-len('java')] + 'class')
2576 if not classfile.exists() or classfile.isOlderThan(javafile): 2527 if not classfile.exists() or classfile.isOlderThan(javafile):
2581 if apsOutOfDate: 2532 if apsOutOfDate:
2582 buildReason = 'annotation processor(s) changed' 2533 buildReason = 'annotation processor(s) changed'
2583 2534
2584 if not buildReason: 2535 if not buildReason:
2585 logv('[all class files for {0} are up to date - skipping]'.format(p.name)) 2536 logv('[all class files for {0} are up to date - skipping]'.format(p.name))
2537 _handleNonJavaFiles(outputDir, p, False, nonjavafiletuples)
2586 continue 2538 continue
2539
2540 _handleNonJavaFiles(outputDir, p, True, nonjavafiletuples)
2587 2541
2588 if len(javafilelist) == 0: 2542 if len(javafilelist) == 0:
2589 logv('[no Java sources for {0} - skipping]'.format(p.name)) 2543 logv('[no Java sources for {0} - skipping]'.format(p.name))
2590 continue 2544 continue
2591 2545
2700 archive(['@' + dist.name]) 2654 archive(['@' + dist.name])
2701 2655
2702 if suppliedParser: 2656 if suppliedParser:
2703 return args 2657 return args
2704 return None 2658 return None
2659
2660 def _handleNonJavaFiles(outputDir, p, clean, nonjavafiletuples):
2661 if exists(outputDir):
2662 if clean:
2663 log('Cleaning {0}...'.format(outputDir))
2664 shutil.rmtree(outputDir)
2665 os.mkdir(outputDir)
2666 else:
2667 os.mkdir(outputDir)
2668 genDir = p.source_gen_dir()
2669 if genDir != '' and exists(genDir) and clean:
2670 log('Cleaning {0}...'.format(genDir))
2671 for f in os.listdir(genDir):
2672 shutil.rmtree(join(genDir, f))
2673
2674 # Copy all non Java resources or assemble Jasmin files
2675 jasminAvailable = None
2676 for nonjavafiletuple in nonjavafiletuples:
2677 sourceDir = nonjavafiletuple[0]
2678 nonjavafilelist = nonjavafiletuple[1]
2679
2680 for src in nonjavafilelist:
2681 if src.endswith('.jasm'):
2682 className = None
2683 with open(src) as f:
2684 for line in f:
2685 if line.startswith('.class '):
2686 className = line.split()[-1]
2687 break
2688
2689 if className is not None:
2690 jasminOutputDir = p.jasmin_output_dir()
2691 classFile = join(jasminOutputDir, className.replace('/', os.sep) + '.class')
2692 if exists(dirname(classFile)) and (not exists(classFile) or os.path.getmtime(classFile) < os.path.getmtime(src)):
2693 if jasminAvailable is None:
2694 try:
2695 with open(os.devnull) as devnull:
2696 subprocess.call('jasmin', stdout=devnull, stderr=subprocess.STDOUT)
2697 jasminAvailable = True
2698 except OSError:
2699 jasminAvailable = False
2700
2701 if jasminAvailable:
2702 log('Assembling Jasmin file ' + src)
2703 run(['jasmin', '-d', jasminOutputDir, src])
2704 else:
2705 log('The jasmin executable could not be found - skipping ' + src)
2706 with file(classFile, 'a'):
2707 os.utime(classFile, None)
2708
2709 else:
2710 log('could not file .class directive in Jasmin source: ' + src)
2711 else:
2712 dst = join(outputDir, src[len(sourceDir) + 1:])
2713 if not exists(dirname(dst)):
2714 os.makedirs(dirname(dst))
2715 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)):
2716 shutil.copyfile(src, dst)
2705 2717
2706 def _chunk_files_for_command_line(files, limit=None, pathFunction=None): 2718 def _chunk_files_for_command_line(files, limit=None, pathFunction=None):
2707 """ 2719 """
2708 Returns a generator for splitting up a list of files into chunks such that the 2720 Returns a generator for splitting up a list of files into chunks such that the
2709 size of the space separated file paths in a chunk is less than a given limit. 2721 size of the space separated file paths in a chunk is less than a given limit.