()
| 293 | |
| 294 | |
| 295 | def main(): |
| 296 | parser = OptionParser() |
| 297 | parser.add_option("-r", "--replace", action="append", |
| 298 | help="Replaces substrings. If passed a=b, replaces all substrs a with b.") |
| 299 | (options, args) = parser.parse_args() |
| 300 | |
| 301 | if len(args) != 1: |
| 302 | raise Exception("Need one argument which is the .gypi file to read.") |
| 303 | |
| 304 | data = LoadPythonDictionary(args[0]) |
| 305 | if options.replace: |
| 306 | # Do replacements for all specified patterns. |
| 307 | for replace in options.replace: |
| 308 | split = replace.split('=') |
| 309 | # Allow "foo=" to replace with nothing. |
| 310 | if len(split) == 1: |
| 311 | split.append('') |
| 312 | assert len(split) == 2, "Replacement must be of the form 'key=value'." |
| 313 | data = ReplaceSubstrings(data, split[0], split[1]) |
| 314 | |
| 315 | gn_dict = {} |
| 316 | for key in data: |
| 317 | gn_key = key.replace('-', '_') |
| 318 | # Sometimes .gypi files use the GYP syntax with percents at the end of the |
| 319 | # variable name (to indicate not to overwrite a previously-defined value): |
| 320 | # 'foo%': 'bar', |
| 321 | # Convert these to regular variables. |
| 322 | if len(key) > 1 and key[len(key) - 1] == '%': |
| 323 | gn_dict[gn_key[:-1]] = data[key] |
| 324 | else: |
| 325 | gn_dict[gn_key] = data[key] |
| 326 | |
| 327 | print(ToGNString(DeduplicateLists(gn_dict))) |
| 328 | |
| 329 | if __name__ == '__main__': |
| 330 | try: |
no test coverage detected
searching dependent graphs…