diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-03-20 11:38:55 -0700 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-03-20 13:13:33 -0700 |
commit | 1d57949ea5bae66b27febc2edcfc7ae0f10be716 (patch) | |
tree | d7114134e4ff7fe3f129e16c175ba6dedfb49fe9 /android/tools | |
parent | 417c67d3c58c82d000b103070abf241c9de414b6 (diff) | |
download | external_qemu-1d57949ea5bae66b27febc2edcfc7ae0f10be716.zip external_qemu-1d57949ea5bae66b27febc2edcfc7ae0f10be716.tar.gz external_qemu-1d57949ea5bae66b27febc2edcfc7ae0f10be716.tar.bz2 |
Support 'enum' type in hardware-properties.ini file
This CL adds new 'enum' type to the types supported by the script.
Enumerated types should be formatted as such:
enum(type: val1[, val2[, ..., valN])
where:
- 'type' defines type of enumerated values, and must be one of the types
listed in typesToMacros
- 'val1'... 'valN' lists enumerated values, separated with a comma.
- '...' is a special value indicating that AVD editor may set property
value that doesn't match values enumerated in the .ini file. However,
default value set for the property must match one of the enumerated
values.
Change-Id: Id5c1c2940a956002e9e01a2d2456b6218f1f3742
Diffstat (limited to 'android/tools')
-rwxr-xr-x | android/tools/gen-hw-config.py | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/android/tools/gen-hw-config.py b/android/tools/gen-hw-config.py index 3822485..a55d7a3 100755 --- a/android/tools/gen-hw-config.py +++ b/android/tools/gen-hw-config.py @@ -28,7 +28,7 @@ def quoteStringForC(str): # a dictionary that maps item types as they appear in the .ini # file into macro names in the generated C header # -typesToMacros = { +typesToMacros = { 'integer': 'HWCFG_INT', 'string': 'HWCFG_STRING', 'boolean': 'HWCFG_BOOL', @@ -69,12 +69,69 @@ class Item: self.default = None self.abstract = "" self.description = "" + self.enum_values = [] + + # gets base type for an enum value. + # This is a very basic implementation of enum parser that assumes that enum + # is formatted as such: + # + # enum(type: val1[, val2[, ..., valN] [, ...]) + # + # where: + # - 'type' defines type of enumerated values, and must be one of the types + # listed in typesToMacros + # - 'val1'... 'valN' lists enumerated values, separated with a comma. + # - '...' is a special value indicating that AVD editor may set property + # value that doesn't match values enumerated in the .ini file. However, + # default value set for the property must match one of the enumerated + # values. + # This method provides some basic checking for the format, but it could, or + # should be improved. + # + def trueenumtype(self,type): + # Make sure enum ends with a ')' + if not type.endswith(")"): + print"Bad enum fomat in '" + type + "'" + sys.exit(1) + # Cut substring between 'enum(', and terminating ')' + enum_data = type[5:len(type)-1] + # Locate enum's value type + type_index = enum_data.find(':') + if type_index == -1: + print "Property '" + self.name + "': Value type is missing in enum." + sys.exit(1) + value_type = enum_data[:type_index].strip() + # Make sure value type is known + if not value_type in typesToMacros: + print "Property '" + self.name + "': Unknown value type '" + value_type + "' in enum." + sys.exit(1) + # Save list of enumerated values, stripped of spaces. + for value in enum_data[type_index+1:].split(','): + self.enum_values.append(value.strip()) + return value_type + + # gets true basic type for a type obtained from the .ini file + # Here we simply check if type is an enum, and if so, we extract basic + # type for enumerated values. + def truetype(self,type): + if type.startswith("enum("): + return self.trueenumtype(type.strip()) + return type def add(self,key,val): if key == 'type': - self.type = val + self.type = self.truetype(val) elif key == 'default': - self.default = val + if len(val) > 0 and len(self.enum_values) > 0: + # Make sure that default value (if set) is present in enum. + if self.enum_values.count(val) == 0: + print "Property '" + self.name + "': Default value '" + val + "' is missing in enum: ", + print self.enum_values, + sys.exit(1) + else: + self.default = val + else: + self.default = val elif key == 'abstract': self.abstract = val elif key == 'description': |