From b68957113c56bae1a9e1f871ec4909c89a38e924 Mon Sep 17 00:00:00 2001 From: kurisaw <2053731441@qq.com> Date: Mon, 29 Jan 2024 11:40:11 +0800 Subject: [PATCH] [bsp][renesas] Optimize startup check script structure --- bsp/renesas/ebf_qi_min_6m5/SConstruct | 12 +++- bsp/renesas/ra2l1-cpk/SConstruct | 10 ++- bsp/renesas/ra2l1-cpk/startup_check.py | 62 ------------------- bsp/renesas/ra4m2-eco/SConstruct | 12 +++- bsp/renesas/ra4m2-eco/startup_check.py | 62 ------------------- bsp/renesas/ra6m3-ek/SConstruct | 10 ++- bsp/renesas/ra6m3-ek/startup_check.py | 62 ------------------- bsp/renesas/ra6m3-hmi-board/SConstruct | 10 ++- bsp/renesas/ra6m3-hmi-board/startup_check.py | 62 ------------------- bsp/renesas/ra6m4-cpk/SConstruct | 10 ++- bsp/renesas/ra6m4-cpk/startup_check.py | 62 ------------------- bsp/renesas/ra6m4-iot/SConstruct | 10 ++- bsp/renesas/ra6m4-iot/startup_check.py | 62 ------------------- bsp/renesas/ra8d1-ek/SConstruct | 10 ++- bsp/renesas/ra8d1-ek/startup_check.py | 62 ------------------- bsp/renesas/ra8m1-ek/SConstruct | 10 ++- bsp/renesas/ra8m1-ek/startup_check.py | 62 ------------------- .../startup_check.py | 7 ++- 18 files changed, 82 insertions(+), 515 deletions(-) delete mode 100644 bsp/renesas/ra2l1-cpk/startup_check.py delete mode 100644 bsp/renesas/ra4m2-eco/startup_check.py delete mode 100644 bsp/renesas/ra6m3-ek/startup_check.py delete mode 100644 bsp/renesas/ra6m3-hmi-board/startup_check.py delete mode 100644 bsp/renesas/ra6m4-cpk/startup_check.py delete mode 100644 bsp/renesas/ra6m4-iot/startup_check.py delete mode 100644 bsp/renesas/ra8d1-ek/startup_check.py delete mode 100644 bsp/renesas/ra8m1-ek/startup_check.py rename bsp/renesas/{ebf_qi_min_6m5 => tools}/startup_check.py (90%) diff --git a/bsp/renesas/ebf_qi_min_6m5/SConstruct b/bsp/renesas/ebf_qi_min_6m5/SConstruct index 57d44892c4..86e5c0cae1 100644 --- a/bsp/renesas/ebf_qi_min_6m5/SConstruct +++ b/bsp/renesas/ebf_qi_min_6m5/SConstruct @@ -46,8 +46,16 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) + +RegisterPreBuildingAction(startup_check) # prepare building environment objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) diff --git a/bsp/renesas/ra2l1-cpk/SConstruct b/bsp/renesas/ra2l1-cpk/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra2l1-cpk/SConstruct +++ b/bsp/renesas/ra2l1-cpk/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra2l1-cpk/startup_check.py b/bsp/renesas/ra2l1-cpk/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra2l1-cpk/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra4m2-eco/SConstruct b/bsp/renesas/ra4m2-eco/SConstruct index 57d44892c4..86e5c0cae1 100644 --- a/bsp/renesas/ra4m2-eco/SConstruct +++ b/bsp/renesas/ra4m2-eco/SConstruct @@ -46,8 +46,16 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) + +RegisterPreBuildingAction(startup_check) # prepare building environment objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) diff --git a/bsp/renesas/ra4m2-eco/startup_check.py b/bsp/renesas/ra4m2-eco/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra4m2-eco/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra6m3-ek/SConstruct b/bsp/renesas/ra6m3-ek/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra6m3-ek/SConstruct +++ b/bsp/renesas/ra6m3-ek/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra6m3-ek/startup_check.py b/bsp/renesas/ra6m3-ek/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra6m3-ek/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra6m3-hmi-board/SConstruct b/bsp/renesas/ra6m3-hmi-board/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra6m3-hmi-board/SConstruct +++ b/bsp/renesas/ra6m3-hmi-board/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra6m3-hmi-board/startup_check.py b/bsp/renesas/ra6m3-hmi-board/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra6m3-hmi-board/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra6m4-cpk/SConstruct b/bsp/renesas/ra6m4-cpk/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra6m4-cpk/SConstruct +++ b/bsp/renesas/ra6m4-cpk/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra6m4-cpk/startup_check.py b/bsp/renesas/ra6m4-cpk/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra6m4-cpk/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra6m4-iot/SConstruct b/bsp/renesas/ra6m4-iot/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra6m4-iot/SConstruct +++ b/bsp/renesas/ra6m4-iot/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra6m4-iot/startup_check.py b/bsp/renesas/ra6m4-iot/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra6m4-iot/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra8d1-ek/SConstruct b/bsp/renesas/ra8d1-ek/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra8d1-ek/SConstruct +++ b/bsp/renesas/ra8d1-ek/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra8d1-ek/startup_check.py b/bsp/renesas/ra8d1-ek/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra8d1-ek/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ra8m1-ek/SConstruct b/bsp/renesas/ra8m1-ek/SConstruct index 91489ff888..86e5c0cae1 100644 --- a/bsp/renesas/ra8m1-ek/SConstruct +++ b/bsp/renesas/ra8m1-ek/SConstruct @@ -46,8 +46,14 @@ Export('SDK_LIB') rtconfig.BSP_LIBRARY_TYPE = None def startup_check(): - import startup_check - startup_check.startup_check() + import subprocess + startup_check_path = os.getcwd() + "/../tools/startup_check.py" + + if os.path.exists(startup_check_path): + try: + subprocess.call(["python", startup_check_path]) + except: + subprocess.call(["python3", startup_check_path]) RegisterPreBuildingAction(startup_check) diff --git a/bsp/renesas/ra8m1-ek/startup_check.py b/bsp/renesas/ra8m1-ek/startup_check.py deleted file mode 100644 index 6eeae016f5..0000000000 --- a/bsp/renesas/ra8m1-ek/startup_check.py +++ /dev/null @@ -1,62 +0,0 @@ -import subprocess -import sys - -def check_git_exists(): - try: - # Check if Git is installed - subprocess.call(["git", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except OSError: - return False - return True - -def install_git(): - if sys.version_info[0] == 2: - version_cmd = subprocess.call - else: - version_cmd = subprocess.run - - # Install Git based on the operating system type - system = sys.platform.lower() - if "linux" in system: - version_cmd(["sudo", "apt-get", "install", "git"]) - elif "darwin" in system: - version_cmd(["brew", "install", "git"]) - elif "win" in system: - print("Please manually install Git and ensure it is added to the system PATH.") - sys.exit(1) - -def check_file_changes(filepath): - # Use Git to check the file status - result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, _ = result.communicate() - - # Return True if the file has changes - return bool(out.decode('utf-8')) - -def revert_to_original(filepath): - # Use Git to revert the file to its original state - subprocess.call(["git", "checkout", filepath]) - -def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" - python_executable = 'python' if sys.version_info[0] == 2 else 'python3' - - # Check if Git is installed, if not, try to install it - if not check_git_exists(): - print("Git not detected, attempting to install...") - install_git() - - # Check if Git is installed after the installation attempt - if not check_git_exists(): - print("Git installation failed. Please manually install Git and add it to the system PATH.") - sys.exit(1) - - # Check if the file has changes - if check_file_changes(file_path): - # If changes are detected, revert the file to its original state - revert_to_original(file_path) - # else: - # print "File {file_path} is unchanged." - -if __name__ == "__main__": - startup_check() diff --git a/bsp/renesas/ebf_qi_min_6m5/startup_check.py b/bsp/renesas/tools/startup_check.py similarity index 90% rename from bsp/renesas/ebf_qi_min_6m5/startup_check.py rename to bsp/renesas/tools/startup_check.py index 6eeae016f5..0cf1e4f38b 100644 --- a/bsp/renesas/ebf_qi_min_6m5/startup_check.py +++ b/bsp/renesas/tools/startup_check.py @@ -1,5 +1,9 @@ import subprocess import sys +import os + +# cwd_path = os.getcwd() +# sys.path.append(os.path.join(os.path.dirname(cwd_path), 'rt-thread', 'tools')) def check_git_exists(): try: @@ -26,6 +30,7 @@ def install_git(): sys.exit(1) def check_file_changes(filepath): + # Use Git to check the file status result = subprocess.Popen(["git", "status", "--porcelain", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _ = result.communicate() @@ -38,7 +43,7 @@ def revert_to_original(filepath): subprocess.call(["git", "checkout", filepath]) def startup_check(): - file_path = "ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" + file_path = os.getcwd() + f"/ra/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c" python_executable = 'python' if sys.version_info[0] == 2 else 'python3' # Check if Git is installed, if not, try to install it