- def main() to prevent global variable platform/platforms/fqbn
- remove obsolete test_examples_in_learningrepo()
This commit is contained in:
parent
3ecccafa3e
commit
a6e7d709bf
1 changed files with 21 additions and 50 deletions
|
|
@ -62,7 +62,6 @@ elif "METROX-Examples-and-Project-Sketches" in BUILD_DIR:
|
|||
CROSS = u'\N{cross mark}'
|
||||
CHECK = u'\N{check mark}'
|
||||
|
||||
|
||||
BSP_URLS = (
|
||||
"https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,"
|
||||
"http://arduino.esp8266.com/stable/package_esp8266com_index.json,"
|
||||
|
|
@ -71,6 +70,9 @@ BSP_URLS = (
|
|||
"https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json"
|
||||
)
|
||||
|
||||
# global exit code
|
||||
success = 0
|
||||
|
||||
class ColorPrint:
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -249,10 +251,12 @@ def download_uf2_utils():
|
|||
return False
|
||||
return True
|
||||
|
||||
def generate_uf2(example_path):
|
||||
"""Generates a .uf2 file from a .bin or .hex file.
|
||||
:param str example_path: A path to the compiled .bin or .hex file.
|
||||
|
||||
def generate_uf2(platform, fqbn, example_path):
|
||||
"""Generates a .uf2 file from a .bin or .hex file.
|
||||
:param str platform: The platform name.
|
||||
:param str fqbn: The fully qualified board name.
|
||||
:param str example_path: A path to the compiled .bin or .hex file.
|
||||
"""
|
||||
if not download_uf2_utils():
|
||||
return None
|
||||
|
|
@ -314,12 +318,13 @@ def group_output(title):
|
|||
sys.stdout.flush()
|
||||
|
||||
|
||||
def test_examples_in_folder(folderpath):
|
||||
def test_examples_in_folder(platform, folderpath):
|
||||
global success
|
||||
fqbn = ALL_PLATFORMS[platform][0]
|
||||
for example in sorted(os.listdir(folderpath)):
|
||||
examplepath = folderpath+"/"+example
|
||||
if os.path.isdir(examplepath):
|
||||
test_examples_in_folder(examplepath)
|
||||
test_examples_in_folder(platform, examplepath)
|
||||
continue
|
||||
if not examplepath.endswith(".ino"):
|
||||
continue
|
||||
|
|
@ -374,11 +379,11 @@ def test_examples_in_folder(folderpath):
|
|||
with group_output(f"{example} {fqbn} build output"):
|
||||
ColorPrint.print_fail(err.decode("utf-8"))
|
||||
if os.path.exists(gen_file_name):
|
||||
if ALL_PLATFORMS[platform][1] == None:
|
||||
if ALL_PLATFORMS[platform][1] is None:
|
||||
ColorPrint.print_info("Platform does not support UF2 files, skipping...")
|
||||
else:
|
||||
ColorPrint.print_info("Generating UF2...")
|
||||
filename = generate_uf2(folderpath)
|
||||
filename = generate_uf2(platform, fqbn, folderpath)
|
||||
if filename is None:
|
||||
success = 1 # failure
|
||||
if IS_LEARNING_SYS:
|
||||
|
|
@ -394,52 +399,14 @@ def test_examples_in_folder(folderpath):
|
|||
ColorPrint.print_fail(err.decode("utf-8"))
|
||||
success = 1
|
||||
|
||||
def test_examples_in_learningrepo(folderpath):
|
||||
global success
|
||||
for project in os.listdir(folderpath):
|
||||
projectpath = folderpath+"/"+project
|
||||
if os.path.isdir(learningrepo):
|
||||
test_examples_in_learningrepo(projectpath)
|
||||
continue
|
||||
if not projectpath.endswith(".ino"):
|
||||
continue
|
||||
# found an INO!
|
||||
print('\t'+projectpath, end=' ', flush=True)
|
||||
# check if we should SKIP
|
||||
skipfilename = folderpath+"/."+platform+".test.skip"
|
||||
onlyfilename = folderpath+"/."+platform+".test.only"
|
||||
if os.path.exists(skipfilename):
|
||||
ColorPrint.print_warn("skipping")
|
||||
continue
|
||||
elif glob.glob(folderpath+"/.*.test.only") and not os.path.exists(onlyfilename):
|
||||
ColorPrint.print_warn("skipping")
|
||||
continue
|
||||
|
||||
cmd = ['arduino-cli', 'compile', '--warnings', 'all', '--fqbn', fqbn, projectpath]
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
r = proc.wait()
|
||||
out = proc.stdout.read()
|
||||
err = proc.stderr.read()
|
||||
if r == 0:
|
||||
ColorPrint.print_pass(CHECK)
|
||||
if err:
|
||||
# also print out warning message
|
||||
ColorPrint.print_fail(err.decode("utf-8"))
|
||||
else:
|
||||
ColorPrint.print_fail(CROSS)
|
||||
ColorPrint.print_fail(out.decode("utf-8"))
|
||||
ColorPrint.print_fail(err.decode("utf-8"))
|
||||
success = 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
# Test platforms
|
||||
platforms = []
|
||||
success = 0
|
||||
|
||||
# expand groups:
|
||||
for arg in sys.argv[1:]:
|
||||
|
||||
platform = ALL_PLATFORMS.get(arg, None)
|
||||
if isinstance(platform, list):
|
||||
platforms.append(arg)
|
||||
|
|
@ -460,7 +427,11 @@ if __name__ == "__main__":
|
|||
install_platform(":".join(fqbn.split(':', 2)[0:2]), ALL_PLATFORMS[platform]) # take only first two elements
|
||||
print('#'*80)
|
||||
if not IS_LEARNING_SYS:
|
||||
test_examples_in_folder(BUILD_DIR+"/examples")
|
||||
test_examples_in_folder(platform, BUILD_DIR+"/examples")
|
||||
else:
|
||||
test_examples_in_folder(BUILD_DIR)
|
||||
test_examples_in_folder(platform, BUILD_DIR)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
exit(success)
|
||||
|
|
|
|||
Loading…
Reference in a new issue