forked from lpenz/ghaction-cmake
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathentrypoint.py
107 lines (81 loc) · 3.22 KB
/
entrypoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3 -u
import subprocess
import json
import os, sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
if os.environ["INPUT_VERBOSE"] == "true":
verbose = True
eprint("Environment: ", json.dumps(os.environ.copy(), indent=4, sort_keys=True))
else:
verbose = False
def check_call(*args, **kwargs):
if verbose:
eprint("Calling subprocess: ", args)
subprocess.check_call(*args, **kwargs)
extra_dependencies = os.environ.get("INPUT_DEPENDENCIES", "").split()
if len(extra_dependencies) > 0:
args = ["apt-get", "install", "--no-install-recommends", "-y"]
args.extend(extra_dependencies)
check_call(args)
callenv = os.environ.copy()
callenv["CFLAGS"] = callenv.get("CFLAGS", "")
callenv["CXXFLAGS"] = callenv.get("CXXFLAGS", "")
ctest_coverage = os.environ["INPUT_CTEST_COVERAGE"] == "true"
if ctest_coverage:
callenv["CFLAGS"] += " --coverage"
callenv["CXXFLAGS"] += " --coverage"
source_directory = os.environ["INPUT_SOURCE_DIRECTORY"]
build_directory = os.environ["INPUT_BUILD_DIRECTORY"]
if verbose:
eprint(
"Creating directories: src:",
source_directory,
", build: ",
build_directory,
", in cwd=",
os.getcwd(),
)
os.makedirs(os.path.join(os.getcwd(), source_directory), exist_ok=True)
os.makedirs(os.path.join(os.getcwd(), build_directory), exist_ok=True)
cmake_configure_commands = ["cmake", "-S", source_directory, "-B", build_directory]
cmake_configure_commands.append("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON")
cmake_configure_sanitize = os.environ["INPUT_CMAKE_CONFIGURE_SANITIZE"]
if len(cmake_configure_sanitize) > 1:
callenv["CFLAGS"] += " -fsanitize=" + cmake_configure_sanitize
callenv["CXXFLAGS"] += " -fsanitize=" + cmake_configure_sanitize
cmake_configure_environment = os.environ["INPUT_CMAKE_CONFIGURE_ENVIRONMENT"]
if verbose:
eprint("INPUT_CMAKE_CONFIGURE_ENVIRONMENT=", cmake_configure_environment)
for cenv in cmake_configure_environment.split():
if verbose:
eprint("Adding entry to call environment:", cenv)
var, val = cenv.split("=", 1)
if verbose:
eprint("callenv[", var, "] = ", val)
callenv[var] = val
cmake_configure_extra_commands = os.environ["INPUT_CMAKE_CONFIGURE_EXTRA_ARGS"].split()
cmake_configure_commands.extend(cmake_configure_extra_commands)
if verbose:
eprint("CMake configure env: ", json.dumps(callenv, indent=4, sort_keys=True))
check_call(cmake_configure_commands, env=callenv)
if os.environ["INPUT_CMAKE_BUILD_ENABLE"] == "true":
cmake_build_options = os.environ.get("INPUT_CMAKE_BUILD_OPTIONS", "").split()
args = ["cmake", "--build", build_directory]
args.extend(cmake_build_options)
check_call(args)
if os.environ["INPUT_CTEST_ENABLE"] == "true":
args = ["ctest"]
args.extend(os.environ.get("INPUT_CTEST_FLAGS", "").split())
check_call(args, cwd=build_directory)
if os.environ["INPUT_CMAKE_INSTALL_ENABLE"] == "true":
args = [
"cmake",
"--install",
build_directory,
"--prefix",
os.environ["INPUT_CMAKE_INSTALL_DIRECTORY"],
]
cmake_install_options = os.environ.get("INPUT_CMAKE_INSTALL_OPTIONS", "")
args.extend(cmake_install_options)
check_call(args)