Merge pull request #968 from Faless/build/4.x_custom_paths
[SCons] Fix custom API file/dir relative paths.pull/989/head
commit
129c358a72
41
SConstruct
41
SConstruct
|
@ -5,6 +5,7 @@ import platform
|
|||
import sys
|
||||
import subprocess
|
||||
from binding_generator import scons_generate_bindings, scons_emit_files
|
||||
from SCons.Errors import UserError
|
||||
|
||||
EnsureSConsVersion(4, 0)
|
||||
|
||||
|
@ -15,6 +16,28 @@ def add_sources(sources, dir, extension):
|
|||
sources.append(dir + "/" + f)
|
||||
|
||||
|
||||
def normalize_path(val):
|
||||
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
|
||||
|
||||
|
||||
def validate_api_file(key, val, env):
|
||||
if not os.path.isfile(normalize_path(val)):
|
||||
raise UserError("GDExtension API file ('%s') does not exist: %s" % (key, val))
|
||||
|
||||
|
||||
def validate_gdextension_dir(key, val, env):
|
||||
if not os.path.isdir(normalize_path(val)):
|
||||
raise UserError("GDExtension directory ('%s') does not exist: %s" % (key, val))
|
||||
|
||||
|
||||
def get_gdextension_dir(env):
|
||||
return normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath))
|
||||
|
||||
|
||||
def get_api_file(env):
|
||||
return normalize_path(env.get("custom_api_file", os.path.join(get_gdextension_dir(env), "extension_api.json")))
|
||||
|
||||
|
||||
# Try to detect the host platform automatically.
|
||||
# This is used if no `platform` argument is passed
|
||||
if sys.platform.startswith("linux"):
|
||||
|
@ -80,9 +103,9 @@ opts.Add(
|
|||
opts.Add(
|
||||
PathVariable(
|
||||
"gdextension_dir",
|
||||
"Path to the directory containing GDExtension interface header and API JSON file",
|
||||
"gdextension",
|
||||
PathVariable.PathIsDir,
|
||||
"Path to a custom directory containing GDExtension interface header and API JSON file",
|
||||
None,
|
||||
validate_gdextension_dir,
|
||||
)
|
||||
)
|
||||
opts.Add(
|
||||
|
@ -90,7 +113,7 @@ opts.Add(
|
|||
"custom_api_file",
|
||||
"Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
|
||||
None,
|
||||
PathVariable.PathIsFile,
|
||||
validate_api_file,
|
||||
)
|
||||
)
|
||||
opts.Add(
|
||||
|
@ -186,16 +209,10 @@ if env["float"] == "64":
|
|||
|
||||
# Generate bindings
|
||||
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})
|
||||
json_api_file = ""
|
||||
|
||||
if "custom_api_file" in env:
|
||||
json_api_file = env["custom_api_file"]
|
||||
else:
|
||||
json_api_file = os.path.join(os.getcwd(), env["gdextension_dir"], "extension_api.json")
|
||||
|
||||
bindings = env.GenerateBindings(
|
||||
env.Dir("."),
|
||||
[json_api_file, os.path.join(env["gdextension_dir"], "gdextension_interface.h"), "binding_generator.py"],
|
||||
[get_api_file(env), os.path.join(get_gdextension_dir(env), "gdextension_interface.h"), "binding_generator.py"],
|
||||
)
|
||||
|
||||
scons_cache_path = os.environ.get("SCONS_CACHE")
|
||||
|
@ -209,7 +226,7 @@ if env["generate_bindings"]:
|
|||
NoCache(bindings)
|
||||
|
||||
# Includes
|
||||
env.Append(CPPPATH=[[env.Dir(d) for d in [env["gdextension_dir"], "include", os.path.join("gen", "include")]]])
|
||||
env.Append(CPPPATH=[[env.Dir(d) for d in [get_gdextension_dir(env), "include", os.path.join("gen", "include")]]])
|
||||
|
||||
# Sources to compile
|
||||
sources = []
|
||||
|
|
Loading…
Reference in New Issue