Skip to content

Commit 7c09b54

Browse files
authored
Merge pull request #981 from Faless/build/3.x_qol_backports
[3.x] [SCons] Backport SCons generator, cache.
2 parents 97c181a + 686db8e commit 7c09b54

File tree

6 files changed

+133
-54
lines changed

6 files changed

+133
-54
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Setup Godot build cache
2+
description: Setup Godot build cache.
3+
inputs:
4+
cache-name:
5+
description: The cache base name (job name by default).
6+
default: "${{github.job}}"
7+
scons-cache:
8+
description: The scons cache path.
9+
default: "${{github.workspace}}/.scons-cache/"
10+
runs:
11+
using: "composite"
12+
steps:
13+
# Upload cache on completion and check it out now
14+
- name: Load .scons_cache directory
15+
uses: actions/cache@v3
16+
with:
17+
path: ${{inputs.scons-cache}}
18+
key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
19+
restore-keys: |
20+
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
21+
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}
22+
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}

.github/workflows/ci.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: Continuous integration
22
on: [push, pull_request]
33

4+
env:
5+
# Only used for the cache key. Increment version to force clean build.
6+
GODOT_BASE_BRANCH: 3.x
7+
8+
concurrency:
9+
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}
10+
cancel-in-progress: true
11+
412
jobs:
513
build:
614
name: ${{ matrix.name }}
@@ -16,19 +24,22 @@ jobs:
1624
artifact-path: bin/libgodot-cpp.linux.release.64.a
1725
godot_zip: Godot_v3.5-stable_linux_server.64.zip
1826
executable: Godot_v3.5-stable_linux_server.64
27+
cache-name: linux-x86_64
1928

2029
- name: 🏁 Windows (x86_64, MSVC)
2130
os: windows-2019
2231
platform: windows
2332
artifact-name: godot-cpp-windows-msvc2019-x86_64-release
2433
artifact-path: bin/libgodot-cpp.windows.release.64.lib
34+
cache-name: windows-x86_64-msvc
2535

2636
- name: 🏁 Windows (x86_64, MinGW)
2737
os: windows-2019
2838
platform: windows
2939
artifact-name: godot-cpp-linux-mingw-x86_64-release
3040
artifact-path: bin/libgodot-cpp.windows.release.64.a
3141
flags: use_mingw=yes
42+
cache-name: windows-x86_64-mingw
3243

3344
- name: 🍎 macOS (universal)
3445
os: macos-11
@@ -38,26 +49,38 @@ jobs:
3849
flags: macos_arch=universal
3950
godot_zip: Godot_v3.5-stable_osx.universal.zip
4051
executable: Godot.app/Contents/MacOS/Godot
52+
cache-name: macos-unversal
4153

4254
- name: 🤖 Android (arm64)
4355
os: ubuntu-18.04
4456
platform: android
4557
artifact-name: godot-cpp-android-arm64-release
4658
artifact-path: bin/libgodot-cpp.android.release.arm64v8.a
4759
flags: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME android_arch=arm64v8
60+
cache-name: android-arm64
4861

4962
- name: 🍏 iOS (arm64)
5063
os: macos-11
5164
platform: ios
5265
artifact-name: godot-cpp-ios-arm64-release
5366
artifact-path: bin/libgodot-cpp.ios.release.arm64.a
67+
cache-name: ios-arm64
68+
69+
env:
70+
SCONS_CACHE: ${{ github.workspace }}/.scons-cache/
5471

5572
steps:
5673
- name: Checkout
5774
uses: actions/checkout@v2
5875
with:
5976
submodules: recursive
6077

78+
- name: Setup Godot build cache
79+
uses: ./.github/actions/godot-cache
80+
with:
81+
cache-name: ${{ matrix.cache-name }}
82+
continue-on-error: true
83+
6184
- name: Set up Python (for SCons)
6285
uses: actions/setup-python@v4
6386
with:
@@ -79,7 +102,7 @@ jobs:
79102

80103
- name: Build godot-cpp (debug)
81104
run: |
82-
scons platform=${{ matrix.platform }} target=debug generate_bindings=yes ${{ matrix.flags }}
105+
scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }}
83106
84107
- name: Build test without rebuilding godot-cpp (debug)
85108
run: |
@@ -111,6 +134,8 @@ jobs:
111134
steps:
112135
- name: Checkout
113136
uses: actions/checkout@v2
137+
with:
138+
submodules: recursive
114139

115140
- name: Make apt sources.list use the default Ubuntu repositories
116141
run: |
@@ -127,3 +152,7 @@ jobs:
127152
- name: Style checks via clang-format
128153
run: |
129154
bash ./misc/scripts/clang_format.sh
155+
156+
- name: Bindings generation checks (ensures get_file_list returns all generated files)
157+
run: |
158+
python ./misc/scripts/check_get_file_list.py

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ gen/*
33
logs/*
44
*.log
55

6+
# The default cache directory
7+
.scons_cache/
8+
69
# Binaries
710
*.o
811
*.os

SConstruct

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
import subprocess
6+
from binding_generator import scons_generate_bindings, scons_emit_files
67

78
if sys.version_info < (3,):
89

@@ -133,15 +134,7 @@ opts.Add(
133134
)
134135
)
135136
opts.Add(PathVariable("custom_api_file", "Path to a custom JSON API file", None, PathVariable.PathIsFile))
136-
opts.Add(
137-
EnumVariable(
138-
"generate_bindings",
139-
"Generate GDNative API bindings",
140-
"auto",
141-
allowed_values=["yes", "no", "auto", "true"],
142-
ignorecase=2,
143-
)
144-
)
137+
opts.Add(BoolVariable("generate_bindings", "Force GDNative API bindings generation.", False))
145138
opts.Add(
146139
EnumVariable(
147140
"android_arch",
@@ -472,40 +465,37 @@ elif env["platform"] == "javascript":
472465
elif env["target"] == "release":
473466
env.Append(CCFLAGS=["-O3"])
474467

475-
env.Append(
476-
CPPPATH=[
477-
".",
478-
env["headers_dir"],
479-
"include",
480-
"include/gen",
481-
"include/core",
482-
]
483-
)
468+
# Cache
469+
scons_cache_path = os.environ.get("SCONS_CACHE")
470+
if scons_cache_path is not None:
471+
CacheDir(scons_cache_path)
472+
Decider("MD5")
484473

485-
# Generate bindings?
474+
# Generate bindings
475+
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})
486476
json_api_file = ""
487477

488478
if "custom_api_file" in env:
489479
json_api_file = env["custom_api_file"]
490480
else:
491481
json_api_file = os.path.join(os.getcwd(), env["headers_dir"], "api.json")
492482

493-
if env["generate_bindings"] == "auto":
494-
# Check if generated files exist
495-
should_generate_bindings = not os.path.isfile(os.path.join(os.getcwd(), "src", "gen", "Object.cpp"))
496-
else:
497-
should_generate_bindings = env["generate_bindings"] in ["yes", "true"]
483+
bindings = env.GenerateBindings(
484+
env.Dir("."), [json_api_file, "binding_generator.py"]
485+
)
498486

499-
if should_generate_bindings:
500-
# Actually create the bindings here
501-
import binding_generator
487+
# Forces bindings regeneration.
488+
if env["generate_bindings"]:
489+
AlwaysBuild(bindings)
490+
NoCache(bindings)
502491

503-
binding_generator.generate_bindings(json_api_file, env["generate_template_get_node"])
492+
# Includes
493+
env.Append(CPPPATH=[[env.Dir(d) for d in [".", env["headers_dir"], "include", "include/gen", "include/core"]]])
504494

505495
# Sources to compile
506496
sources = []
507497
add_sources(sources, "src/core", "cpp")
508-
add_sources(sources, "src/gen", "cpp")
498+
sources.extend(f for f in bindings if str(f).endswith(".cpp"))
509499

510500
arch_suffix = env["bits"]
511501
if env["platform"] == "android":
@@ -530,7 +520,6 @@ if env["build_library"]:
530520
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
531521
Default(library)
532522

533-
env.Append(CPPPATH=[env.Dir(f) for f in [env["headers_dir"], "include", "include/gen", "include/core"]])
534523
env.Append(LIBPATH=[env.Dir("bin")])
535524
env.Append(LIBS=library_name)
536525
Return("env")

binding_generator.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def correct_method_name(method_list):
1515
classes = []
1616

1717

18-
def print_file_list(api_filepath, output_dir, headers=False, sources=False):
18+
def get_file_list(api_filepath, output_dir, headers=False, sources=False):
1919
global classes
20-
end = ";"
20+
files = []
2121
with open(api_filepath) as api_file:
2222
classes = json.load(api_file)
2323
include_gen_folder = Path(output_dir) / "include" / "gen"
@@ -26,17 +26,35 @@ def print_file_list(api_filepath, output_dir, headers=False, sources=False):
2626
header_filename = include_gen_folder / (strip_name(_class["name"]) + ".hpp")
2727
source_filename = source_gen_folder / (strip_name(_class["name"]) + ".cpp")
2828
if headers:
29-
print(str(header_filename.as_posix()), end=end)
29+
files.append(str(header_filename.as_posix()))
3030
if sources:
31-
print(str(source_filename.as_posix()), end=end)
31+
files.append(str(source_filename.as_posix()))
3232
icall_header_filename = include_gen_folder / "__icalls.hpp"
3333
register_types_filename = source_gen_folder / "__register_types.cpp"
3434
init_method_bindings_filename = source_gen_folder / "__init_method_bindings.cpp"
3535
if headers:
36-
print(str(icall_header_filename.as_posix()), end=end)
36+
files.append(str(icall_header_filename.as_posix()))
3737
if sources:
38-
print(str(register_types_filename.as_posix()), end=end)
39-
print(str(init_method_bindings_filename.as_posix()), end=end)
38+
files.append(str(register_types_filename.as_posix()))
39+
files.append(str(init_method_bindings_filename.as_posix()))
40+
return files
41+
42+
43+
def print_file_list(api_filepath, output_dir, headers=False, sources=False):
44+
for f in get_file_list(api_filepath, output_dir, headers, sources):
45+
print(f, end=";")
46+
47+
48+
def scons_emit_files(target, source, env):
49+
files = [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)]
50+
env.Clean(target, files)
51+
env["godot_cpp_gen_dir"] = target[0].abspath
52+
return files, source
53+
54+
55+
def scons_generate_bindings(target, source, env):
56+
generate_bindings(str(source[0]), env["generate_template_get_node"], env["godot_cpp_gen_dir"])
57+
return None
4058

4159

4260
def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
@@ -48,25 +66,12 @@ def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
4866
include_gen_folder = Path(output_dir) / "include" / "gen"
4967
source_gen_folder = Path(output_dir) / "src" / "gen"
5068

51-
try:
52-
include_gen_folder.mkdir(parents=True)
53-
except os.error as e:
54-
if e.errno == errno.EEXIST:
55-
print(str(source_gen_folder) + ": " + os.strerror(e.errno))
56-
else:
57-
exit(1)
58-
59-
try:
60-
source_gen_folder.mkdir(parents=True)
61-
except os.error as e:
62-
if e.errno == errno.EEXIST:
63-
print(str(source_gen_folder) + ": " + os.strerror(e.errno))
64-
else:
65-
exit(1)
69+
include_gen_folder.mkdir(parents=True, exist_ok=True)
70+
source_gen_folder.mkdir(parents=True, exist_ok=True)
6671

6772
for c in classes:
6873
# print(c['name'])
69-
used_classes = get_used_classes(c)
74+
used_classes = sorted(get_used_classes(c))
7075
if use_template_get_node and c["name"] == "Node":
7176
correct_method_name(c["methods"])
7277

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
3+
import os, sys
4+
5+
from pathlib import Path
6+
7+
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", ".."))
8+
9+
from binding_generator import get_file_list, generate_bindings
10+
11+
api_filepath = "godot-headers/api.json"
12+
bits = "64"
13+
double = "float"
14+
output_dir = "self_test"
15+
16+
generate_bindings(api_filepath, use_template_get_node=False, output_dir=output_dir)
17+
flist = get_file_list(api_filepath, output_dir, headers=True, sources=True)
18+
19+
p = Path(output_dir)
20+
allfiles = [str(f.as_posix()) for f in p.glob("**/*.*")]
21+
missing = list(filter((lambda f: f not in flist), allfiles))
22+
extras = list(filter((lambda f: f not in allfiles), flist))
23+
if len(missing) > 0 or len(extras) > 0:
24+
print("Error!")
25+
for f in missing:
26+
print("MISSING: " + str(f))
27+
for f in extras:
28+
print("EXTRA: " + str(f))
29+
sys.exit(1)
30+
else:
31+
print("OK!")

0 commit comments

Comments
 (0)