summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorScott Shawcroft <[email protected]>2022-01-05 15:44:23 -0800
committerScott Shawcroft <[email protected]>2022-01-05 15:44:23 -0800
commit7b27b8f498a185d8a7c1bea5dac8f43e7030ebd7 (patch)
tree520d7b75abe6f1b679d3ef5e42b1ce26747955fa /tools
parent4fe0a30ec7bf254c839a76da9be3a2968d1690db (diff)
Unify skip and only logic for build scripts
And switch to a single file that can include mcu, family or board.
Diffstat (limited to 'tools')
-rw-r--r--tools/build_board.py31
-rw-r--r--tools/build_esp32sx.py7
-rw-r--r--tools/build_family.py44
-rw-r--r--tools/build_utils.py61
4 files changed, 70 insertions, 73 deletions
diff --git a/tools/build_board.py b/tools/build_board.py
index 9397c754f..b2a80c680 100644
--- a/tools/build_board.py
+++ b/tools/build_board.py
@@ -4,6 +4,8 @@ import sys
import subprocess
import time
+import build_utils
+
SUCCEEDED = "\033[32msucceeded\033[0m"
FAILED = "\033[31mfailed\033[0m"
SKIPPED = "\033[33mskipped\033[0m"
@@ -50,7 +52,7 @@ def build_board(example, board):
sram_size = "-"
# Check if board is skipped
- if skip_example(example, board):
+ if build_utils.skip_example(example, board):
success = SKIPPED
skip_count += 1
print(build_format.format(example, board, success, '-', flash_size, sram_size))
@@ -82,33 +84,6 @@ def build_size(example, board):
sram_size = int(size_list[1]) + int(size_list[2])
return (flash_size, sram_size)
-def skip_example(example, board):
- ex_dir = 'examples/' + example
- board_mk = 'hw/bsp/{}/board.mk'.format(board)
- with open(board_mk) as mk:
- mk_contents = mk.read()
-
- # Skip all OPT_MCU_NONE these are WIP port
- if '-DCFG_TUSB_MCU=OPT_MCU_NONE' in mk_contents:
- return 1
-
- # Skip if CFG_TUSB_MCU in board.mk to match skip file
- for skip_file in glob.iglob(ex_dir + '/.skip.MCU_*'):
- mcu_cflag = '-DCFG_TUSB_MCU=OPT_' + os.path.basename(skip_file).split('.')[2]
- if mcu_cflag in mk_contents:
- return 1
-
- # Build only list, if exists only these MCU are built
- only_list = list(glob.iglob(ex_dir + '/.only.MCU_*'))
- if len(only_list) > 0:
- for only_file in only_list:
- mcu_cflag = '-DCFG_TUSB_MCU=OPT_' + os.path.basename(only_file).split('.')[2]
- if mcu_cflag in mk_contents:
- return 0
- return 1
-
- return 0
-
print(build_separator)
print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
diff --git a/tools/build_esp32sx.py b/tools/build_esp32sx.py
index 91953f080..2947a0a6b 100644
--- a/tools/build_esp32sx.py
+++ b/tools/build_esp32sx.py
@@ -4,6 +4,8 @@ import sys
import subprocess
import time
+import build_utils
+
SUCCEEDED = "\033[32msucceeded\033[0m"
FAILED = "\033[31mfailed\033[0m"
SKIPPED = "\033[33mskipped\033[0m"
@@ -51,7 +53,7 @@ def build_board(example, board):
sram_size = "-"
# Check if board is skipped
- if skip_example(example, board):
+ if build_utils.skip_example(example, board):
success = SKIPPED
skip_count += 1
print(build_format.format(example, board, success, '-', flash_size, sram_size))
@@ -83,9 +85,6 @@ def build_size(example, board):
sram_size = int(size_list[1]) + int(size_list[2])
return (flash_size, sram_size)
-def skip_example(example, board):
- return 0
-
print(build_separator)
print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
print(build_separator)
diff --git a/tools/build_family.py b/tools/build_family.py
index ccbcfa3f8..4094d07db 100644
--- a/tools/build_family.py
+++ b/tools/build_family.py
@@ -4,6 +4,8 @@ import sys
import subprocess
import time
+import build_utils
+
SUCCEEDED = "\033[32msucceeded\033[0m"
FAILED = "\033[31mfailed\033[0m"
SKIPPED = "\033[33mskipped\033[0m"
@@ -62,7 +64,7 @@ def build_board(example, board):
sram_size = "-"
# Check if board is skipped
- if skip_example(example, board):
+ if build_utils.skip_example(example, board):
success = SKIPPED
skip_count += 1
print(build_format.format(example, board, success, '-', flash_size, sram_size))
@@ -95,46 +97,6 @@ def build_size(example, board):
sram_size = int(size_list[1]) + int(size_list[2])
return (flash_size, sram_size)
-def skip_example(example, board):
- ex_dir = 'examples/' + example
-
- # Check if example is skipped by family or board directory
- skip_file = ".skip." + example.replace('/', '.');
- if os.path.isfile("hw/bsp/{}/{}".format(family, skip_file)) or os.path.isfile("hw/bsp/{}/boards/{}/{}".format(family, board, skip_file)):
- return 1
-
- # Otherwise check if mcu is excluded by example directory
-
- # family CMake
- family_mk = 'hw/bsp/{}/family.cmake'.format(family)
-
- # family.mk
- if not os.path.exists(family_mk):
- family_mk = 'hw/bsp/{}/family.mk'.format(family)
-
- with open(family_mk) as mk:
- mk_contents = mk.read()
-
- # Skip all OPT_MCU_NONE these are WIP port
- if 'CFG_TUSB_MCU=OPT_MCU_NONE' in mk_contents:
- return 1
-
- # Skip if CFG_TUSB_MCU in family.mk to match skip file
- for skip_file in glob.iglob(ex_dir + '/.skip.MCU_*'):
- mcu_cflag = 'CFG_TUSB_MCU=OPT_' + os.path.basename(skip_file).split('.')[2]
- if mcu_cflag in mk_contents:
- return 1
-
- # Build only list, if exists only these MCU are built
- only_list = list(glob.iglob(ex_dir + '/.only.MCU_*'))
- if len(only_list) > 0:
- for only_file in only_list:
- mcu_cflag = 'CFG_TUSB_MCU=OPT_' + os.path.basename(only_file).split('.')[2]
- if mcu_cflag in mk_contents:
- return 0
- return 1
- return 0
-
print(build_separator)
print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
diff --git a/tools/build_utils.py b/tools/build_utils.py
new file mode 100644
index 000000000..299fffa4d
--- /dev/null
+++ b/tools/build_utils.py
@@ -0,0 +1,61 @@
+import pathlib
+
+def skip_example(example, board):
+ ex_dir = pathlib.Path('examples/') / example
+ bsp = pathlib.Path("hw/bsp")
+
+ board_dir = list(bsp.glob("*/boards/" + board))
+ if not board_dir:
+ # Skip unknown boards
+ return True
+
+ board_dir = list(board_dir)[0]
+
+ family_dir = board_dir.parent.parent
+ family = family_dir.name
+
+ # family CMake
+ family_mk = family_dir / "family.cmake"
+
+ # family.mk
+ if not family_mk.exists():
+ family_mk = family_dir / "family.mk"
+
+ mk_contents = family_mk.read_text()
+
+ # Find the mcu
+ if "CFG_TUSB_MCU=OPT_MCU_" not in mk_contents:
+ board_mk = board_dir / "board.cmake"
+ if not board_mk.exists():
+ board_mk = board_dir / "board.mk"
+
+ mk_contents = board_mk.read_text()
+
+ for token in mk_contents.split():
+ if "CFG_TUSB_MCU=OPT_MCU_" in token:
+ # Strip " because cmake files has them.
+ token = token.strip("\"")
+ _, opt_mcu = token.split("=")
+ mcu = opt_mcu[len("OPT_MCU_"):]
+
+ # Skip all OPT_MCU_NONE these are WIP port
+ if mcu == "NONE":
+ return True
+
+ skip_file = ex_dir / "skip.txt"
+ only_file = ex_dir / "only.txt"
+
+ if skip_file.exists() and only_file.exists():
+ raise RuntimeError("Only have a skip or only file. Not both.")
+ elif skip_file.exists():
+ skips = skip_file.read_text().split()
+ return ("mcu:" + mcu in skips or
+ "board:" + board in skips or
+ "family:" + family in skips)
+ elif only_file.exists():
+ onlys = only_file.read_text().split()
+ return not ("mcu:" + mcu in onlys or
+ "board:" + board in onlys or
+ "family:" + family in onlys)
+
+ return False