methods.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import os
  2. import sys
  3. def no_verbose(sys, env):
  4. colors = {}
  5. # Colors are disabled in non-TTY environments such as pipes. This means
  6. # that if output is redirected to a file, it will not contain color codes
  7. if sys.stdout.isatty():
  8. colors["blue"] = "\033[0;94m"
  9. colors["bold_blue"] = "\033[1;94m"
  10. colors["reset"] = "\033[0m"
  11. else:
  12. colors["blue"] = ""
  13. colors["bold_blue"] = ""
  14. colors["reset"] = ""
  15. # There is a space before "..." to ensure that source file names can be
  16. # Ctrl + clicked in the VS Code terminal.
  17. compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format(
  18. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  19. )
  20. java_compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format(
  21. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  22. )
  23. compile_shared_source_message = "{}Compiling shared {}$SOURCE{} ...{}".format(
  24. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  25. )
  26. link_program_message = "{}Linking Program {}$TARGET{} ...{}".format(
  27. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  28. )
  29. link_library_message = "{}Linking Static Library {}$TARGET{} ...{}".format(
  30. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  31. )
  32. ranlib_library_message = "{}Ranlib Library {}$TARGET{} ...{}".format(
  33. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  34. )
  35. link_shared_library_message = "{}Linking Shared Library {}$TARGET{} ...{}".format(
  36. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  37. )
  38. java_library_message = "{}Creating Java Archive {}$TARGET{} ...{}".format(
  39. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  40. )
  41. env.Append(CXXCOMSTR=[compile_source_message])
  42. env.Append(CCCOMSTR=[compile_source_message])
  43. env.Append(SHCCCOMSTR=[compile_shared_source_message])
  44. env.Append(SHCXXCOMSTR=[compile_shared_source_message])
  45. env.Append(ARCOMSTR=[link_library_message])
  46. env.Append(RANLIBCOMSTR=[ranlib_library_message])
  47. env.Append(SHLINKCOMSTR=[link_shared_library_message])
  48. env.Append(LINKCOMSTR=[link_program_message])
  49. env.Append(JARCOMSTR=[java_library_message])
  50. env.Append(JAVACCOMSTR=[java_compile_source_message])
  51. def disable_warnings(self):
  52. # 'self' is the environment
  53. if self["platform"] == "windows" and not self["use_mingw"]:
  54. # We have to remove existing warning level defines before appending /w,
  55. # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
  56. warn_flags = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/WX"]
  57. self.Append(CCFLAGS=["/w"])
  58. self.Append(CFLAGS=["/w"])
  59. self.Append(CXXFLAGS=["/w"])
  60. self["CCFLAGS"] = [x for x in self["CCFLAGS"] if not x in warn_flags]
  61. self["CFLAGS"] = [x for x in self["CFLAGS"] if not x in warn_flags]
  62. self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if not x in warn_flags]
  63. else:
  64. self.Append(CCFLAGS=["-w"])
  65. self.Append(CFLAGS=["-w"])
  66. self.Append(CXXFLAGS=["-w"])
  67. def make_icu_data(target, source, env):
  68. dst = target[0].srcnode().abspath
  69. g = open(dst, "w", encoding="utf-8")
  70. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  71. g.write("/* (C) 2016 and later: Unicode, Inc. and others. */\n")
  72. g.write("/* License & terms of use: https://www.unicode.org/copyright.html */\n")
  73. g.write("#ifndef _ICU_DATA_H\n")
  74. g.write("#define _ICU_DATA_H\n")
  75. g.write('#include "unicode/utypes.h"\n')
  76. g.write('#include "unicode/udata.h"\n')
  77. g.write('#include "unicode/uversion.h"\n')
  78. f = open(source[0].srcnode().abspath, "rb")
  79. buf = f.read()
  80. g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n")
  81. g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n')
  82. for i in range(len(buf)):
  83. g.write("\t" + str(buf[i]) + ",\n")
  84. g.write("};\n")
  85. g.write("#endif")
  86. def write_macos_plist(target, binary_name, identifier, name):
  87. os.makedirs(f"{target}/Resource/", exist_ok=True)
  88. f = open(f"{target}/Resource/Info.plist", "w")
  89. f.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
  90. f.write(f'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
  91. f.write(f'<plist version="1.0">\n')
  92. f.write(f"<dict>\n")
  93. f.write(f"\t<key>CFBundleExecutable</key>\n")
  94. f.write(f"\t<string>{binary_name}</string>\n")
  95. f.write(f"\t<key>CFBundleIdentifier</key>\n")
  96. f.write(f"\t<string>{identifier}</string>\n")
  97. f.write(f"\t<key>CFBundleInfoDictionaryVersion</key>\n")
  98. f.write(f"\t<string>6.0</string>\n")
  99. f.write(f"\t<key>CFBundleName</key>\n")
  100. f.write(f"\t<string>{name}</string>\n")
  101. f.write(f"\t<key>CFBundlePackageType</key>\n")
  102. f.write(f"\t<string>FMWK</string>\n")
  103. f.write(f"\t<key>CFBundleShortVersionString</key>\n")
  104. f.write(f"\t<string>1.0.0</string>\n")
  105. f.write(f"\t<key>CFBundleSupportedPlatforms</key>\n")
  106. f.write(f"\t<array>\n")
  107. f.write(f"\t\t<string>MacOSX</string>\n")
  108. f.write(f"\t</array>\n")
  109. f.write(f"\t<key>CFBundleVersion</key>\n")
  110. f.write(f"\t<string>1.0.0</string>\n")
  111. f.write(f"\t<key>LSMinimumSystemVersion</key>\n")
  112. f.write(f"\t<string>10.14</string>\n")
  113. f.write(f"</dict>\n")
  114. f.write(f"</plist>\n")