OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | 2 # Copyright (c) 2012 Google Inc. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Utility functions to perform Xcode-style build steps. | 6 """Utility functions to perform Xcode-style build steps. |
7 | 7 |
8 These functions are executed via gyp-mac-tool when using the Makefile generator. | 8 These functions are executed via gyp-mac-tool when using the Makefile generator. |
9 """ | 9 """ |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 fp.close() | 109 fp.close() |
110 if header.startswith("\xFE\xFF"): | 110 if header.startswith("\xFE\xFF"): |
111 return "UTF-16" | 111 return "UTF-16" |
112 elif header.startswith("\xFF\xFE"): | 112 elif header.startswith("\xFF\xFE"): |
113 return "UTF-16" | 113 return "UTF-16" |
114 elif header.startswith("\xEF\xBB\xBF"): | 114 elif header.startswith("\xEF\xBB\xBF"): |
115 return "UTF-8" | 115 return "UTF-8" |
116 else: | 116 else: |
117 return None | 117 return None |
118 | 118 |
119 def ExecCopyInfoPlist(self, source, dest): | 119 def ExecCopyInfoPlist(self, source, dest, *keys): |
120 """Copies the |source| Info.plist to the destination directory |dest|.""" | 120 """Copies the |source| Info.plist to the destination directory |dest|.""" |
121 # Read the source Info.plist into memory. | 121 # Read the source Info.plist into memory. |
122 fd = open(source, 'r') | 122 fd = open(source, 'r') |
123 lines = fd.read() | 123 lines = fd.read() |
124 fd.close() | 124 fd.close() |
125 | 125 |
| 126 # Insert synthesized key/value pairs (e.g. BuildMachineOSBuild). |
| 127 plist = plistlib.readPlistFromString(lines) |
| 128 plist = dict(plist.items() + zip(keys[::2], keys[1::2])) |
| 129 lines = plistlib.writePlistToString(plist) |
| 130 |
126 # Go through all the environment variables and replace them as variables in | 131 # Go through all the environment variables and replace them as variables in |
127 # the file. | 132 # the file. |
128 IDENT_RE = re.compile('[/\s]') | 133 IDENT_RE = re.compile('[/\s]') |
129 for key in os.environ: | 134 for key in os.environ: |
130 if key.startswith('_'): | 135 if key.startswith('_'): |
131 continue | 136 continue |
132 evar = '${%s}' % key | 137 evar = '${%s}' % key |
133 evalue = os.environ[key] | 138 evalue = os.environ[key] |
134 lines = string.replace(lines, evar, evalue) | 139 lines = string.replace(lines, evar, evalue) |
135 | 140 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 def _Relink(self, dest, link): | 241 def _Relink(self, dest, link): |
237 """Creates a symlink to |dest| named |link|. If |link| already exists, | 242 """Creates a symlink to |dest| named |link|. If |link| already exists, |
238 it is overwritten.""" | 243 it is overwritten.""" |
239 if os.path.lexists(link): | 244 if os.path.lexists(link): |
240 os.remove(link) | 245 os.remove(link) |
241 os.symlink(dest, link) | 246 os.symlink(dest, link) |
242 | 247 |
243 | 248 |
244 if __name__ == '__main__': | 249 if __name__ == '__main__': |
245 sys.exit(main(sys.argv[1:])) | 250 sys.exit(main(sys.argv[1:])) |
OLD | NEW |