Skip to content

Added warning message if using bad command line options, fixed mono options #53030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import sys
import time
from collections import OrderedDict

import SCons

# Local
import methods
import glsl_builders
Expand Down Expand Up @@ -57,7 +59,7 @@ methods.save_active_platforms(active_platforms, active_platform_ids)

custom_tools = ["default"]

platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))
platform_arg = ARGUMENTS.get("selected_platform", ARGUMENTS.get("p", False))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems wrong to me, doesn't it change our platform command line option to selected_platform? That would break compatibility and force us to update all documentation, as well as force users to update all their build scripts, I wouldn't do it unless it's strictly needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this was a mass find + replace mistake. The build interface should remain the same, I'll fix it.


if os.name == "nt" and (platform_arg == "android" or methods.get_cmdline_bool("use_mingw", False)):
custom_tools = ["mingw"]
Expand Down Expand Up @@ -111,6 +113,7 @@ if profile:
customs.append(profile + ".py")

opts = Variables(customs, ARGUMENTS)
env_base["opts"] = opts

# Target build options
opts.Add("p", "Platform (alias for 'platform')", "")
Expand Down Expand Up @@ -233,7 +236,7 @@ if selected_platform in ["linux", "bsd", "x11"]:

# Make sure to update this to the found, valid platform as it's used through the buildsystem as the reference.
# It should always be re-set after calling `opts.Update()` otherwise it uses the original input value.
env_base["platform"] = selected_platform
env_base["selected_platform"] = selected_platform

# Add platform-specific options.
if selected_platform in platform_opts:
Expand All @@ -242,7 +245,6 @@ if selected_platform in platform_opts:

# Update the environment to take platform-specific options into account.
opts.Update(env_base)
env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().

# Detect modules.
modules_detected = OrderedDict()
Expand Down Expand Up @@ -296,8 +298,6 @@ methods.write_modules(modules_detected)

# Update the environment again after all the module options are added.
opts.Update(env_base)
env_base["platform"] = selected_platform # Must always be re-set after calling opts.Update().
Help(opts.GenerateHelpText(env_base))
Comment on lines -299 to -300
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a pain that SCons puts user-provided arguments and dev-defined environment configuration in the same data structure. Ideally we should be able to use the most natural term "platform" both for the argument that users are passing, and for the internal variable we want to check to see what platform we're building for.

It's a bit annoying that this forces us either to do hacks like I used to have, or use a wordy "selected_platform" everywhere (which breaks compatibility for user scripts and custom modules, so I'm not too fond of the prospect).

Copy link
Contributor Author

@dmoody256 dmoody256 Oct 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well scons is not forcing you, you are telling the Variables obj to update them in that environment. I suppose Update could have an optional interface of a list of Variables to ignore in a given update. It essentially what you doing with the set after update.

The alternative method here is that you make multiple Variables instances and then each update to the environment is a separate one. You will need to join them together to generate the complete help text. Want me to rewrite this with that implementation?


# add default include paths

Expand Down Expand Up @@ -478,7 +478,7 @@ if selected_platform in platform_list:
)
# Apple LLVM versions differ from upstream LLVM version \o/, compare
# in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
elif env["platform"] == "osx" or env["platform"] == "iphone":
elif env["selected_platform"] == "osx" or env["selected_platform"] == "iphone":
vanilla = methods.is_vanilla_clang(env)
if vanilla and cc_version_major < 6:
print(
Expand Down Expand Up @@ -718,6 +718,15 @@ if selected_platform in platform_list:
env.vs_incs = []
env.vs_srcs = []

if opts.UnknownVariables():

methods.print_color(sys, "red", "ERROR: Unknown command line variables:")
for name, val in opts.UnknownVariables().items():
methods.print_color(sys, "red", " '{}={}'".format(name, val))
methods.print_color(sys, "red", "Please check valid variables usage with '--help' option.")

Help(opts.GenerateHelpText(env))

Export("env")

# Build subdirs, the build order is dependent on link order.
Expand Down Expand Up @@ -748,6 +757,7 @@ if selected_platform in platform_list:
if conf.CheckCHeader(header[0]):
env.AppendUnique(CPPDEFINES=[header[1]])


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does black not fix whitespace? I have been lazy about my whitespace expecting black to format it.

elif selected_platform != "":
if selected_platform == "list":
print("The following platforms are available:\n")
Expand Down
2 changes: 1 addition & 1 deletion drivers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SConscript("windows/SCsub")
SConscript("alsa/SCsub")
SConscript("coreaudio/SCsub")
SConscript("pulseaudio/SCsub")
if env["platform"] == "windows":
if env["selected_platform"] == "windows":
SConscript("wasapi/SCsub")
if env["xaudio2"]:
SConscript("xaudio2/SCsub")
Expand Down
12 changes: 6 additions & 6 deletions drivers/vulkan/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ if env["use_volk"]:
env.AppendUnique(CPPDEFINES=["USE_VOLK"])
env.Prepend(CPPPATH=[thirdparty_volk_dir])

if env["platform"] == "android":
if env["selected_platform"] == "android":
env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_ANDROID_KHR"])
elif env["platform"] == "iphone":
elif env["selected_platform"] == "iphone":
env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_IOS_MVK"])
elif env["platform"] == "linuxbsd":
elif env["selected_platform"] == "linuxbsd":
env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_XLIB_KHR"])
elif env["platform"] == "osx":
elif env["selected_platform"] == "osx":
env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_MACOS_MVK"])
elif env["platform"] == "windows":
elif env["selected_platform"] == "windows":
env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_WIN32_KHR"])

# Build Vulkan memory allocator and volk
Expand All @@ -36,7 +36,7 @@ if env["use_volk"]:

thirdparty_sources_volk = [thirdparty_volk_dir + "/volk.c"]
env_thirdparty_volk.add_source_files(thirdparty_obj, thirdparty_sources_volk)
elif env["platform"] == "android":
elif env["selected_platform"] == "android":
# Our current NDK version only provides old Vulkan headers,
# so we have to limit VMA.
env_thirdparty_vma.AppendUnique(CPPDEFINES=["VMA_VULKAN_VERSION=1000000"])
Expand Down
15 changes: 14 additions & 1 deletion methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def save_active_platforms(apnames, ap):
pngw.write(str)


def no_verbose(sys, env):
def get_terminal_colors(sys):

colors = {}

Expand All @@ -452,6 +452,19 @@ def no_verbose(sys, env):
colors["red"] = ""
colors["end"] = ""

return colors


def print_color(sys, color, message):

colors = get_terminal_colors(sys)
print("{}{}{}".format(colors[color], message, colors["end"]))


def no_verbose(sys, env):

colors = get_terminal_colors(sys)

compile_source_message = "{}Compiling {}==> {}$SOURCE{}".format(
colors["blue"], colors["purple"], colors["yellow"], colors["end"]
)
Expand Down
4 changes: 2 additions & 2 deletions modules/camera/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Import("env_modules")

env_camera = env_modules.Clone()

if env["platform"] == "windows":
if env["selected_platform"] == "windows":
env_camera.add_source_files(env.modules_sources, "register_types.cpp")
env_camera.add_source_files(env.modules_sources, "camera_win.cpp")

elif env["platform"] == "osx":
elif env["selected_platform"] == "osx":
env_camera.add_source_files(env.modules_sources, "register_types.cpp")
env_camera.add_source_files(env.modules_sources, "camera_osx.mm")
4 changes: 2 additions & 2 deletions modules/freetype/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if env["builtin_freetype"]:
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

if env["platform"] == "uwp":
if env["selected_platform"] == "uwp":
# Include header for UWP to fix build issues
env_freetype.Append(CCFLAGS=["/FI", '"modules/freetype/uwpdef.h"'])
# Globally too, as freetype is used in scene (see bottom)
Expand All @@ -76,7 +76,7 @@ if env["builtin_freetype"]:

sfnt = thirdparty_dir + "src/sfnt/sfnt.c"
# Must be done after all CPPDEFINES are being set so we can copy them.
if env["platform"] == "javascript":
if env["selected_platform"] == "javascript":
# Forcibly undefine this macro so SIMD is not used in this file,
# since currently unsupported in WASM
tmp_env = env_freetype.Clone()
Expand Down
2 changes: 1 addition & 1 deletion modules/gdnative/nativescript/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Import("env_gdnative")

env_gdnative.add_source_files(env.modules_sources, "*.cpp")

if "platform" in env and env["platform"] in ["linuxbsd", "iphone"]:
if "selected_platform" in env and env["selected_platform"] in ["linuxbsd", "iphone"]:
env.Append(LINKFLAGS=["-rdynamic"])
2 changes: 1 addition & 1 deletion modules/glslang/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if env["builtin_glslang"]:
"StandAlone/ResourceLimits.cpp",
]

if env["platform"] == "windows":
if env["selected_platform"] == "windows":
thirdparty_sources.append("glslang/OSDependent/Windows/ossource.cpp")
else:
thirdparty_sources.append("glslang/OSDependent/Unix/ossource.cpp")
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ env_mono.add_source_files(env.modules_sources, "utils/*.cpp")

env_mono.add_source_files(env.modules_sources, "mono_gd/support/*.cpp")

if env["platform"] in ["osx", "iphone"]:
if env["selected_platform"] in ["osx", "iphone"]:
env_mono.add_source_files(env.modules_sources, "mono_gd/support/*.mm")
env_mono.add_source_files(env.modules_sources, "mono_gd/support/*.m")

Expand Down
2 changes: 1 addition & 1 deletion modules/mono/build_scripts/godot_net_sdk_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_godot_net_sdk(source, target, env):

from .solution_builder import build_solution

extra_msbuild_args = ["/p:GodotPlatform=" + env["platform"]]
extra_msbuild_args = ["/p:GodotPlatform=" + env["selected_platform"]]

build_solution(env, solution_path, build_config, extra_msbuild_args)
# No need to copy targets. The Godot.NET.Sdk csproj takes care of copying them.
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/build_scripts/godot_tools_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_godot_tools(source, target, env):

from .solution_builder import build_solution

extra_msbuild_args = ["/p:GodotPlatform=" + env["platform"]]
extra_msbuild_args = ["/p:GodotPlatform=" + env["selected_platform"]]

build_solution(env, solution_path, build_config, extra_msbuild_args)
# No need to copy targets. The GodotTools csproj takes care of copying them.
Expand Down
22 changes: 11 additions & 11 deletions modules/mono/build_scripts/mono_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def find_wasm_src_dir(mono_root):

def configure(env, env_mono):
bits = env["bits"]
is_android = env["platform"] == "android"
is_javascript = env["platform"] == "javascript"
is_ios = env["platform"] == "iphone"
is_android = env["selected_platform"] == "android"
is_javascript = env["selected_platform"] == "javascript"
is_ios = env["selected_platform"] == "iphone"
is_ios_sim = is_ios and env["arch"] in ["x86", "x86_64"]

tools_enabled = env["tools"]
Expand All @@ -104,7 +104,7 @@ def configure(env, env_mono):
if is_android and not env["android_arch"] in android_arch_dirs:
raise RuntimeError("This module does not support the specified 'android_arch': " + env["android_arch"])

if tools_enabled and not module_supports_tools_on(env["platform"]):
if tools_enabled and not module_supports_tools_on(env["selected_platform"]):
# TODO:
# Android: We have to add the data directory to the apk, concretely the Api and Tools folders.
raise RuntimeError("This module does not currently support building for this platform with tools enabled")
Expand Down Expand Up @@ -137,7 +137,7 @@ def configure(env, env_mono):
if (env["tools"] or env["target"] != "release") and not mono_single_appdomain:
env_mono.Append(CPPDEFINES=["GD_MONO_HOT_RELOAD"])

if env["platform"] == "windows":
if env["selected_platform"] == "windows":
mono_root = mono_prefix

if not mono_root and os.name == "nt":
Expand Down Expand Up @@ -206,7 +206,7 @@ def configure(env, env_mono):

copy_file(mono_bin_path, "#bin", mono_dll_file)
else:
is_apple = env["platform"] in ["osx", "iphone"]
is_apple = env["selected_platform"] in ["osx", "iphone"]
is_macos = is_apple and not is_ios

sharedlib_ext = ".dylib" if is_apple else ".so"
Expand Down Expand Up @@ -284,7 +284,7 @@ def copy_mono_lib(libname_wo_ext):
copy_mono_lib("libmono-icall-table")
copy_mono_lib("libmono-ilgen")
else:
assert is_desktop(env["platform"]) or is_android or is_javascript
assert is_desktop(env["selected_platform"]) or is_android or is_javascript
env.Append(LINKFLAGS=["-Wl,-whole-archive", mono_lib_file, "-Wl,-no-whole-archive"])

if is_javascript:
Expand Down Expand Up @@ -365,7 +365,7 @@ def copy_mono_lib(libname_wo_ext):
copy_file(mono_lib_path, libs_output_dir, mono_so_file)

if not tools_enabled:
if is_desktop(env["platform"]):
if is_desktop(env["selected_platform"]):
if not mono_root:
mono_root = (
subprocess.check_output(["pkg-config", "mono-2", "--variable=prefix"]).decode("utf8").strip()
Expand Down Expand Up @@ -399,7 +399,7 @@ def copy_mono_lib(libname_wo_ext):
def make_template_dir(env, mono_root):
from shutil import rmtree

platform = env["platform"]
platform = env["selected_platform"]
target = env["target"]

template_dir_name = ""
Expand Down Expand Up @@ -443,7 +443,7 @@ def copy_mono_root_files(env, mono_root, mono_bcl):
# Copy etc/mono/

editor_mono_config_dir = os.path.join(editor_mono_root_dir, "etc", "mono")
copy_mono_etc_dir(mono_root, editor_mono_config_dir, env["platform"])
copy_mono_etc_dir(mono_root, editor_mono_config_dir, env["selected_platform"])

# Copy the required shared libraries

Expand Down Expand Up @@ -509,7 +509,7 @@ def copy_if_exists(src, dst):
if os.path.isfile(src):
copy(src, dst)

platform = env["platform"]
platform = env["selected_platform"]

if platform == "windows":
src_mono_bin_dir = os.path.join(mono_root, "bin")
Expand Down
6 changes: 2 additions & 4 deletions modules/mono/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def can_build(env, platform):


def configure(env):
platform = env["platform"]
platform = env["selected_platform"]

if platform not in supported_platforms:
raise RuntimeError("This module does not currently support building for this platform")
Expand All @@ -18,7 +18,7 @@ def configure(env):
default_mono_static = platform in ["iphone", "javascript"]
default_mono_bundles_zlib = platform in ["javascript"]

envvars = Variables()
envvars = env["opts"]
envvars.Add(
PathVariable(
"mono_prefix",
Expand Down Expand Up @@ -48,9 +48,7 @@ def configure(env):
"mono_bundles_zlib", "Specify if the Mono runtime was built with bundled zlib", default_mono_bundles_zlib
)
)

envvars.Update(env)
Help(envvars.GenerateHelpText(env))

if env["mono_bundles_zlib"]:
# Mono may come with zlib bundled for WASM or on newer version when built with MinGW.
Expand Down
8 changes: 4 additions & 4 deletions modules/opus/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ if env["builtin_opus"]:

opus_sources_silk = []

if env["platform"] in ["android", "iphone", "javascript"]:
if env["selected_platform"] in ["android", "iphone", "javascript"]:
env_opus.Append(CPPDEFINES=["FIXED_POINT"])
opus_sources_silk = [
"silk/fixed/LTP_analysis_filter_FIX.c",
Expand Down Expand Up @@ -221,17 +221,17 @@ if env["builtin_opus"]:
]
env_opus.Prepend(CPPPATH=[thirdparty_dir + "/" + dir for dir in thirdparty_include_paths])

if env["platform"] == "android":
if env["selected_platform"] == "android":
if "android_arch" in env and env["android_arch"] == "armv7":
env_opus.Append(CPPDEFINES=["OPUS_ARM_OPT"])
elif "android_arch" in env and env["android_arch"] == "arm64v8":
env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"])
elif env["platform"] == "iphone":
elif env["selected_platform"] == "iphone":
if "arch" in env and env["arch"] == "arm":
env_opus.Append(CPPDEFINES=["OPUS_ARM_OPT"])
elif "arch" in env and env["arch"] == "arm64":
env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"])
elif env["platform"] == "osx":
elif env["selected_platform"] == "osx":
if "arch" in env and env["arch"] == "arm64":
env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"])

Expand Down
4 changes: 2 additions & 2 deletions modules/raycast/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ if env["builtin_embree"]:
if env["arch"] in ["x86", "x86_64"]:
env_raycast.Append(CPPFLAGS=["-msse2", "-mxsave"])

if env["platform"] == "windows":
if env["selected_platform"] == "windows":
env_raycast.Append(CPPFLAGS=["-mstackrealign"])

if env["platform"] == "windows":
if env["selected_platform"] == "windows":
if env.msvc:
env.Append(LINKFLAGS=["psapi.lib"])
else:
Expand Down
4 changes: 2 additions & 2 deletions modules/text_server_adv/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ if env["builtin_harfbuzz"]:
]
)

if env["platform"] == "android" or env["platform"] == "linuxbsd":
if env["selected_platform"] == "android" or env["selected_platform"] == "linuxbsd":
env_harfbuzz.Append(CCFLAGS=["-DHAVE_PTHREAD"])

if env["platform"] == "javascript":
if env["selected_platform"] == "javascript":
if env["threads_enabled"]:
env_harfbuzz.Append(CCFLAGS=["-DHAVE_PTHREAD"])
else:
Expand Down
Loading