Apple M1: Support for unit testing universal builds

This commit is contained in:
Skyler Saleh 2021-06-19 10:06:47 -07:00
parent 655ed37983
commit 1203c23781
1 changed files with 38 additions and 1 deletions

View File

@ -70,6 +70,8 @@ DEFAULT_CONFIG = {
"generator": "Unix Makefiles", "generator": "Unix Makefiles",
"build_type": "Release", "build_type": "Release",
"run_unit_tests": False,
} }
# Architectures to build for. This is explicity left out of the command line # Architectures to build for. This is explicity left out of the command line
@ -114,6 +116,9 @@ def parse_args(conf=DEFAULT_CONFIG):
help="Path to .entitlements file for code signing", help="Path to .entitlements file for code signing",
default=conf["entitlements"]) default=conf["entitlements"])
parser.add_argument("--run_unit_tests", action="store_true",
default=conf["run_unit_tests"])
parser.add_argument( parser.add_argument(
"--codesign", "--codesign",
help="Code signing identity to use to sign the applications", help="Code signing identity to use to sign the applications",
@ -323,8 +328,40 @@ def build(config):
"--verbose=2", "--verbose=2",
path]) path])
print("Built Universal Binary successfully!")
# Build and run unit tests for each architecture
unit_test_results = {}
if config["run_unit_tests"]:
for arch in ARCHITECTURES:
if not os.path.exists(arch):
os.mkdir(arch)
print("Building and running unit tests for: {arch}")
unit_test_results[arch] = \
subprocess.call(["cmake", "--build", ".",
"--config", config["build_type"],
"--target", "unittests",
"--parallel", f"{threads}"], cwd=arch)
passed_unit_tests = True
for a in unit_test_results:
code = unit_test_results[a]
passed = code == 0
status_string = "PASSED"
if not passed:
passed_unit_tests = False
status_string = f"FAILED ({code})"
print(a + " Unit Tests: " + status_string)
if not passed_unit_tests:
exit(-1)
print("Passed all unit tests")
if __name__ == "__main__": if __name__ == "__main__":
conf = parse_args() conf = parse_args()
build(conf) build(conf)
print("Built Universal Binary successfully!")