e59341d91538de6cba7bd68e22dfbc8496a03187b9a1f3b8f9788b45b60239958f0d7fbb848531a2de9ccf06d11f48b37d4ea37ae9d2f68e9c53d6943aa50d 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (c) 2011 Google Inc. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. """gypd output module
  5. This module produces gyp input as its output. Output files are given the
  6. .gypd extension to avoid overwriting the .gyp files that they are generated
  7. from. Internal references to .gyp files (such as those found in
  8. "dependencies" sections) are not adjusted to point to .gypd files instead;
  9. unlike other paths, which are relative to the .gyp or .gypd file, such paths
  10. are relative to the directory from which gyp was run to create the .gypd file.
  11. This generator module is intended to be a sample and a debugging aid, hence
  12. the "d" for "debug" in .gypd. It is useful to inspect the results of the
  13. various merges, expansions, and conditional evaluations performed by gyp
  14. and to see a representation of what would be fed to a generator module.
  15. It's not advisable to rename .gypd files produced by this module to .gyp,
  16. because they will have all merges, expansions, and evaluations already
  17. performed and the relevant constructs not present in the output; paths to
  18. dependencies may be wrong; and various sections that do not belong in .gyp
  19. files such as such as "included_files" and "*_excluded" will be present.
  20. Output will also be stripped of comments. This is not intended to be a
  21. general-purpose gyp pretty-printer; for that, you probably just want to
  22. run "pprint.pprint(eval(open('source.gyp').read()))", which will still strip
  23. comments but won't do all of the other things done to this module's output.
  24. The specific formatting of the output generated by this module is subject
  25. to change.
  26. """
  27. import gyp.common
  28. import pprint
  29. # These variables should just be spit back out as variable references.
  30. _generator_identity_variables = [
  31. "CONFIGURATION_NAME",
  32. "EXECUTABLE_PREFIX",
  33. "EXECUTABLE_SUFFIX",
  34. "INTERMEDIATE_DIR",
  35. "LIB_DIR",
  36. "PRODUCT_DIR",
  37. "RULE_INPUT_ROOT",
  38. "RULE_INPUT_DIRNAME",
  39. "RULE_INPUT_EXT",
  40. "RULE_INPUT_NAME",
  41. "RULE_INPUT_PATH",
  42. "SHARED_INTERMEDIATE_DIR",
  43. "SHARED_LIB_DIR",
  44. "SHARED_LIB_PREFIX",
  45. "SHARED_LIB_SUFFIX",
  46. "STATIC_LIB_PREFIX",
  47. "STATIC_LIB_SUFFIX",
  48. ]
  49. # gypd doesn't define a default value for OS like many other generator
  50. # modules. Specify "-D OS=whatever" on the command line to provide a value.
  51. generator_default_variables = {}
  52. # gypd supports multiple toolsets
  53. generator_supports_multiple_toolsets = True
  54. # TODO(mark): This always uses <, which isn't right. The input module should
  55. # notify the generator to tell it which phase it is operating in, and this
  56. # module should use < for the early phase and then switch to > for the late
  57. # phase. Bonus points for carrying @ back into the output too.
  58. for v in _generator_identity_variables:
  59. generator_default_variables[v] = "<(%s)" % v
  60. def GenerateOutput(target_list, target_dicts, data, params):
  61. output_files = {}
  62. for qualified_target in target_list:
  63. [input_file, target] = gyp.common.ParseQualifiedTarget(qualified_target)[0:2]
  64. if input_file[-4:] != ".gyp":
  65. continue
  66. input_file_stem = input_file[:-4]
  67. output_file = input_file_stem + params["options"].suffix + ".gypd"
  68. output_files[output_file] = output_files.get(output_file, input_file)
  69. for output_file, input_file in output_files.items():
  70. output = open(output_file, "w")
  71. pprint.pprint(data[input_file], output)
  72. output.close()