comparison mxtool/mx.py @ 17183:4046e014f29f

mx: removed convertprojects
author Doug Simon <doug.simon@oracle.com>
date Tue, 23 Sep 2014 12:53:40 +0200
parents d6c7c530ca84
children 1cc8b62b4d37
comparison
equal deleted inserted replaced
17182:d6c7c530ca84 17183:4046e014f29f
848 attrs = OrderedDict() 848 attrs = OrderedDict()
849 m[name] = attrs 849 m[name] = attrs
850 attrs[attr] = value 850 attrs[attr] = value
851 return suite 851 return suite
852 852
853 # TODO: remove this command once all repos have transitioned
854 # to the new project format
855 def convertprojects(args, verbose=True):
856 """convert old style projects file to projects*.py file(s)"""
857
858 class Printer:
859 def __init__(self, fp, indent):
860 self.fp = fp
861 self.indent = indent
862 self.prefix = ''
863 def println(self, s):
864 if len(s) == 0:
865 print >> self.fp, s
866 else:
867 print >> self.fp, self.prefix + s
868 def inc(self):
869 self.prefix = ''.rjust(len(self.prefix) + self.indent)
870 def dec(self):
871 self.prefix = ''.rjust(len(self.prefix) - self.indent)
872
873 list_attrs = ['urls', 'dependencies', 'sourceUrls', 'sourceDirs', 'annotationProcessors', 'exclude', 'distDependencies']
874
875 for projectsFile in args:
876 suite = _read_projects_file(projectsFile)
877 def print_attrs(p, name, attrs, is_last=False):
878 p.println('"' + name + '" : {')
879 p.inc()
880 for n, v in attrs.iteritems():
881 if n in list_attrs:
882 if len(v) == 0:
883 p.println('"{}" : [],'.format(n))
884 else:
885 v = [e.strip() for e in v.split(',')]
886 if len(v) == 1:
887 p.println('"{}" : ["{}"],'.format(n, v[0]))
888 else:
889 p.println('"{}" : ['.format(n))
890 p.inc()
891 for e in v:
892 p.println('"' + e + '",')
893 p.dec()
894 p.println('],')
895 else:
896 p.println('"{}" : "{}",'.format(n, v))
897 p.dec()
898 if is_last:
899 p.println('}')
900 else:
901 p.println('},')
902 p.println('')
903
904 def print_section(p, sname, suite, is_last=False):
905 section = suite.get(sname)
906 if section:
907 p.println('"' + sname + '" : {')
908 p.inc()
909 i = 0
910 for name, attrs in section.iteritems():
911 i = i + 1
912 print_attrs(p, name, attrs, i == len(section))
913
914 p.dec()
915 if is_last:
916 p.println('}')
917 else:
918 p.println('},')
919 p.println('')
920
921 existing, suitePyFile = _load_suite_dict(dirname(projectsFile))
922 if existing:
923 assert existing['name'] == suite.pop('name')
924 assert existing['mxversion'] == suite.pop('mxversion')
925 for s in ['projects', 'libraries', 'jrelibraries', 'distributions']:
926 section = suite[s]
927 for k in existing[s].iterkeys():
928 duplicate = section.pop(k)
929 if duplicate and s == 'distributions':
930 original = existing[s][k]
931 extensions = [d for d in duplicate['dependencies'].split(',') if d not in original['dependencies']]
932 if len(extensions):
933 extensions = ','.join(extensions)
934 suite.setdefault('distribution_extensions', {})[k] = {'dependencies' : extensions}
935 if len(section) == 0:
936 suite.pop(s)
937
938 if len(suite):
939 out = StringIO.StringIO()
940 p = Printer(out, 2)
941 p.println(('extra' if existing else 'suite') + ' = {')
942 p.inc()
943 if not existing:
944 p.println('"mxversion" : "' + suite['mxversion'] + '",')
945 p.println('"name" : "' + suite['name'] + '",')
946 print_section(p, 'libraries', suite)
947 print_section(p, 'jrelibraries', suite)
948 print_section(p, 'projects', suite)
949 print_section(p, 'distributions', suite)
950 if existing and suite.has_key('distribution_extensions'):
951 print_section(p, 'distribution_extensions', suite, is_last=True)
952
953 p.dec()
954 p.println('}')
955
956 with open(suitePyFile, 'w') as fp:
957 fp.write(out.getvalue())
958 if verbose:
959 print 'created: ' + suitePyFile
960
961 def _load_suite_dict(mxDir): 853 def _load_suite_dict(mxDir):
962 854
963 suffix = 1 855 suffix = 1
964 suite = None 856 suite = None
965 dictName = 'suite' 857 dictName = 'suite'
1078 970
1079 def __str__(self): 971 def __str__(self):
1080 return self.name 972 return self.name
1081 973
1082 def _load_projects(self): 974 def _load_projects(self):
1083 # TODO: remove once mx/projects has been deprecated
1084 projectsFile = join(self.mxDir, 'projects')
1085 if exists(projectsFile):
1086 convertprojects([projectsFile], verbose=False)
1087
1088 suitePyFile = join(self.mxDir, 'suite.py') 975 suitePyFile = join(self.mxDir, 'suite.py')
1089 if not exists(suitePyFile): 976 if not exists(suitePyFile):
1090 return 977 return
1091 978
1092 suiteDict, _ = _load_suite_dict(self.mxDir) 979 suiteDict, _ = _load_suite_dict(self.mxDir)
5180 # Suite extensions should not update this table directly, but use update_commands 5067 # Suite extensions should not update this table directly, but use update_commands
5181 _commands = { 5068 _commands = {
5182 'about': [about, ''], 5069 'about': [about, ''],
5183 'build': [build, '[options]'], 5070 'build': [build, '[options]'],
5184 'checkstyle': [checkstyle, ''], 5071 'checkstyle': [checkstyle, ''],
5185 'convertprojects' : [convertprojects, ''],
5186 'canonicalizeprojects': [canonicalizeprojects, ''], 5072 'canonicalizeprojects': [canonicalizeprojects, ''],
5187 'clean': [clean, ''], 5073 'clean': [clean, ''],
5188 'eclipseinit': [eclipseinit, ''], 5074 'eclipseinit': [eclipseinit, ''],
5189 'eclipseformat': [eclipseformat, ''], 5075 'eclipseformat': [eclipseformat, ''],
5190 'exportlibs': [exportlibs, ''], 5076 'exportlibs': [exportlibs, ''],