comparison mxtool/mx.py @ 12630:aadb188e4258

mxtool: regenerate IDE files when suite imports file changes
author Mick Jordan <mick.jordan@oracle.com>
date Tue, 29 Oct 2013 21:05:15 -0700
parents a9f750305a38
children 2303d9e199e3
comparison
equal deleted inserted replaced
12629:8ba058ffbc2e 12630:aadb188e4258
767 767
768 if self.name is None: 768 if self.name is None:
769 abort('Missing "suite=<name>" in ' + projectsFile) 769 abort('Missing "suite=<name>" in ' + projectsFile)
770 770
771 def _commands_name(self): 771 def _commands_name(self):
772 return 'mx_' + self.name.replace('-', '_') 772 return 'mx_' + self.name.replace('-','_')
773 773
774 def _find_commands(self, name): 774 def _find_commands(self, name):
775 commandsPath = join(self.mxDir, name + '.py') 775 commandsPath = join(self.mxDir, name + '.py')
776 if exists(commandsPath): 776 if exists(commandsPath):
777 return name 777 return name
801 if hasattr(mod, 'mx_post_parse_cmd_line'): 801 if hasattr(mod, 'mx_post_parse_cmd_line'):
802 self.mx_post_parse_cmd_line = mod.mx_post_parse_cmd_line 802 self.mx_post_parse_cmd_line = mod.mx_post_parse_cmd_line
803 803
804 mod.mx_init(self) 804 mod.mx_init(self)
805 self.commands = mod 805 self.commands = mod
806
807 def _imports_file(self):
808 return join(self.mxDir, 'imports')
809
810 def import_timestamp(self):
811 return TimeStampFile(self._imports_file())
806 812
807 def visit_imports(self, visitor, **extra_args): 813 def visit_imports(self, visitor, **extra_args):
808 """ 814 """
809 Visitor support for the imports file. 815 Visitor support for the imports file.
810 For each line of the imports file that specifies an import, the visitor function is 816 For each line of the imports file that specifies an import, the visitor function is
815 all imports are processed. 821 all imports are processed.
816 N.B. There is no built-in support for avoiding visiting the same suite multiple times, 822 N.B. There is no built-in support for avoiding visiting the same suite multiple times,
817 as this function only visits the imports of a single suite. If a (recursive) visitor function 823 as this function only visits the imports of a single suite. If a (recursive) visitor function
818 wishes to visit a suite exactly once, it must manage that through extra_args. 824 wishes to visit a suite exactly once, it must manage that through extra_args.
819 """ 825 """
820 importsFile = join(self.mxDir, 'imports') 826 importsFile = self._imports_file()
821 if exists(importsFile): 827 if exists(importsFile):
822 update_versions = extra_args.has_key('update_versions') and extra_args['update_versions'] 828 update_versions = extra_args.has_key('update_versions') and extra_args['update_versions']
823 out = StringIO.StringIO() if update_versions else None 829 out = StringIO.StringIO() if update_versions else None
824 extra_args['updated_imports'] = out 830 extra_args['updated_imports'] = out
825 with open(importsFile) as f: 831 with open(importsFile) as f:
2130 log('Wrote backup of {0} modified files to {1}'.format(len(modified), backup)) 2136 log('Wrote backup of {0} modified files to {1}'.format(len(modified), backup))
2131 return 1 2137 return 1
2132 return 0 2138 return 0
2133 2139
2134 def processorjars(): 2140 def processorjars():
2135 2141 for s in suites(True):
2142 _processorjars_suite(s)
2143
2144 def _processorjars_suite(s):
2136 projs = set() 2145 projs = set()
2137 for p in sorted_deps(): 2146 candidates = sorted_project_deps(s.projects)
2147 for p in candidates:
2138 if _isAnnotationProcessorDependency(p): 2148 if _isAnnotationProcessorDependency(p):
2139 projs.add(p) 2149 projs.add(p)
2140 2150
2141 if len(projs) < 0: 2151 if len(projs) <= 0:
2142 return 2152 return
2143 2153
2144 pnames = [p.name for p in projs] 2154 pnames = [p.name for p in projs]
2145 build(['--projects', ",".join(pnames)]) 2155 build(['--projects', ",".join(pnames)])
2146 archive(pnames) 2156 archive(pnames)
2376 self.timestamp = os.path.getmtime(path) if exists(path) else None 2386 self.timestamp = os.path.getmtime(path) if exists(path) else None
2377 2387
2378 def isOlderThan(self, arg): 2388 def isOlderThan(self, arg):
2379 if not self.timestamp: 2389 if not self.timestamp:
2380 return True 2390 return True
2381 if isinstance(arg, types.ListType): 2391 if isinstance(arg, TimeStampFile):
2392 if arg.timestamp is None:
2393 return False
2394 else:
2395 return arg.timestamp > self.timestamp
2396 elif isinstance(arg, types.ListType):
2382 files = arg 2397 files = arg
2383 else: 2398 else:
2384 files = [arg] 2399 files = [arg]
2385 for f in files: 2400 for f in files:
2386 if os.path.getmtime(f) > self.timestamp: 2401 if os.path.getmtime(f) > self.timestamp:
2639 fromIndex = fromIndex + 1 2654 fromIndex = fromIndex + 1
2640 igv.close('edges') 2655 igv.close('edges')
2641 igv.close('graph') 2656 igv.close('graph')
2642 igv.close('group') 2657 igv.close('group')
2643 igv.close('graphDocument') 2658 igv.close('graphDocument')
2644 2659
2645 if args.igv: 2660 if args.igv:
2646 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 2661 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2647 s.connect(('127.0.0.1', 4444)) 2662 s.connect(('127.0.0.1', 4444))
2648 s.send(igv.xml()) 2663 s.send(igv.xml())
2649 else: 2664 else:
2650 print igv.xml(indent=' ', newl='\n'); 2665 print igv.xml(indent=' ', newl='\n')
2651 return 2666 return
2652 2667
2653
2654 print 'digraph projects {' 2668 print 'digraph projects {'
2655 print 'rankdir=BT;' 2669 print 'rankdir=BT;'
2656 print 'node [shape=rect];' 2670 print 'node [shape=rect];'
2657 for p in projects(): 2671 for p in projects():
2658 for dep in p.canonical_deps(): 2672 for dep in p.canonical_deps():
2785 for s in suites(True): 2799 for s in suites(True):
2786 _eclipseinit_suite(args, s, buildProcessorJars, refreshOnly) 2800 _eclipseinit_suite(args, s, buildProcessorJars, refreshOnly)
2787 2801
2788 generate_eclipse_workingsets() 2802 generate_eclipse_workingsets()
2789 2803
2804 def _check_ide_timestamp(suite, timestamp):
2805 """return True if and only if the projects file, imports file, and mx itself are all older than timestamp"""
2806 projectsFile = join(suite.mxDir, 'projects')
2807 projectsFileOlder = not timestamp.isOlderThan(projectsFile)
2808 importsFileOlder = not timestamp.isOlderThan(suite.import_timestamp())
2809 # Assume that any mx change might imply changes to the generated IDE files
2810 mxOlder = not timestamp.isOlderThan(__file__)
2811 return projectsFileOlder and importsFileOlder and mxOlder
2790 2812
2791 def _eclipseinit_suite(args, suite, buildProcessorJars=True, refreshOnly=False): 2813 def _eclipseinit_suite(args, suite, buildProcessorJars=True, refreshOnly=False):
2792 projectsFile = join(suite.mxDir, 'projects')
2793 timestamp = TimeStampFile(join(suite.mxDir, 'eclipseinit.timestamp')) 2814 timestamp = TimeStampFile(join(suite.mxDir, 'eclipseinit.timestamp'))
2794 if refreshOnly and not timestamp.exists(): 2815 if refreshOnly and not timestamp.exists():
2795 return 2816 return
2796 2817
2797 if not timestamp.isOlderThan(projectsFile) and not TimeStampFile(projectsFile).isOlderThan(__file__): 2818 if _check_ide_timestamp(suite, timestamp):
2798 logv('[Eclipse configurations are up to date - skipping]') 2819 logv('[Eclipse configurations are up to date - skipping]')
2799 return 2820 return
2800 2821
2801 if buildProcessorJars: 2822 if buildProcessorJars:
2802 # todo suite specific 2823 _processorjars_suite(suite)
2803 processorjars()
2804 2824
2805 projToDist = dict() 2825 projToDist = dict()
2806 for dist in _dists.values(): 2826 for dist in _dists.values():
2807 distDeps = sorted_deps(dist.deps) 2827 distDeps = sorted_deps(dist.deps)
2808 for p in distDeps: 2828 for p in distDeps:
3197 3217
3198 for suite in suites(True): 3218 for suite in suites(True):
3199 _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars) 3219 _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars)
3200 3220
3201 def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True): 3221 def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True):
3202 projectsFile = join(suite.mxDir, 'projects')
3203 timestamp = TimeStampFile(join(suite.mxDir, 'netbeansinit.timestamp')) 3222 timestamp = TimeStampFile(join(suite.mxDir, 'netbeansinit.timestamp'))
3204 if refreshOnly and not timestamp.exists(): 3223 if refreshOnly and not timestamp.exists():
3205 return 3224 return
3206 3225
3207 if not timestamp.isOlderThan(projectsFile) and not TimeStampFile(projectsFile).isOlderThan(__file__): 3226 if _check_ide_timestamp(suite, timestamp):
3208 logv('[NetBeans configurations are up to date - skipping]') 3227 logv('[NetBeans configurations are up to date - skipping]')
3209 return 3228 return
3210 3229
3211 updated = False 3230 updated = False
3212 for p in suite.projects: 3231 for p in suite.projects: