comparison mxtool/mx.py @ 17169:a8c0553cb2e4

restore support for expanding environment variables in suite declarations
author Doug Simon <doug.simon@oracle.com>
date Fri, 19 Sep 2014 22:52:25 +0200
parents 30dda118ef3d
children d6c7c530ca84
comparison
equal deleted inserted replaced
17168:65c75f0bfc7b 17169:a8c0553cb2e4
845 845
846 attrs = m.get(name) 846 attrs = m.get(name)
847 if attrs is None: 847 if attrs is None:
848 attrs = OrderedDict() 848 attrs = OrderedDict()
849 m[name] = attrs 849 m[name] = attrs
850 value = expandvars_in_property(value)
851 attrs[attr] = value 850 attrs[attr] = value
852 return suite 851 return suite
853 852
854 # TODO: remove this command once all repos have transitioned 853 # TODO: remove this command once all repos have transitioned
855 # to the new project format 854 # to the new project format
963 962
964 suffix = 1 963 suffix = 1
965 suite = None 964 suite = None
966 dictName = 'suite' 965 dictName = 'suite'
967 966
967 def expand(value, context):
968 if isinstance(value, types.DictionaryType):
969 for n, v in value.iteritems():
970 value[n] = expand(v, context + [n])
971 elif isinstance(value, types.ListType):
972 for i in range(len(value)):
973 value[i] = expand(value[i], context + [str(i)])
974 else:
975 if not isinstance(value, types.StringTypes):
976 abort('value of ' + '.'.join(context) + ' is of unexpected type ' + str(type(value)))
977 value = expandvars(value)
978 if '$' in value or '%' in value:
979 abort('value of ' + '.'.join(context) + ' contains an undefined environment variable: ' + value)
980
981 return value
982
968 moduleName = 'projects' 983 moduleName = 'projects'
969 modulePath = join(mxDir, moduleName + '.py') 984 modulePath = join(mxDir, moduleName + '.py')
970 while exists(modulePath): 985 while exists(modulePath):
971 986
972 savedModule = sys.modules.get(moduleName) 987 savedModule = sys.modules.get(moduleName)
994 # revert the Python path 1009 # revert the Python path
995 del sys.path[0] 1010 del sys.path[0]
996 1011
997 if not hasattr(module, dictName): 1012 if not hasattr(module, dictName):
998 abort(modulePath + ' must define a variable named "' + dictName + '"') 1013 abort(modulePath + ' must define a variable named "' + dictName + '"')
999 d = getattr(module, dictName) 1014 d = expand(getattr(module, dictName), [dictName])
1000 sections = ['projects', 'libraries', 'jrelibraries', 'distributions'] + (['distribution_extensions'] if suite else ['name', 'mxversion']) 1015 sections = ['projects', 'libraries', 'jrelibraries', 'distributions'] + (['distribution_extensions'] if suite else ['name', 'mxversion'])
1001 unknown = d.viewkeys() - sections 1016 unknown = d.viewkeys() - sections
1002 if unknown: 1017 if unknown:
1003 abort(modulePath + ' defines unsupported suite sections: ' + ', '.join(unknown)) 1018 abort(modulePath + ' defines unsupported suite sections: ' + ', '.join(unknown))
1004 1019