From 22817d6cbc91fec3168d6c497ede70be80343363 Mon Sep 17 00:00:00 2001 From: amatilda Date: Thu, 27 Jun 2024 13:50:17 +0300 Subject: [PATCH] add rule 'Checks compiling examples' --- .../arduino/zunoG2/cores/core_metadata.json | 4 +- script/compiling_examples.py | 51 ++++++++--- script/support.py | 85 ++----------------- 3 files changed, 48 insertions(+), 92 deletions(-) diff --git a/hardware/arduino/zunoG2/cores/core_metadata.json b/hardware/arduino/zunoG2/cores/core_metadata.json index 064d19d3..f18e1fa6 100644 --- a/hardware/arduino/zunoG2/cores/core_metadata.json +++ b/hardware/arduino/zunoG2/cores/core_metadata.json @@ -71,7 +71,7 @@ "-fno-rtti", "-fsingle-precision-constant", "-fzero-initialized-in-bss", - "-flto", + "-Os", "-DCMSIS_NVIC_VIRTUAL", "-fno-exceptions"], "linker_flags":["-mthumb", @@ -79,7 +79,7 @@ "-std=c++17", "--specs=nano.specs", "-lm", - "-flto", + "-Os", "-Wl,--gc-sections"], "chip_depending":{ "ZGM230SA27HGN":{ diff --git a/script/compiling_examples.py b/script/compiling_examples.py index 2fcbcbde..a5fa631f 100644 --- a/script/compiling_examples.py +++ b/script/compiling_examples.py @@ -64,6 +64,23 @@ def CompliteAllChipLoopDirFunc(path_ino:str, chip_name:str, path_out:str, tool_p finallizeStepStatus(os.path.basename(entry.path), "SKIP") pass +def CompliteAllChipFunc(tool_path:str, gcc_version:str, question:bool) -> None: + temp_dir = tempfile.TemporaryDirectory() + ino_lists = [os.path.abspath(os.path.join(func_prog_dir_get(), "..", "hardware", "arduino", "zunoG2", "ctt"))] + ino_lists = ino_lists + [os.path.abspath(os.path.join(func_prog_dir_get(), "..", "hardware", "arduino", "zunoG2", "libraries", "Z-Uno-2G", "examples"))] + chip_list = ["ZGM130S037HGN1"] + for chip in chip_list: + try: + path_out_chip = os.path.join(temp_dir.name, chip) + if os.path.exists(path_out_chip) == False: + os.makedirs(path_out_chip, exist_ok=True) + except Exception as e: + sys.stderr.write("Error: mkdir. Code %s\n"%(e)) + sys.exit(-1) + for ino in ino_lists: + CompliteAllChipLoopDirFunc(ino, chip, path_out_chip, tool_path, gcc_version, question) + temp_dir.cleanup() + argv = sys.argv[0x1:] if len(argv) < 0x2 or len(argv) > 0x3: sys.stderr.write("Wrong number of arguments\n") @@ -74,17 +91,23 @@ def CompliteAllChipLoopDirFunc(path_ino:str, chip_name:str, path_out:str, tool_p if len(argv) == 0x3: question = True -path_out = tempfile.TemporaryDirectory().name -ino_lists = [os.path.abspath(os.path.join(func_prog_dir_get(), "..", "hardware", "arduino", "zunoG2", "ctt"))] -# ino_lists = ino_lists + [os.path.abspath(os.path.join(func_prog_dir_get(), "..", "hardware", "arduino", "zunoG2", "libraries", "Z-Uno-2G", "examples"))] -chip_list = ["ZGM130S037HGN1"] -for chip in chip_list: - try: - path_out_chip = os.path.join(path_out, chip) - if os.path.exists(path_out_chip) == False: - os.makedirs(path_out_chip, exist_ok=True) - except Exception as e: - sys.stderr.write("Error: mkdir. Code %s\n"%(e)) - sys.exit(-1) - for ino in ino_lists: - CompliteAllChipLoopDirFunc(ino, chip, path_out_chip, tool_path, gcc_version, question) +finallizeStepStatus("COMPLITE WITH LTO", "START") +CompliteAllChipFunc(tool_path, gcc_version, question) +finallizeStepStatus("COMPLITE WITH LTO", "FINISH") + +filename = os.path.abspath(os.path.join(func_prog_dir_get(), "..", "hardware", "arduino", "zunoG2", "cores", "core_metadata.json")) +try: + file = open(filename, "r") + text = file.read() + file.close() + text = text.replace('"-flto"', '"-Os"') + file = open(filename, "w") + file.write(text) + file.close() +except Exception as e: + sys.stderr.write("Failed to change 'core_metadata.json' - %s\n"%(e)) + sys.exit(-1) + +finallizeStepStatus("COMPLITE WITHOUT LTO", "START") +CompliteAllChipFunc(tool_path, gcc_version, question) +finallizeStepStatus("COMPLITE WITHOUT LTO", "FINISH") \ No newline at end of file diff --git a/script/support.py b/script/support.py index 833f0dd8..2078675d 100644 --- a/script/support.py +++ b/script/support.py @@ -1,14 +1,18 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import inspect import argparse import platform import os -import tempfile -import subprocess -import hashlib import shutil import json +import sys + +def func_prog_dir_get() -> str: + if getattr(sys, 'frozen', False): + application_path = os.path.dirname(sys.executable) + else: + application_path = os.path.dirname(__file__) + return (os.path.abspath(application_path)) MY_VERSION = "0.1" @@ -29,71 +33,8 @@ def finallizeStepStatus(text, stat_text): print('\r%-40s %s' % (text, '.' * 30), end='') print('%30s\n' % (stat_text), end='') -def CompliteAllChipLoopDirFunc(path_ino, path_tools, path_out, chip_name): - path_core = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "..", "..","core")) - zme_make = os.path.abspath(os.path.join(path_tools, "toolchain", "zme_make", "zme_make")) - path_gcc_include = os.path.abspath(os.path.join(path_tools, "gcc", "lib", "gcc", "arm-none-eabi", "10.3.1", "include")) - path_gcc_bin = os.path.abspath(os.path.join(path_tools, "gcc", "bin")) - path_libclang = os.path.abspath(os.path.join(path_tools, "toolchain", "libClang")) - path_cores = os.path.abspath(os.path.join(path_core, "hardware", "arduino", "zunoG2", "cores")) - path_libraries = os.path.abspath(os.path.join(path_core, "hardware", "arduino", "zunoG2", "libraries")) - with os.scandir(path_ino) as it: - for entry in it: - if entry.is_dir(): - CompliteAllChipLoopDirFunc(entry.path, path_tools, path_out, chip_name) - if entry.is_file() and entry.name.endswith(".ino"): - path_out_ino = os.path.join(path_out, hashlib.md5(entry.path.encode()).hexdigest()) - try: - if os.path.exists(path_out_ino) == False: - os.makedirs(path_out_ino, exist_ok=True) - except Exception as e: - print("Error: mkdir. Code %s"%e) - exit(-1) - while True: - try: - arg = [zme_make, "build", entry.path, '-S', path_cores, '-S', path_libraries, "-S", path_gcc_include, "-B", path_out_ino, "-T", path_gcc_bin, "-lcl", path_libclang, "-O", "BO:-Wall", "-O", "BO:-Wextra", "-O", "BO:-Werror", "-C", chip_name] - out = subprocess.run(arg, stdout=subprocess.PIPE, text=True) - except Exception as e: - print("Error: No run. Code %s"%e) - exit(-1) - if out.returncode == 0x0: - finallizeStepStatus(os.path.basename(entry.path), "OK") - break - print(out.stdout) - while True: - text = input("Would you like to repeat, skip or cancel? - repeat|skip|cancel\n") - if text == "cancel": - exit(-1) - if text == "repeat" or text == "skip": - break - if text == "repeat": - continue - if text == "skip": - break - finallizeStepStatus(os.path.basename(entry.path), "SKIP") - pass - -def CompliteAllChipFunc(path_ino, path_out, path_tools, chip_name): - try: - if os.path.exists(path_out) == False: - os.makedirs(path_out, exist_ok=True) - except Exception as e: - print("Error: mkdir. Code %s"%e) - exit(-1) - CompliteAllChipLoopDirFunc(path_ino, path_tools, path_out, chip_name) - pass - -def CompliteAllFunc(path_tools): - path_out = os.path.join(tempfile.gettempdir(), "Zuno_test_7423A65F79394BC7B1DC1D417422781F") - path_ino = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "..", "..","core", "hardware", "arduino", "zunoG2", "ctt")) - chip_name = "ZGM130S037HGN1" - CompliteAllChipFunc(path_ino, os.path.join(path_out, chip_name), path_tools, chip_name) - path_ino = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "..", "..","core", "hardware", "arduino", "zunoG2", "libraries", "Z-Uno-2G", "examples")) - CompliteAllChipFunc(path_ino, os.path.join(path_out, chip_name), path_tools, chip_name) - pass - def SdkFunc(path_sdk): - path_core = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), "..", "..","core")) + path_core = os.path.abspath(os.path.join(func_prog_dir_get(), "..", "..","core")) path_core_metadata = os.path.join(path_core, "hardware", "arduino", "zunoG2", "cores", "core_metadata.json") path_emlib = os.path.join(path_core, "hardware", "arduino", "zunoG2", "cores", "emlib") path_cmsis = os.path.join(path_core, "hardware", "arduino", "zunoG2", "cores", "cmsis") @@ -145,10 +86,6 @@ def SdkFunc(path_sdk): def dummyFunc(args): print("*** Platform: %s Version: %s ***"%(platform.system(), MY_VERSION)) - def mainCompliteAllFunc(args): - CompliteAllFunc(args.path_tools) - pass - def mainSdkFunc(args): SdkFunc(args.path_sdk) pass @@ -159,10 +96,6 @@ def Main(): parser.set_defaults(func=dummyFunc) subparsers = parser.add_subparsers() - parserppCompliteAll = subparsers.add_parser('complite_all', help="") - parserppCompliteAll.add_argument('path_tools', help="") - parserppCompliteAll.set_defaults(func=mainCompliteAllFunc) - parserppSdk = subparsers.add_parser('sdk', help="") parserppSdk.add_argument('path_sdk', help="") parserppSdk.set_defaults(func=mainSdkFunc)