| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 | 3 |
| 4 # Copyright 2014 The Crashpad Authors. All rights reserved. | 4 # Copyright 2014 The Crashpad Authors. All rights reserved. |
| 5 # | 5 # |
| 6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
| 8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
| 9 # | 9 # |
| 10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 # | 11 # |
| 12 # Unless required by applicable law or agreed to in writing, software | 12 # Unless required by applicable law or agreed to in writing, software |
| 13 # distributed under the License is distributed on an "AS IS" BASIS, | 13 # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 # See the License for the specific language governing permissions and | 15 # See the License for the specific language governing permissions and |
| 16 # limitations under the License. | 16 # limitations under the License. |
| 17 | 17 |
| 18 import argparse |
| 18 import os | 19 import os |
| 19 import re | 20 import re |
| 20 import subprocess | 21 import subprocess |
| 21 import sys | 22 import sys |
| 22 | 23 |
| 23 def FixUserImplementation(implementation): | 24 def FixUserImplementation(implementation): |
| 24 """Rewrites a MIG-generated user implementation (.c) file. | 25 """Rewrites a MIG-generated user implementation (.c) file. |
| 25 | 26 |
| 26 Rewrites the file at |implementation| by adding “__attribute__((unused))” to | 27 Rewrites the file at |implementation| by adding “__attribute__((unused))” to |
| 27 the definition of any structure typedefed as “__Reply” by searching for the | 28 the definition of any structure typedefed as “__Reply” by searching for the |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 #ifdef __cplusplus | 101 #ifdef __cplusplus |
| 101 } | 102 } |
| 102 #endif | 103 #endif |
| 103 ''' % (contents, declarations_text) | 104 ''' % (contents, declarations_text) |
| 104 file.seek(0) | 105 file.seek(0) |
| 105 file.truncate() | 106 file.truncate() |
| 106 file.write(contents) | 107 file.write(contents) |
| 107 file.close() | 108 file.close() |
| 108 | 109 |
| 109 def main(args): | 110 def main(args): |
| 110 if len(args) == 5: | 111 parser = argparse.ArgumentParser() |
| 111 (defs_file, user_c, server_c, user_h, server_h) = args | 112 parser.add_argument('--developer-dir', help='Path to Xcode') |
| 112 elif len(args) == 6: | 113 parser.add_argument('--sdk', help='Path to SDK') |
| 113 (defs_file, user_c, server_c, user_h, server_h, dev_dir) = args | 114 parser.add_argument('defs') |
| 114 os.environ['DEVELOPER_DIR'] = dev_dir | 115 parser.add_argument('user_c') |
| 115 else: | 116 parser.add_argument('server_c') |
| 116 assert False, "Wrong number of arguments" | 117 parser.add_argument('user_h') |
| 117 subprocess.check_call(['mig', | 118 parser.add_argument('server_h') |
| 118 '-user', user_c, | 119 parsed = parser.parse_args(args) |
| 119 '-server', server_c, | 120 |
| 120 '-header', user_h, | 121 command = ['mig', |
| 121 '-sheader', server_h, | 122 '-user', parsed.user_c, |
| 122 defs_file]) | 123 '-server', parsed.server_c, |
| 123 FixUserImplementation(user_c) | 124 '-header', parsed.user_h, |
| 124 server_declarations = FixServerImplementation(server_c) | 125 '-sheader', parsed.server_h, |
| 125 FixHeader(user_h) | 126 ] |
| 126 FixHeader(server_h, server_declarations) | 127 if parsed.sdk is not None: |
| 128 command.extend(['-isysroot', parsed.sdk]) |
| 129 if parsed.developer_dir is not None: |
| 130 os.environ['DEVELOPER_DIR'] = parsed.developer_dir |
| 131 command.append(parsed.defs) |
| 132 subprocess.check_call(command) |
| 133 FixUserImplementation(parsed.user_c) |
| 134 server_declarations = FixServerImplementation(parsed.server_c) |
| 135 FixHeader(parsed.user_h) |
| 136 FixHeader(parsed.server_h, server_declarations) |
| 127 | 137 |
| 128 if __name__ == '__main__': | 138 if __name__ == '__main__': |
| 129 sys.exit(main(sys.argv[1:])) | 139 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |