feat(build): check platforms exist before building
Check the list of platforms to build provided on the command line
through the PLATFORM variable are available from the project.
Provide a 'make list' option permitting to list platforms available
for building.
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: I3bfe36ef998961c27f9328188306b2a0f5c74d26
diff --git a/build/check_platform_exists.py b/build/check_platform_exists.py
new file mode 100755
index 0000000..2675d49
--- /dev/null
+++ b/build/check_platform_exists.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+#
+# Copyright 2024 The Hafnium Authors.
+#
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://opensource.org/licenses/BSD-3-Clause.
+
+"""Check a list of platforms are defined in a project.
+
+First argument is the project name (e.g. reference).
+The script returns a zero error code if the list of platform names given as
+arguments (following the project name) are available for building.
+If one platform supplied in arguments doesn't exist, the script prints the
+list of supported platforms and returns 1 as an exit code.
+If the script is called with only the project name, it prints the list of
+available platforms and returns 0.
+"""
+
+import sys
+import re
+import os
+
+def Main():
+ project = sys.argv[1]
+
+ platforms = []
+ reg = re.compile('aarch64_toolchains\("(\w*)')
+ with open("project/" + project + "/BUILD.gn") as project_file:
+ for line in project_file:
+ platforms += reg.findall(line)
+
+ if len(sys.argv) < 3:
+ print("Supported platforms: ", platforms)
+ return 0
+
+ platform_list = sys.argv[2:]
+
+ if not set(platform_list).issubset(platforms):
+ print("Supported platforms: ", platforms)
+ return 1
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(Main())