소스 검색

SCons: Validate dependencies for linked multimedia modules

This is still a bit hacky and eventually we should rework the way we handle
optional dependencies (especially with regard to builtin/system libs), but
it's a simple first step.

Fixes #39219.
Rémi Verschelde 5 년 전
부모
커밋
7c74312217
6개의 변경된 파일38개의 추가작업 그리고 12개의 파일을 삭제
  1. 7 8
      SConstruct
  2. 24 0
      methods.py
  3. 1 1
      modules/opus/config.py
  4. 1 1
      modules/theora/config.py
  5. 1 1
      modules/vorbis/config.py
  6. 4 1
      modules/webm/config.py

+ 7 - 8
SConstruct

@@ -86,6 +86,7 @@ env_base.__class__.add_library = methods.add_library
 env_base.__class__.add_program = methods.add_program
 env_base.__class__.add_program = methods.add_program
 env_base.__class__.CommandNoCache = methods.CommandNoCache
 env_base.__class__.CommandNoCache = methods.CommandNoCache
 env_base.__class__.disable_warnings = methods.disable_warnings
 env_base.__class__.disable_warnings = methods.disable_warnings
+env_base.__class__.module_check_dependencies = methods.module_check_dependencies
 
 
 env_base["x86_libtheora_opt_gcc"] = False
 env_base["x86_libtheora_opt_gcc"] = False
 env_base["x86_libtheora_opt_vc"] = False
 env_base["x86_libtheora_opt_vc"] = False
@@ -607,14 +608,12 @@ if selected_platform in platform_list:
         env.Append(CPPDEFINES=["MINIZIP_ENABLED"])
         env.Append(CPPDEFINES=["MINIZIP_ENABLED"])
 
 
     editor_module_list = ["regex"]
     editor_module_list = ["regex"]
-    for x in editor_module_list:
-        if not env["module_" + x + "_enabled"]:
-            if env["tools"]:
-                print(
-                    "Build option 'module_" + x + "_enabled=no' cannot be used with 'tools=yes' (editor), "
-                    "only with 'tools=no' (export template)."
-                )
-                Exit(255)
+    if env["tools"] and not env.module_check_dependencies("tools", editor_module_list):
+        print(
+            "Build option 'module_" + x + "_enabled=no' cannot be used with 'tools=yes' (editor), "
+            "only with 'tools=no' (export template)."
+        )
+        Exit(255)
 
 
     if not env["verbose"]:
     if not env["verbose"]:
         methods.no_verbose(sys, env)
         methods.no_verbose(sys, env)

+ 24 - 0
methods.py

@@ -231,6 +231,30 @@ def disable_module(self):
     self.disabled_modules.append(self.current_module)
     self.disabled_modules.append(self.current_module)
 
 
 
 
+def module_check_dependencies(self, module, dependencies):
+    """
+    Checks if module dependencies are enabled for a given module,
+    and prints a warning if they aren't.
+    Meant to be used in module `can_build` methods.
+    Returns a boolean (True if dependencies are satisfied).
+    """
+    missing_deps = []
+    for dep in dependencies:
+        opt = "module_{}_enabled".format(dep)
+        if not opt in self or not self[opt]:
+            missing_deps.append(dep)
+
+    if missing_deps != []:
+        print(
+            "Disabling '{}' module as the following dependencies are not satisfied: {}".format(
+                module, ", ".join(missing_deps)
+            )
+        )
+        return False
+    else:
+        return True
+
+
 def use_windows_spawn_fix(self, platform=None):
 def use_windows_spawn_fix(self, platform=None):
 
 
     if os.name != "nt":
     if os.name != "nt":

+ 1 - 1
modules/opus/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
 def can_build(env, platform):
-    return True
+    return env.module_check_dependencies("opus", ["ogg"])
 
 
 
 
 def configure(env):
 def configure(env):

+ 1 - 1
modules/theora/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
 def can_build(env, platform):
-    return True
+    return env.module_check_dependencies("theora", ["ogg", "vorbis"])
 
 
 
 
 def configure(env):
 def configure(env):

+ 1 - 1
modules/vorbis/config.py

@@ -1,5 +1,5 @@
 def can_build(env, platform):
 def can_build(env, platform):
-    return True
+    return env.module_check_dependencies("vorbis", ["ogg"])
 
 
 
 
 def configure(env):
 def configure(env):

+ 4 - 1
modules/webm/config.py

@@ -1,5 +1,8 @@
 def can_build(env, platform):
 def can_build(env, platform):
-    return platform not in ["iphone"]
+    if platform in ["iphone"]:
+        return False
+
+    return env.module_check_dependencies("webm", ["ogg", "opus", "vorbis"])
 
 
 
 
 def configure(env):
 def configure(env):