methods.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. compiled_resource_message = "{}Creating Compiled Resource {}$TARGET{} ...{}".format(
  42. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  43. )
  44. generated_file_message = "{}Generating {}$TARGET{} ...{}".format(
  45. colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
  46. )
  47. env.Append(CXXCOMSTR=[compile_source_message])
  48. env.Append(CCCOMSTR=[compile_source_message])
  49. env.Append(SHCCCOMSTR=[compile_shared_source_message])
  50. env.Append(SHCXXCOMSTR=[compile_shared_source_message])
  51. env.Append(ARCOMSTR=[link_library_message])
  52. env.Append(RANLIBCOMSTR=[ranlib_library_message])
  53. env.Append(SHLINKCOMSTR=[link_shared_library_message])
  54. env.Append(LINKCOMSTR=[link_program_message])
  55. env.Append(JARCOMSTR=[java_library_message])
  56. env.Append(JAVACCOMSTR=[java_compile_source_message])
  57. env.Append(RCCOMSTR=[compiled_resource_message])
  58. env.Append(GENCOMSTR=[generated_file_message])
  59. def disable_warnings(self):
  60. # 'self' is the environment
  61. if self["platform"] == "windows" and not self["use_mingw"]:
  62. # We have to remove existing warning level defines before appending /w,
  63. # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
  64. warn_flags = ["/Wall", "/W4", "/W3", "/W2", "/W1", "/WX"]
  65. self.Append(CCFLAGS=["/w"])
  66. self.Append(CFLAGS=["/w"])
  67. self.Append(CXXFLAGS=["/w"])
  68. self["CCFLAGS"] = [x for x in self["CCFLAGS"] if not x in warn_flags]
  69. self["CFLAGS"] = [x for x in self["CFLAGS"] if not x in warn_flags]
  70. self["CXXFLAGS"] = [x for x in self["CXXFLAGS"] if not x in warn_flags]
  71. else:
  72. self.Append(CCFLAGS=["-w"])
  73. self.Append(CFLAGS=["-w"])
  74. self.Append(CXXFLAGS=["-w"])
  75. def make_icu_data(target, source, env):
  76. dst = target[0].srcnode().abspath
  77. with open(dst, "w", encoding="utf-8", newline="\n") as g:
  78. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  79. g.write("/* (C) 2016 and later: Unicode, Inc. and others. */\n")
  80. g.write("/* License & terms of use: https://www.unicode.org/copyright.html */\n")
  81. g.write("#ifndef _ICU_DATA_H\n")
  82. g.write("#define _ICU_DATA_H\n")
  83. g.write('#include "unicode/utypes.h"\n')
  84. g.write('#include "unicode/udata.h"\n')
  85. g.write('#include "unicode/uversion.h"\n')
  86. with open(source[0].srcnode().abspath, "rb") as f:
  87. buf = f.read()
  88. g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n")
  89. g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n')
  90. for i in range(len(buf)):
  91. g.write("\t" + str(buf[i]) + ",\n")
  92. g.write("};\n")
  93. g.write("#endif")
  94. def write_macos_plist(target, binary_name, identifier, name):
  95. os.makedirs(f"{target}/Resource/", exist_ok=True)
  96. with open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n") as f:
  97. f.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
  98. f.write(
  99. f'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
  100. )
  101. f.write(f'<plist version="1.0">\n')
  102. f.write(f"<dict>\n")
  103. f.write(f"\t<key>CFBundleExecutable</key>\n")
  104. f.write(f"\t<string>{binary_name}</string>\n")
  105. f.write(f"\t<key>CFBundleIdentifier</key>\n")
  106. f.write(f"\t<string>{identifier}</string>\n")
  107. f.write(f"\t<key>CFBundleInfoDictionaryVersion</key>\n")
  108. f.write(f"\t<string>6.0</string>\n")
  109. f.write(f"\t<key>CFBundleName</key>\n")
  110. f.write(f"\t<string>{name}</string>\n")
  111. f.write(f"\t<key>CFBundlePackageType</key>\n")
  112. f.write(f"\t<string>FMWK</string>\n")
  113. f.write(f"\t<key>CFBundleShortVersionString</key>\n")
  114. f.write(f"\t<string>1.0.0</string>\n")
  115. f.write(f"\t<key>CFBundleSupportedPlatforms</key>\n")
  116. f.write(f"\t<array>\n")
  117. f.write(f"\t\t<string>MacOSX</string>\n")
  118. f.write(f"\t</array>\n")
  119. f.write(f"\t<key>CFBundleVersion</key>\n")
  120. f.write(f"\t<string>1.0.0</string>\n")
  121. f.write(f"\t<key>LSMinimumSystemVersion</key>\n")
  122. f.write(f"\t<string>10.14</string>\n")
  123. f.write(f"</dict>\n")
  124. f.write(f"</plist>\n")