comparison mxtool/mx.py @ 12631:2303d9e199e3

rebuild projects if their annotation processor dependencies change; clean output directories before (re)compiling a Java project
author Doug Simon <doug.simon@oracle.com>
date Wed, 30 Oct 2013 09:49:53 +0100
parents aadb188e4258
children 6860d5528902
comparison
equal deleted inserted replaced
12630:aadb188e4258 12631:2303d9e199e3
323 for p in allDeps: 323 for p in allDeps:
324 if hasattr(p, 'annotationProcessorForDependents') and p.annotationProcessorForDependents.lower() == 'true': 324 if hasattr(p, 'annotationProcessorForDependents') and p.annotationProcessorForDependents.lower() == 'true':
325 ap.add(p.name) 325 ap.add(p.name)
326 self._annotationProcessors = list(ap) 326 self._annotationProcessors = list(ap)
327 return self._annotationProcessors 327 return self._annotationProcessors
328
329 def update_current_annotation_processors_file(self):
330 aps = self.annotation_processors()
331 outOfDate = False
332 currentApsFile = join(self.dir, '.currentAnnotationProcessors')
333 if exists(currentApsFile):
334 with open(currentApsFile) as fp:
335 currentAps = [l.strip() for l in fp.readlines()]
336 if currentAps != aps:
337 outOfDate = True
338 else:
339 outOfDate = True
340 if outOfDate:
341 with open(currentApsFile, 'w') as fp:
342 for ap in aps:
343 print >> fp, ap
344 return outOfDate
345
328 346
329 class Library(Dependency): 347 class Library(Dependency):
330 def __init__(self, suite, name, path, mustExist, urls, sourcePath, sourceUrls): 348 def __init__(self, suite, name, path, mustExist, urls, sourcePath, sourceUrls):
331 Dependency.__init__(self, suite, name) 349 Dependency.__init__(self, suite, name)
332 self.path = path.replace('/', os.sep) 350 self.path = path.replace('/', os.sep)
1851 sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True) 1869 sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True)
1852 1870
1853 if args.java: 1871 if args.java:
1854 ideinit([], refreshOnly=True, buildProcessorJars=False) 1872 ideinit([], refreshOnly=True, buildProcessorJars=False)
1855 1873
1874 def prepareOutputDirs(p, clean):
1875 outputDir = p.output_dir()
1876 if exists(outputDir):
1877 if clean:
1878 log('Cleaning {0}...'.format(outputDir))
1879 shutil.rmtree(outputDir)
1880 os.mkdir(outputDir)
1881 else:
1882 os.mkdir(outputDir)
1883 genDir = p.source_gen_dir()
1884 if genDir != '' and exists(genDir) and clean:
1885 log('Cleaning {0}...'.format(genDir))
1886 for f in os.listdir(genDir):
1887 shutil.rmtree(join(genDir, f))
1888 return outputDir
1889
1856 for p in sortedProjects: 1890 for p in sortedProjects:
1857 if p.native: 1891 if p.native:
1858 if args.native: 1892 if args.native:
1859 log('Calling GNU make {0}...'.format(p.dir)) 1893 log('Calling GNU make {0}...'.format(p.dir))
1860 1894
1873 # skip building this Java project if its Java compliance level is "higher" than the configured JDK 1907 # skip building this Java project if its Java compliance level is "higher" than the configured JDK
1874 if javaCompliance < p.javaCompliance: 1908 if javaCompliance < p.javaCompliance:
1875 log('Excluding {0} from build (Java compliance level {1} required)'.format(p.name, p.javaCompliance)) 1909 log('Excluding {0} from build (Java compliance level {1} required)'.format(p.name, p.javaCompliance))
1876 continue 1910 continue
1877 1911
1878 outputDir = p.output_dir() 1912 outputDir = prepareOutputDirs(p, args.clean)
1879 if exists(outputDir):
1880 if args.clean:
1881 log('Cleaning {0}...'.format(outputDir))
1882 shutil.rmtree(outputDir)
1883 os.mkdir(outputDir)
1884 else:
1885 os.mkdir(outputDir)
1886 1913
1887 cp = classpath(p.name, includeSelf=True) 1914 cp = classpath(p.name, includeSelf=True)
1888 sourceDirs = p.source_dirs() 1915 sourceDirs = p.source_dirs()
1889 mustBuild = args.force 1916 mustBuild = args.force
1890 if not mustBuild: 1917 if not mustBuild:
1891 for dep in p.all_deps([], False): 1918 for dep in p.all_deps([], False):
1892 if dep.name in built: 1919 if dep.name in built:
1893 mustBuild = True 1920 mustBuild = True
1921
1894 1922
1895 jasminAvailable = None 1923 jasminAvailable = None
1896 javafilelist = [] 1924 javafilelist = []
1897 for sourceDir in sourceDirs: 1925 for sourceDir in sourceDirs:
1898 for root, _, files in os.walk(sourceDir): 1926 for root, _, files in os.walk(sourceDir):
1939 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)): 1967 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)):
1940 shutil.copyfile(src, dst) 1968 shutil.copyfile(src, dst)
1941 1969
1942 if not mustBuild: 1970 if not mustBuild:
1943 for javafile in javafiles: 1971 for javafile in javafiles:
1944 classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class' 1972 classfile = TimeStampFile(outputDir + javafile[len(sourceDir):-len('java')] + 'class')
1945 if not exists(classfile) or os.path.getmtime(javafile) > os.path.getmtime(classfile): 1973 if not classfile.exists() or classfile.isOlderThan(javafile):
1946 mustBuild = True 1974 mustBuild = True
1947 break 1975 break
1976
1977 aps = p.annotation_processors()
1978 apsOutOfDate = p.update_current_annotation_processors_file()
1979 if apsOutOfDate:
1980 logv('[annotation processors for {0} changed]'.format(p.name))
1981 mustBuild = True
1948 1982
1949 if not mustBuild: 1983 if not mustBuild:
1950 logv('[all class files for {0} are up to date - skipping]'.format(p.name)) 1984 logv('[all class files for {0} are up to date - skipping]'.format(p.name))
1951 continue 1985 continue
1952 1986
1953 if len(javafilelist) == 0: 1987 if len(javafilelist) == 0:
1954 logv('[no Java sources for {0} - skipping]'.format(p.name)) 1988 logv('[no Java sources for {0} - skipping]'.format(p.name))
1955 continue 1989 continue
1990
1991 # Ensure that the output directories are clean
1992 prepareOutputDirs(p, True)
1956 1993
1957 built.add(p.name) 1994 built.add(p.name)
1958 1995
1959 argfileName = join(p.dir, 'javafilelist.txt') 1996 argfileName = join(p.dir, 'javafilelist.txt')
1960 argfile = open(argfileName, 'wb') 1997 argfile = open(argfileName, 'wb')
1961 argfile.write('\n'.join(javafilelist)) 1998 argfile.write('\n'.join(javafilelist))
1962 argfile.close() 1999 argfile.close()
1963 2000
1964 processorArgs = [] 2001 processorArgs = []
1965 2002
1966 ap = p.annotation_processors() 2003 if len(aps) > 0:
1967 if len(ap) > 0: 2004 processorPath = classpath(aps, resolve=True)
1968 processorPath = classpath(ap, resolve=True)
1969 genDir = p.source_gen_dir() 2005 genDir = p.source_gen_dir()
1970 if exists(genDir): 2006 if exists(genDir):
1971 shutil.rmtree(genDir) 2007 shutil.rmtree(genDir)
1972 os.mkdir(genDir) 2008 os.mkdir(genDir)
1973 processorArgs += ['-processorpath', join(processorPath), '-s', genDir] 2009 processorArgs += ['-processorpath', join(processorPath), '-s', genDir]