this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Switch back to generating empty classes

+71 -61
+71 -61
tools/darling-stub-gen
··· 6 6 library = False 7 7 framework = False 8 8 private_framework = False 9 - uses_objc = False 10 - full_path = "" 11 - output_dir = "" 12 - target_name = "" 13 - header_dir = "" 14 - source_dir = "" 15 9 16 10 # Constants 17 11 library_prefix = "/usr/lib/" ··· 20 14 21 15 class_dump = "~/bin/class-dump" 22 16 23 - copyright ="""/* 17 + copyright = """/* 24 18 This file is part of Darling. 25 19 26 20 Copyright (C) 2017 Lubos Dolezel ··· 57 51 } 58 52 59 53 """ 54 + 55 + 60 56 # Utility functions 61 57 def usage(): 62 - print("Usage: " + sys.argv[0] + " <Mach-O> <output directory>") 63 - exit(1) 58 + print("Usage: " + sys.argv[0] + " <Mach-O> <output directory>") 59 + exit(1) 60 + 64 61 65 62 def extract_library_name(name): 66 - prefix_len = len(library_prefix) + len("lib") 67 - ext_len = len(".dylib") 63 + prefix_len = len(library_prefix) + len("lib") 64 + ext_len = len(".dylib") 68 65 69 - return name[prefix_len : len(name) - ext_len] 66 + return name[prefix_len: len(name) - ext_len] 67 + 70 68 71 69 def extract_framework_name(name): 72 - return name[name.rfind("/") + 1 :] 70 + return name[name.rfind("/") + 1:] 71 + 73 72 74 73 def write_objc_source_file_locs(cmake_file, classes, num_spaces): 75 74 for cls in classes: 76 75 cmake_file.write(" " * num_spaces + "src/%s.m\n" % cls) 77 76 77 + 78 78 # Main program start 79 79 if len(sys.argv) != 3: 80 - usage() 80 + usage() 81 81 82 82 full_path = sys.argv[1] 83 83 output_dir = sys.argv[2] 84 84 85 85 try: 86 - os.makedirs(output_dir) 86 + os.makedirs(output_dir) 87 87 except FileExistsError: 88 - pass 89 - 88 + pass 90 89 91 90 if len(full_path) > len(library_prefix) and full_path[:len(library_prefix)] == library_prefix: 92 - library = True 93 - target_name = extract_library_name(full_path) 91 + library = True 92 + target_name = extract_library_name(full_path) 94 93 elif len(full_path) > len(framework_prefix) and full_path[:len(framework_prefix)] == framework_prefix: 95 - framework = True 96 - target_name = extract_framework_name(full_path) 97 - elif len(full_path) > len(private_framework_prefix) and full_path[:len(private_framework_prefix)] == private_framework_prefix: 98 - private_framework = True 99 - target_name = extract_framework_name(full_path) 94 + framework = True 95 + target_name = extract_framework_name(full_path) 96 + elif len(full_path) > len(private_framework_prefix) and full_path[ 97 + :len(private_framework_prefix)] == private_framework_prefix: 98 + private_framework = True 99 + target_name = extract_framework_name(full_path) 100 100 else: 101 - print("Failed to recognize Mach-O location") 102 - exit(1) 101 + print("Failed to recognize Mach-O location") 102 + target_name = None 103 + exit(1) 103 104 104 105 header_dir = output_dir + "/include/" + target_name + "/" 105 106 source_dir = output_dir + "/src/" ··· 121 122 122 123 functions = [] 123 124 for line in c_func_out.splitlines(): 124 - 125 + 125 126 if line == "": 126 127 continue 127 128 128 129 address, id, name = line.split(" ") 129 130 # Remove the underscore 130 - name = name[1 : ] 131 + name = name[1:] 131 132 132 133 if id == "T": 133 134 functions.append(name) 134 135 136 + class_dump_output = subprocess.check_output(["class-dump", full_path]).decode('utf8').strip() 137 + uses_objc = "This file does not contain any Objective-C runtime information." not in class_dump_output 138 + 135 139 c_header = open(header_dir + target_name + ".h", "w") 136 - c_source = open(source_dir + target_name + ".c", "w") 140 + c_source = open(source_dir + target_name + ".m", "w") if uses_objc else open(source_dir + target_name + ".c", "w") 137 141 138 142 c_header.write(copyright) 139 143 c_source.write(copyright) ··· 168 172 cmake.write("set(DYLIB_INSTALL_NAME \"%s\")\n" % full_path) 169 173 cmake.write("set(DYLIB_COMPAT_VERSION \"%s\")\n" % compat) 170 174 cmake.write("set(DYLIB_CURRENT_VERSION \"%s\")\n\n" % current) 171 - 172 - class_dump_output = subprocess.check_output(["class-dump", full_path]).decode('utf8').strip() 173 - 174 - uses_objc = "This file does not contain any Objective-C runtime information." not in class_dump_output 175 175 176 176 c_header.write("\n#ifndef _%s_H_\n#define _%s_H_\n\n" % (target_name, target_name)) 177 177 178 178 if uses_objc: 179 179 c_header.write("#import <Foundation/Foundation.h>\n\n") 180 - 181 - typedef_void_regex = re.compile("(typedef void.+?;)", re.DOTALL | re.MULTILINE) 182 - for typedef_void_def in typedef_void_regex.finditer(class_dump_output): 183 - c_header.write(typedef_void_def.groups()[0]) 184 - c_header.write("\n\n") 185 180 186 - structs_regex = re.compile("(struct (.+?)};)", re.DOTALL | re.MULTILINE) 187 - for struct_def in structs_regex.finditer(class_dump_output): 188 - c_header.write(struct_def.groups()[0]) 189 - c_header.write("\n\n") 181 + # typedef_void_regex = re.compile("(typedef void.+?;)", re.DOTALL | re.MULTILINE) 182 + # for typedef_void_def in typedef_void_regex.finditer(class_dump_output): 183 + # c_header.write(typedef_void_def.groups()[0]) 184 + # c_header.write("\n\n") 185 + # 186 + # blacklisted_structs = ["_NSRange"] 187 + # structs_regex = re.compile("(struct (.+?) {.+?};)", re.DOTALL | re.MULTILINE) 188 + # for struct_def in structs_regex.finditer(class_dump_output): 189 + # struct_contents, struct_name = struct_def.groups() 190 + # if struct_name in blacklisted_structs: 191 + # continue 192 + # c_header.write(struct_contents) 193 + # c_header.write("\n\n") 194 + # 195 + # typedef_struct_regex = re.compile("(typedef struct {.+?}.+?;)", re.DOTALL | re.MULTILINE) 196 + # for typedef_struct_def in typedef_struct_regex.finditer(class_dump_output): 197 + # c_header.write(typedef_struct_def.groups()[0]) 198 + # c_header.write("\n\n") 190 199 191 - typedef_struct_regex = re.compile("(typedef struct {.+?}.+?;)", re.DOTALL | re.MULTILINE) 192 - for typedef_struct_def in typedef_struct_regex.finditer(class_dump_output): 193 - c_header.write(typedef_struct_def.groups()[0]) 194 - c_header.write("\n\n") 200 + classes = [] 195 201 196 - get_class_names = re.compile("@interface (.+) :.+") 197 - classes = get_class_names.findall(class_dump_output) 198 - 199 - protocols_regex = re.compile("(@protocol (.+?)[\n<].+?@end)", re.DOTALL | re.MULTILINE) 202 + protocols_regex = re.compile("(@protocol (.+?)[\n ].+?@end)", re.DOTALL | re.MULTILINE) 200 203 classes_regex = re.compile("(@interface (.+?) :.+?@end)", re.DOTALL | re.MULTILINE) 201 - 204 + 205 + blacklisted_protocols = ["NSObject", "NSSecureCoding", "NSCoding", "NSCopying"] 202 206 for protocol_def in protocols_regex.finditer(class_dump_output): 203 207 protocol_contents, protocol_name = protocol_def.groups() 208 + if protocol_name in blacklisted_protocols: 209 + continue 204 210 proto_header = open(header_dir + protocol_name + ".h", "w") 205 211 proto_header.write(copyright) 206 - proto_header.write("#import <%s/%s.h>\n\n" % (target_name, target_name)) 207 - proto_header.write(protocol_contents) 212 + proto_header.write("#include <Foundation/Foundation.h>\n\n") 213 + # proto_header.write(protocol_contents) 214 + proto_header.write("@protocol %s\n\n@end\n" % protocol_name) 208 215 proto_header.close() 209 216 c_header.write("#import <%s/%s.h>\n" % (target_name, protocol_name)) 210 217 211 218 for class_def in classes_regex.finditer(class_dump_output): 212 219 class_contents, class_name = class_def.groups() 220 + classes.append(class_name) 213 221 class_header = open(header_dir + class_name + ".h", "w") 214 222 class_header.write(copyright) 215 - class_header.write("#import <%s/%s.h>\n\n" % (target_name, target_name)) 216 - class_header.write(class_contents) 223 + class_header.write("#include <Foundation/Foundation.h>\n\n") 224 + # class_header.write(class_contents) 225 + class_header.write("@interface %s : NSObject\n\n@end\n" % class_name) 217 226 class_header.close() 218 227 c_header.write("#import <%s/%s.h>\n" % (target_name, class_name)) 219 228 ··· 232 241 233 242 if library: 234 243 cmake.write("add_darling_library(%s SHARED\n" % target_name) 235 - cmake.write(" src/%s.c\n" % target_name) 236 - write_objc_source_file_locs(cmake, classes, 4) 244 + cmake.write(" src/%s." % target_name + ("m" if uses_objc else "c") + "\n") 245 + if uses_objc: 246 + write_objc_source_file_locs(cmake, classes, 4) 237 247 cmake.write(")\n") 238 248 cmake.write("make_fat(%s)\n" % target_name) 239 - libraries = "system objc" if uses_objc else "system" 249 + libraries = "system objc Foundation" if uses_objc else "system" 240 250 cmake.write("target_link_libraries(%s %s)\n" % (target_name, libraries)) 241 251 cmake.write("install(TARGETS %s DESTINATION libexec/darling/usr/lib)\n" % target_name) 242 252 else: 243 - cmake.write("add_framework(%s\n" %target_name) 253 + cmake.write("add_framework(%s\n" % target_name) 244 254 cmake.write(" FAT\n CURRENT_VERSION\n") 245 255 if private_framework: 246 256 cmake.write(" PRIVATE\n") 247 257 cmake.write(" VERSION \"A\"\n\n") 248 258 cmake.write(" SOURCES\n") 249 - cmake.write(" src/%s.c\n" % target_name) 259 + cmake.write(" src/%s." % target_name + ("m" if uses_objc else "c") + "\n") 250 260 if uses_objc: 251 261 write_objc_source_file_locs(cmake, classes, 8) 252 262 ··· 259 269 cmake.write(" Foundation\n") 260 270 cmake.write(")\n") 261 271 262 - c_header.write("\n#endif\n") 272 + c_header.write("\n#endif\n")