methods.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. def disable_warnings(self):
  2. # 'self' is the environment
  3. if self["platform"] == "windows" and not self["use_mingw"]:
  4. # We have to remove existing warning level defines before appending /w,
  5. # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
  6. WARN_FLAGS = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/W0"]
  7. self["CCFLAGS"] = [x for x in self["CCFLAGS"] if x not in WARN_FLAGS]
  8. self["CFLAGS"] = [x for x in self["CFLAGS"] if x not in WARN_FLAGS]
  9. self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if x not in WARN_FLAGS]
  10. self.AppendUnique(CCFLAGS=["/w"])
  11. else:
  12. self.AppendUnique(CCFLAGS=["-w"])
  13. def prepare_timer():
  14. import atexit
  15. import time
  16. def print_elapsed_time(time_at_start: float):
  17. time_elapsed = time.time() - time_at_start
  18. time_formatted = time.strftime("%H:%M:%S", time.gmtime(time_elapsed))
  19. time_centiseconds = round((time_elapsed % 1) * 100)
  20. print(f"[Time elapsed: {time_formatted}.{time_centiseconds}]")
  21. atexit.register(print_elapsed_time, time.time())
  22. def make_icu_data(target, source, env):
  23. dst = target[0].srcnode().abspath
  24. with open(dst, "w", encoding="utf-8", newline="\n") as g:
  25. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  26. g.write("/* (C) 2016 and later: Unicode, Inc. and others. */\n")
  27. g.write("/* License & terms of use: https://www.unicode.org/copyright.html */\n")
  28. g.write("#ifndef _ICU_DATA_H\n")
  29. g.write("#define _ICU_DATA_H\n")
  30. g.write('#include "unicode/utypes.h"\n')
  31. g.write('#include "unicode/udata.h"\n')
  32. g.write('#include "unicode/uversion.h"\n')
  33. with open(source[0].srcnode().abspath, "rb") as f:
  34. buf = f.read()
  35. g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n")
  36. g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n')
  37. for i in range(len(buf)):
  38. g.write("\t" + str(buf[i]) + ",\n")
  39. g.write("};\n")
  40. g.write("#endif")
  41. def write_macos_plist(target, binary_name, identifier, name):
  42. import os
  43. os.makedirs(f"{target}/Resource/", exist_ok=True)
  44. with open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n") as f:
  45. f.write(f"""\
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  48. <plist version="1.0">
  49. <dict>
  50. <key>CFBundleExecutable</key>
  51. <string>{binary_name}</string>
  52. <key>CFBundleIdentifier</key>
  53. <string>{identifier}</string>
  54. <key>CFBundleInfoDictionaryVersion</key>
  55. <string>6.0</string>
  56. <key>CFBundleName</key>
  57. <string>{name}</string>
  58. <key>CFBundlePackageType</key>
  59. <string>FMWK</string>
  60. <key>CFBundleShortVersionString</key>
  61. <string>1.0.0</string>
  62. <key>CFBundleSupportedPlatforms</key>
  63. <array>
  64. <string>MacOSX</string>
  65. </array>
  66. <key>CFBundleVersion</key>
  67. <string>1.0.0</string>
  68. <key>LSMinimumSystemVersion</key>
  69. <string>10.14</string>
  70. </dict>
  71. </plist>
  72. """)