methods.py 5.4 KB

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