Skip to content

Commit

Permalink
add rule 'Checks compiling examples'
Browse files Browse the repository at this point in the history
  • Loading branch information
amatilda committed Jun 27, 2024
1 parent 8e15b1c commit 22817d6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 92 deletions.
4 changes: 2 additions & 2 deletions hardware/arduino/zunoG2/cores/core_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@
"-fno-rtti",
"-fsingle-precision-constant",
"-fzero-initialized-in-bss",
"-flto",
"-Os",
"-DCMSIS_NVIC_VIRTUAL",
"-fno-exceptions"],
"linker_flags":["-mthumb",
"-Os",
"-std=c++17",
"--specs=nano.specs",
"-lm",
"-flto",
"-Os",
"-Wl,--gc-sections"],
"chip_depending":{
"ZGM230SA27HGN":{
Expand Down
51 changes: 37 additions & 14 deletions script/compiling_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
85 changes: 9 additions & 76 deletions script/support.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 22817d6

Please sign in to comment.