100-apply-2to3.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. --- a/src/mklibs
  2. +++ b/src/mklibs
  3. @@ -57,18 +57,18 @@ debuglevel = DEBUG_NORMAL
  4. def debug(level, *msg):
  5. if debuglevel >= level:
  6. - print string.join(msg)
  7. + print(' '.join(msg))
  8. # return a list of lines of output of the command
  9. def command(command, *args):
  10. - debug(DEBUG_SPAM, "calling", command, string.join(args))
  11. + debug(DEBUG_SPAM, "calling", command, ' '.join(args))
  12. pipe = os.popen(command + ' ' + ' '.join(args), 'r')
  13. output = pipe.read().strip()
  14. status = pipe.close()
  15. if status is not None and os.WEXITSTATUS(status) != 0:
  16. - print "Command failed with status", os.WEXITSTATUS(status), ":", \
  17. - command, string.join(args)
  18. - print "With output:", output
  19. + print("Command failed with status", os.WEXITSTATUS(status), ":", \
  20. + command, ' '.join(args))
  21. + print("With output:", output)
  22. sys.exit(1)
  23. return [i for i in output.split('\n') if i]
  24. @@ -204,7 +204,7 @@ class ProvidedSymbol(Symbol):
  25. # Return a set of symbols provided by a library
  26. def provided_symbols(obj):
  27. if not os.access(obj, os.F_OK):
  28. - raise Exception("Cannot find lib" + obj)
  29. + raise Exception("Cannot find lib " + obj)
  30. library = extract_soname(obj)
  31. output = command("mklibs-readelf", "--print-symbols-provided", obj)
  32. @@ -297,27 +297,27 @@ def usage(was_err):
  33. outfd = sys.stderr
  34. else:
  35. outfd = sys.stdout
  36. - print >> outfd, "Usage: mklibs [OPTION]... -d DEST FILE ..."
  37. - print >> outfd, "Make a set of minimal libraries for FILE(s) in DEST."
  38. - print >> outfd, ""
  39. - print >> outfd, " -d, --dest-dir DIRECTORY create libraries in DIRECTORY"
  40. - print >> outfd, " -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")"
  41. - print >> outfd, " -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s) to the library search path"
  42. - print >> outfd, " -l LIBRARY add LIBRARY always"
  43. - print >> outfd, " --ldlib LDLIB use LDLIB for the dynamic linker"
  44. - print >> outfd, " --libc-extras-dir DIRECTORY look for libc extra files in DIRECTORY"
  45. - print >> outfd, " --target TARGET prepend TARGET- to the gcc and binutils calls"
  46. - print >> outfd, " --root ROOT search in ROOT for library rpaths"
  47. - print >> outfd, " --sysroot ROOT prepend ROOT to all paths for libraries"
  48. - print >> outfd, " --gcc-options OPTIONS pass OPTIONS to gcc"
  49. - print >> outfd, " --libdir DIR use DIR (e.g. lib64) in place of lib in default paths"
  50. - print >> outfd, " -v, --verbose explain what is being done"
  51. - print >> outfd, " -h, --help display this help and exit"
  52. + print("Usage: mklibs [OPTION]... -d DEST FILE ...", file=outfd)
  53. + print("Make a set of minimal libraries for FILE(s) in DEST.", file=outfd)
  54. + print("", file=outfd)
  55. + print(" -d, --dest-dir DIRECTORY create libraries in DIRECTORY", file=outfd)
  56. + print(" -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")", file=outfd)
  57. + print(" -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s) to the library search path", file=outfd)
  58. + print(" -l LIBRARY add LIBRARY always", file=outfd)
  59. + print(" --ldlib LDLIB use LDLIB for the dynamic linker", file=outfd)
  60. + print(" --libc-extras-dir DIRECTORY look for libc extra files in DIRECTORY", file=outfd)
  61. + print(" --target TARGET prepend TARGET- to the gcc and binutils calls", file=outfd)
  62. + print(" --root ROOT search in ROOT for library rpaths", file=outfd)
  63. + print(" --sysroot ROOT prepend ROOT to all paths for libraries", file=outfd)
  64. + print(" --gcc-options OPTIONS pass OPTIONS to gcc", file=outfd)
  65. + print(" --libdir DIR use DIR (e.g. lib64) in place of lib in default paths", file=outfd)
  66. + print(" -v, --verbose explain what is being done", file=outfd)
  67. + print(" -h, --help display this help and exit", file=outfd)
  68. sys.exit(was_err)
  69. def version(vers):
  70. - print "mklibs: version ",vers
  71. - print ""
  72. + print("mklibs: version ",vers)
  73. + print("")
  74. #################### main ####################
  75. ## Usage: ./mklibs.py [OPTION]... -d DEST FILE ...
  76. @@ -368,8 +368,8 @@ script_pattern = re.compile("^#!\s*/")
  77. try:
  78. optlist, proglist = getopt.getopt(sys.argv[1:], opts, longopts)
  79. -except getopt.GetoptError, msg:
  80. - print >> sys.stderr, msg
  81. +except getopt.GetoptError as msg:
  82. + print(msg, file=sys.stderr)
  83. usage(1)
  84. for opt, arg in optlist:
  85. @@ -377,7 +377,7 @@ for opt, arg in optlist:
  86. if debuglevel < DEBUG_SPAM:
  87. debuglevel = debuglevel + 1
  88. elif opt == "-L":
  89. - lib_path.extend(string.split(arg, ":"))
  90. + lib_path.extend(arg.split(":"))
  91. elif opt in ("-d", "--dest-dir"):
  92. dest_path = arg
  93. elif opt in ("-D", "--no-default-lib"):
  94. @@ -396,17 +396,17 @@ for opt, arg in optlist:
  95. elif opt in ("-l",):
  96. force_libs.append(arg)
  97. elif opt == "--gcc-options":
  98. - gcc_options.extend(string.split(arg, " "))
  99. + gcc_options.extend(arg.split(" "))
  100. elif opt == "--libdir":
  101. libdir = arg
  102. elif opt in ("--help", "-h"):
  103. - usage(0)
  104. + usage(0)
  105. sys.exit(0)
  106. elif opt in ("--version", "-V"):
  107. version(vers)
  108. sys.exit(0)
  109. else:
  110. - print "WARNING: unknown option: " + opt + "\targ: " + arg
  111. + print("WARNING: unknown option: " + opt + "\targ: " + arg)
  112. if include_default_lib_path == "yes":
  113. lib_path.extend([a.replace("/lib/", "/" + libdir + "/") for a in default_lib_path])
  114. @@ -424,22 +424,22 @@ if ldlib == "LDLIB":
  115. objects = {} # map from inode to filename
  116. for prog in proglist:
  117. inode = os.stat(prog)[ST_INO]
  118. - if objects.has_key(inode):
  119. + if inode in objects:
  120. debug(DEBUG_SPAM, prog, "is a hardlink to", objects[inode])
  121. elif so_pattern.match(prog):
  122. debug(DEBUG_SPAM, prog, "is a library")
  123. - elif script_pattern.match(open(prog).read(256)):
  124. + elif script_pattern.match(open(prog, 'r', encoding='iso-8859-1').read(256)):
  125. debug(DEBUG_SPAM, prog, "is a script")
  126. else:
  127. objects[inode] = prog
  128. if not ldlib:
  129. - for obj in objects.values():
  130. + for obj in list(objects.values()):
  131. output = command("mklibs-readelf", "--print-interp", obj)
  132. if output:
  133. ldlib = output.pop()
  134. - if ldlib:
  135. - break
  136. + if ldlib:
  137. + break
  138. if not ldlib:
  139. sys.exit("E: Dynamic linker not found, aborting.")
  140. @@ -454,10 +454,10 @@ for obj in sorted(objects.values()):
  141. for rpath_elem in rpath_val:
  142. if not rpath_elem in lib_rpath:
  143. if debuglevel >= DEBUG_VERBOSE:
  144. - print "Adding rpath " + rpath_elem + " for " + obj
  145. + print("Adding rpath " + rpath_elem + " for " + obj)
  146. lib_rpath.append(rpath_elem)
  147. else:
  148. - print "warning: " + obj + " may need rpath, but --root not specified"
  149. + print("warning: " + obj + " may need rpath, but --root not specified")
  150. lib_path.extend(lib_rpath)
  151. @@ -465,12 +465,12 @@ passnr = 1
  152. available_libs = []
  153. previous_pass_unresolved = set()
  154. while 1:
  155. - debug(DEBUG_NORMAL, "I: library reduction pass", `passnr`)
  156. + debug(DEBUG_NORMAL, "I: library reduction pass", repr(passnr))
  157. if debuglevel >= DEBUG_VERBOSE:
  158. - print "Objects:",
  159. - for obj in sorted([x[string.rfind(x, '/') + 1:] for x in objects.values()]):
  160. - print obj,
  161. - print
  162. + print("Objects:", end=' ')
  163. + for obj in sorted([x[x.rfind('/') + 1:] for x in list(objects.values())]):
  164. + print(obj, end=' ')
  165. + print()
  166. passnr = passnr + 1
  167. # Gather all already reduced libraries and treat them as objects as well
  168. @@ -479,7 +479,7 @@ while 1:
  169. obj = dest_path + "/" + lib
  170. small_libs.append(obj)
  171. inode = os.stat(obj)[ST_INO]
  172. - if objects.has_key(inode):
  173. + if inode in objects:
  174. debug(DEBUG_SPAM, obj, "is hardlink to", objects[inode])
  175. else:
  176. objects[inode] = obj
  177. @@ -509,7 +509,7 @@ while 1:
  178. present_symbols = {}
  179. checked_libs = small_libs
  180. checked_libs.extend(available_libs)
  181. - checked_libs.append(ldlib)
  182. + checked_libs.append(sysroot + "/" + ldlib)
  183. for lib in checked_libs:
  184. for symbol in provided_symbols(lib):
  185. debug(DEBUG_SPAM, "present_symbols adding %s" % symbol)
  186. @@ -529,8 +529,8 @@ while 1:
  187. unresolved.add(name)
  188. num_unresolved = num_unresolved + 1
  189. - debug (DEBUG_NORMAL, `len(needed_symbols)`, "symbols,",
  190. - `num_unresolved`, "unresolved")
  191. + debug (DEBUG_NORMAL, repr(len(needed_symbols)), "symbols,",
  192. + repr(num_unresolved), "unresolved")
  193. if num_unresolved == 0:
  194. break
  195. @@ -539,7 +539,7 @@ while 1:
  196. # No progress in last pass. Verify all remaining symbols are weak.
  197. for name in unresolved:
  198. if not needed_symbols[name].weak:
  199. - print "WARNING: Unresolvable symbol %s" % name
  200. + print("WARNING: Unresolvable symbol %s" % name)
  201. break
  202. previous_pass_unresolved = unresolved
  203. @@ -641,9 +641,9 @@ while 1:
  204. command(target + "gcc", *cmd)
  205. ## DEBUG
  206. - debug(DEBUG_VERBOSE, so_file, "\t", `os.stat(so_file)[ST_SIZE]`)
  207. + debug(DEBUG_VERBOSE, so_file, "\t", repr(os.stat(so_file)[ST_SIZE]))
  208. debug(DEBUG_VERBOSE, dest_path + "/" + so_file_name + "-so", "\t",
  209. - `os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]`)
  210. + repr(os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]))
  211. # Finalising libs and cleaning up
  212. for lib in regexpfilter(os.listdir(dest_path), "(.*)-so$"):
  213. @@ -680,4 +680,4 @@ if not os.access(dest_path + "/" + ld_fu
  214. command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
  215. ld_file, dest_path + "/" + ld_full_path)
  216. -os.chmod(dest_path + "/" + ld_full_path, 0755)
  217. +os.chmod(dest_path + "/" + ld_full_path, 0o755)
  218. --- a/src/mklibs-copy
  219. +++ b/src/mklibs-copy
  220. @@ -51,9 +51,9 @@ def command(command, *args):
  221. output = pipe.read().strip()
  222. status = pipe.close()
  223. if status is not None and os.WEXITSTATUS(status) != 0:
  224. - print "Command failed with status", os.WEXITSTATUS(status), ":", \
  225. - command, ' '.join(args)
  226. - print "With output:", output
  227. + print("Command failed with status", os.WEXITSTATUS(status), ":", \
  228. + command, ' '.join(args))
  229. + print("With output:", output)
  230. sys.exit(1)
  231. return output.split('\n')
  232. @@ -134,8 +134,8 @@ def multiarch(paths):
  233. return paths
  234. def version(vers):
  235. - print "mklibs: version ",vers
  236. - print ""
  237. + print("mklibs: version ",vers)
  238. + print("")
  239. # Clean the environment
  240. vers="0.12"
  241. @@ -159,7 +159,7 @@ if include_default_lib_path:
  242. objects = {} # map from inode to filename
  243. for prog in proglist:
  244. inode = os.stat(prog)[ST_INO]
  245. - if objects.has_key(inode):
  246. + if inode in objects:
  247. logger.debug("%s is a hardlink to %s", prog, objects[inode])
  248. elif so_pattern.match(prog):
  249. logger.debug("%s is a library", prog)
  250. @@ -169,12 +169,12 @@ for prog in proglist:
  251. logger.debug("%s is no ELF", prog)
  252. if not ldlib:
  253. - for obj in objects.values():
  254. + for obj in list(objects.values()):
  255. output = command("mklibs-readelf", "-i", obj)
  256. - for x in output:
  257. + for x in output:
  258. ldlib = x
  259. - if ldlib:
  260. - break
  261. + if ldlib:
  262. + break
  263. if not ldlib:
  264. sys.exit("E: Dynamic linker not found, aborting.")
  265. @@ -182,7 +182,7 @@ if not ldlib:
  266. logger.info('Using %s as dynamic linker', ldlib)
  267. # Check for rpaths
  268. -for obj in objects.values():
  269. +for obj in list(objects.values()):
  270. rpath_val = rpath(obj)
  271. if rpath_val:
  272. if root:
  273. @@ -208,18 +208,18 @@ while 1:
  274. obj = dest_path + "/" + lib
  275. small_libs.append(obj)
  276. inode = os.stat(obj)[ST_INO]
  277. - if objects.has_key(inode):
  278. + if inode in objects:
  279. logger.debug("%s is hardlink to %s", obj, objects[inode])
  280. else:
  281. objects[inode] = obj
  282. - for obj in objects.values():
  283. + for obj in list(objects.values()):
  284. small_libs.append(obj)
  285. - logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.itervalues()]))
  286. + logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.values()]))
  287. libraries = set()
  288. - for obj in objects.values():
  289. + for obj in list(objects.values()):
  290. libraries.update(library_depends(obj))
  291. if libraries == previous_pass_libraries:
  292. @@ -272,4 +272,4 @@ if not os.access(dest_path + "/" + ld_fu
  293. command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
  294. ld_file, dest_path + "/" + ld_full_path)
  295. -os.chmod(dest_path + "/" + ld_full_path, 0755)
  296. +os.chmod(dest_path + "/" + ld_full_path, 0o755)