Mercurial > hg > truffle
comparison mxtool/mx.py @ 11659:ec7aad9dfc47
made 'mx build' refresh IDE configs automatically
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 16 Sep 2013 13:09:02 +0200 |
parents | 60e3fe0fe939 |
children | facb442de5db |
comparison
equal
deleted
inserted
replaced
11657:74ea8747b43a | 11659:ec7aad9dfc47 |
---|---|
1557 if args.only is not None: | 1557 if args.only is not None: |
1558 sortedProjects = [project(name) for name in args.only.split(',')] | 1558 sortedProjects = [project(name) for name in args.only.split(',')] |
1559 else: | 1559 else: |
1560 sortedProjects = sorted_deps(projects, includeAnnotationProcessors=True) | 1560 sortedProjects = sorted_deps(projects, includeAnnotationProcessors=True) |
1561 | 1561 |
1562 if args.java: | |
1563 ideinit([], refreshOnly=True, buildProcessorJars=False) | |
1564 | |
1562 for p in sortedProjects: | 1565 for p in sortedProjects: |
1563 if p.native: | 1566 if p.native: |
1564 if args.native: | 1567 if args.native: |
1565 log('Calling GNU make {0}...'.format(p.dir)) | 1568 log('Calling GNU make {0}...'.format(p.dir)) |
1566 | 1569 |
1960 | 1963 |
1961 The exit code of this command reflects how many files were updated.""" | 1964 The exit code of this command reflects how many files were updated.""" |
1962 | 1965 |
1963 changedFiles = 0 | 1966 changedFiles = 0 |
1964 for s in suites(): | 1967 for s in suites(): |
1965 projectsFile = join(s.dir, 'mx', 'projects') | 1968 projectsFile = join(s.mxDir, 'projects') |
1966 if not exists(projectsFile): | 1969 if not exists(projectsFile): |
1967 continue | 1970 continue |
1968 with open(projectsFile) as f: | 1971 with open(projectsFile) as f: |
1969 out = StringIO.StringIO() | 1972 out = StringIO.StringIO() |
1970 pattern = re.compile('project@([^@]+)@dependencies=.*') | 1973 pattern = re.compile('project@([^@]+)@dependencies=.*') |
2011 content = out.getvalue() | 2014 content = out.getvalue() |
2012 if update_file(projectsFile, content): | 2015 if update_file(projectsFile, content): |
2013 changedFiles += 1 | 2016 changedFiles += 1 |
2014 return changedFiles | 2017 return changedFiles |
2015 | 2018 |
2019 class TimeStampFile: | |
2020 def __init__(self, path): | |
2021 self.path = path | |
2022 self.timestamp = os.path.getmtime(path) if exists(path) else None | |
2023 | |
2024 def outOfDate(self, arg): | |
2025 if not self.timestamp: | |
2026 return True | |
2027 if isinstance(arg, types.ListType): | |
2028 files = arg | |
2029 else: | |
2030 files = [arg] | |
2031 for f in files: | |
2032 if os.path.getmtime(f) > self.timestamp: | |
2033 return True | |
2034 return False | |
2035 | |
2036 def exists(self): | |
2037 return exists(self.path) | |
2038 | |
2039 def touch(self): | |
2040 if exists(self.path): | |
2041 os.utime(self.path, None) | |
2042 else: | |
2043 if not isdir(dirname(self.path)): | |
2044 os.makedirs(dirname(self.path)) | |
2045 file(self.path, 'a') | |
2046 | |
2016 def checkstyle(args): | 2047 def checkstyle(args): |
2017 """run Checkstyle on the Java sources | 2048 """run Checkstyle on the Java sources |
2018 | 2049 |
2019 Run Checkstyle over the Java sources. Any errors or warnings | 2050 Run Checkstyle over the Java sources. Any errors or warnings |
2020 produced by Checkstyle result in a non-zero exit code.""" | 2051 produced by Checkstyle result in a non-zero exit code.""" |
2045 javafilelist += [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] | 2076 javafilelist += [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] |
2046 if len(javafilelist) == 0: | 2077 if len(javafilelist) == 0: |
2047 logv('[no Java sources in {0} - skipping]'.format(sourceDir)) | 2078 logv('[no Java sources in {0} - skipping]'.format(sourceDir)) |
2048 continue | 2079 continue |
2049 | 2080 |
2050 timestampFile = join(p.suite.mxDir, 'checkstyle-timestamps', sourceDir[len(p.suite.dir) + 1:].replace(os.sep, '_') + '.timestamp') | 2081 timestamp = TimeStampFile(join(p.suite.mxDir, 'checkstyle-timestamps', sourceDir[len(p.suite.dir) + 1:].replace(os.sep, '_') + '.timestamp')) |
2051 if not exists(dirname(timestampFile)): | |
2052 os.makedirs(dirname(timestampFile)) | |
2053 mustCheck = False | 2082 mustCheck = False |
2054 if not args.force and exists(timestampFile): | 2083 if not args.force and timestamp.exists(): |
2055 timestamp = os.path.getmtime(timestampFile) | 2084 mustCheck = timestamp.outOfDate(javafilelist) |
2056 for f in javafilelist: | |
2057 if os.path.getmtime(f) > timestamp: | |
2058 mustCheck = True | |
2059 break | |
2060 else: | 2085 else: |
2061 mustCheck = True | 2086 mustCheck = True |
2062 | 2087 |
2063 if not mustCheck: | 2088 if not mustCheck: |
2064 if _opts.verbose: | 2089 if _opts.verbose: |
2139 xp.ParseFile(fp) | 2164 xp.ParseFile(fp) |
2140 if len(errors) != 0: | 2165 if len(errors) != 0: |
2141 map(log, errors) | 2166 map(log, errors) |
2142 totalErrors = totalErrors + len(errors) | 2167 totalErrors = totalErrors + len(errors) |
2143 else: | 2168 else: |
2144 if exists(timestampFile): | 2169 timestamp.touch() |
2145 os.utime(timestampFile, None) | |
2146 else: | |
2147 file(timestampFile, 'a') | |
2148 finally: | 2170 finally: |
2149 if exists(auditfileName): | 2171 if exists(auditfileName): |
2150 os.unlink(auditfileName) | 2172 os.unlink(auditfileName) |
2151 return totalErrors | 2173 return totalErrors |
2152 | 2174 |
2350 eclipseLaunches = join('mx', 'eclipse-launches') | 2372 eclipseLaunches = join('mx', 'eclipse-launches') |
2351 if not exists(eclipseLaunches): | 2373 if not exists(eclipseLaunches): |
2352 os.makedirs(eclipseLaunches) | 2374 os.makedirs(eclipseLaunches) |
2353 return update_file(join(eclipseLaunches, name + '.launch'), launch) | 2375 return update_file(join(eclipseLaunches, name + '.launch'), launch) |
2354 | 2376 |
2355 def eclipseinit(args, suite=None, buildProcessorJars=True): | 2377 def eclipseinit(args, suite=None, buildProcessorJars=True, refreshOnly=False): |
2356 """(re)generate Eclipse project configurations and working sets""" | 2378 """(re)generate Eclipse project configurations and working sets""" |
2357 | 2379 |
2358 if suite is None: | 2380 if suite is None: |
2359 suite = _mainSuite | 2381 suite = _mainSuite |
2382 | |
2383 projectsFile = join(suite.mxDir, 'projects') | |
2384 timestamp = TimeStampFile(join(suite.mxDir, 'eclipseinit.timestamp')) | |
2385 if refreshOnly and not timestamp.exists(): | |
2386 return | |
2387 | |
2388 if not timestamp.outOfDate(projectsFile): | |
2389 logv('[Eclipse configurations are up to date - skipping]') | |
2390 return | |
2360 | 2391 |
2361 if buildProcessorJars: | 2392 if buildProcessorJars: |
2362 processorjars() | 2393 processorjars() |
2363 | 2394 |
2364 projToDist = dict() | 2395 projToDist = dict() |
2541 out.close('factorypath') | 2572 out.close('factorypath') |
2542 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n')) | 2573 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n')) |
2543 | 2574 |
2544 make_eclipse_attach('localhost', '8000', deps=projects()) | 2575 make_eclipse_attach('localhost', '8000', deps=projects()) |
2545 generate_eclipse_workingsets(suite) | 2576 generate_eclipse_workingsets(suite) |
2546 | 2577 timestamp.touch() |
2547 | 2578 |
2548 def _isAnnotationProcessorDependency(p): | 2579 def _isAnnotationProcessorDependency(p): |
2549 """ | 2580 """ |
2550 Determines if a given project is part of an annotation processor. | 2581 Determines if a given project is part of an annotation processor. |
2551 """ | 2582 """ |
2718 wsdoc.open('workingSet', {'editPageID': 'org.eclipse.jdt.ui.JavaWorkingSetPage', 'factoryID': 'org.eclipse.ui.internal.WorkingSetFactory', 'id': 'wsid_' + ws, 'label': ws, 'name': ws}) | 2749 wsdoc.open('workingSet', {'editPageID': 'org.eclipse.jdt.ui.JavaWorkingSetPage', 'factoryID': 'org.eclipse.ui.internal.WorkingSetFactory', 'id': 'wsid_' + ws, 'label': ws, 'name': ws}) |
2719 | 2750 |
2720 def _workingset_element(wsdoc, p): | 2751 def _workingset_element(wsdoc, p): |
2721 wsdoc.element('item', {'elementID': '=' + p, 'factoryID': 'org.eclipse.jdt.ui.PersistableJavaElementFactory'}) | 2752 wsdoc.element('item', {'elementID': '=' + p, 'factoryID': 'org.eclipse.jdt.ui.PersistableJavaElementFactory'}) |
2722 | 2753 |
2723 def netbeansinit(args, suite=None): | 2754 def netbeansinit(args, suite=None, refreshOnly=False, buildProcessorJars=True): |
2724 """(re)generate NetBeans project configurations""" | 2755 """(re)generate NetBeans project configurations""" |
2725 | 2756 |
2726 if suite is None: | 2757 if suite is None: |
2727 suite = _mainSuite | 2758 suite = _mainSuite |
2759 | |
2760 projectsFile = join(suite.mxDir, 'projects') | |
2761 timestamp = TimeStampFile(join(suite.mxDir, 'netbeansinit.timestamp')) | |
2762 if refreshOnly and not timestamp.exists(): | |
2763 return | |
2764 | |
2765 if not timestamp.outOfDate(projectsFile): | |
2766 logv('[NetBeans configurations are up to date - skipping]') | |
2767 return | |
2728 | 2768 |
2729 updated = False | 2769 updated = False |
2730 for p in projects(): | 2770 for p in projects(): |
2731 if p.native: | 2771 if p.native: |
2732 continue | 2772 continue |
2938 if updated: | 2978 if updated: |
2939 log('If using NetBeans:') | 2979 log('If using NetBeans:') |
2940 log(' 1. Ensure that a platform named "JDK_' + str(java().version) + '" is defined (Tools -> Java Platforms)') | 2980 log(' 1. Ensure that a platform named "JDK_' + str(java().version) + '" is defined (Tools -> Java Platforms)') |
2941 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') | 2981 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') |
2942 | 2982 |
2983 timestamp.touch() | |
2984 | |
2943 def ideclean(args, suite=None): | 2985 def ideclean(args, suite=None): |
2944 """remove all Eclipse and NetBeans project configurations""" | 2986 """remove all Eclipse and NetBeans project configurations""" |
2945 def rm(path): | 2987 def rm(path): |
2946 if exists(path): | 2988 if exists(path): |
2947 os.remove(path) | 2989 os.remove(path) |
2990 | |
2991 for s in suites(): | |
2992 rm(join(s.mxDir, 'eclipseinit.timestamp')) | |
2993 rm(join(s.mxDir, 'netbeansinit.timestamp')) | |
2948 | 2994 |
2949 for p in projects(): | 2995 for p in projects(): |
2950 if p.native: | 2996 if p.native: |
2951 continue | 2997 continue |
2952 | 2998 |
2962 rm(join(p.dir, p.name + '.jar')) | 3008 rm(join(p.dir, p.name + '.jar')) |
2963 except: | 3009 except: |
2964 log("Error removing {0}".format(p.name + '.jar')) | 3010 log("Error removing {0}".format(p.name + '.jar')) |
2965 | 3011 |
2966 | 3012 |
2967 def ideinit(args, suite=None): | 3013 def ideinit(args, suite=None, refreshOnly=False, buildProcessorJars=True): |
2968 """(re)generate Eclipse and NetBeans project configurations""" | 3014 """(re)generate Eclipse and NetBeans project configurations""" |
2969 eclipseinit(args, suite) | 3015 eclipseinit(args, suite, refreshOnly=refreshOnly, buildProcessorJars=buildProcessorJars) |
2970 netbeansinit(args, suite) | 3016 netbeansinit(args, suite, refreshOnly=refreshOnly, buildProcessorJars=buildProcessorJars) |
2971 fsckprojects([]) | 3017 if not refreshOnly: |
3018 fsckprojects([]) | |
2972 | 3019 |
2973 def fsckprojects(args): | 3020 def fsckprojects(args): |
2974 """find directories corresponding to deleted Java projects and delete them""" | 3021 """find directories corresponding to deleted Java projects and delete them""" |
2975 for suite in suites(): | 3022 for suite in suites(): |
2976 projectDirs = [p.dir for p in suite.projects] | 3023 projectDirs = [p.dir for p in suite.projects] |
3464 run([javapExe, '-private', '-verbose', '-classpath', classpath()] + selection) | 3511 run([javapExe, '-private', '-verbose', '-classpath', classpath()] + selection) |
3465 | 3512 |
3466 def show_projects(args): | 3513 def show_projects(args): |
3467 """show all loaded projects""" | 3514 """show all loaded projects""" |
3468 for s in suites(): | 3515 for s in suites(): |
3469 projectsFile = join(s.dir, 'mx', 'projects') | 3516 projectsFile = join(s.mxDir, 'projects') |
3470 if exists(projectsFile): | 3517 if exists(projectsFile): |
3471 log(projectsFile) | 3518 log(projectsFile) |
3472 for p in s.projects: | 3519 for p in s.projects: |
3473 log('\t' + p.name) | 3520 log('\t' + p.name) |
3474 | 3521 |