diff options
| author | Bernard Xiong <[email protected]> | 2021-03-02 15:00:43 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-02 15:00:43 +0800 |
| commit | 2c12493ff342ea9ba808311c3f6835eba31a8d3e (patch) | |
| tree | b1e1dfbeaead7c08ab8d7d0f34066154c125841b /tools | |
| parent | 5f17cf9204e501d971cd28486e0a7193d2f1fae4 (diff) | |
| parent | 19871ac32e41590b1f3e3742d9ab023dc3147ba0 (diff) | |
Merge pull request #4404 from KyleChenjh/lts-v3.1.x
[Update] Sync from v4.0.3
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/building.py | 11 | ||||
| -rw-r--r-- | tools/eclipse.py | 54 | ||||
| -rw-r--r-- | tools/gcc.py | 14 | ||||
| -rw-r--r-- | tools/keil.py | 3 | ||||
| -rw-r--r-- | tools/menuconfig.py | 42 | ||||
| -rw-r--r-- | tools/rtthread.mk | 17 | ||||
| -rw-r--r-- | tools/utils.py | 2 |
7 files changed, 105 insertions, 38 deletions
diff --git a/tools/building.py b/tools/building.py index 65af794434..2ddeb9669b 100644 --- a/tools/building.py +++ b/tools/building.py @@ -28,6 +28,7 @@ import os import sys import string import utils +import operator from SCons.Script import * from utils import _make_path_relative @@ -675,8 +676,16 @@ def DefineGroup(name, src, depend, **parameters): MergeGroup(g, group) return objs + def PriorityInsertGroup(groups, group): + length = len(groups) + for i in range(0, length): + if operator.gt(groups[i]['name'].lower(), group['name'].lower()): + groups.insert(i, group) + return + groups.append(group) + # add a new group - Projects.append(group) + PriorityInsertGroup(Projects, group) return objs diff --git a/tools/eclipse.py b/tools/eclipse.py index 253db37bea..269d8ce301 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -20,6 +20,10 @@ from utils import xml_indent import xml.etree.ElementTree as etree from xml.etree.ElementTree import SubElement +from building import * + +MODULE_VER_NUM = 5 + source_pattern = ['*.c', '*.cpp', '*.cxx', '*.s', '*.S', '*.asm'] def OSPath(path): @@ -135,7 +139,22 @@ def IsRttEclipsePathFormat(path): else : return False +# all libs added by scons should be ends with five whitespace as a flag +rtt_lib_flag = 5 * " " + + +def ConverToRttEclipseLibFormat(lib): + return str(lib) + str(rtt_lib_flag) + +def IsRttEclipseLibFormat(path): + if path.endswith(rtt_lib_flag): + return True + else: + return False + + + def HandleToolOption(tools, env, project, reset): BSP_ROOT = os.path.abspath(env['BSP_ROOT']) @@ -216,7 +235,7 @@ def HandleToolOption(tools, env, project, reset): with open('rtconfig_preinc.h', mode = 'w+') as f: f.write(file_header) for cppdef in CPPDEFINES: - f.write("#define " + cppdef + '\n') + f.write("#define " + cppdef.replace('=', ' ') + '\n') f.write(file_tail) # change the c.compiler.include.files files = option.findall('listOptionValue') @@ -276,23 +295,31 @@ def HandleToolOption(tools, env, project, reset): else: option.set('value', 'false') # update libs - if linker_libs_option is not None : + if linker_libs_option is not None: option = linker_libs_option # remove old libs for item in option.findall('listOptionValue'): - option.remove(item) + if IsRttEclipseLibFormat(item.get("value")): + option.remove(item) + # add new libs - for lib in env['LIBS']: - SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib}) + if env.has_key('LIBS'): + for lib in env['LIBS']: + formatedLib = ConverToRttEclipseLibFormat(lib) + SubElement(option, 'listOptionValue', { + 'builtIn': 'false', 'value': formatedLib}) + # update lib paths - if linker_paths_option is not None : + if linker_paths_option is not None: option = linker_paths_option # remove old lib paths for item in option.findall('listOptionValue'): - option.remove(item) + if IsRttEclipsePathFormat(item.get('value')): + # clean old configuration + option.remove(item) # add new old lib paths for path in env['LIBPATH']: - SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': path}) + SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': ConverToRttEclipsePathFormat(RelativeProjectPath(env, path).replace('\\', '/'))}) return @@ -334,12 +361,13 @@ def GenExcluding(env, project): rtt_root = os.path.abspath(env['RTT_ROOT']) bsp_root = os.path.abspath(env['BSP_ROOT']) coll_dirs = CollectPaths(project['DIRS']) - all_paths = [OSPath(path) for path in coll_dirs] + all_paths_temp = [OSPath(path) for path in coll_dirs] + all_paths = [] - # remove unused path - for path in all_paths: - if not path.startswith(rtt_root) and not path.startswith(bsp_root): - all_paths.remove(path) + # add used path + for path in all_paths_temp: + if path.startswith(rtt_root) or path.startswith(bsp_root): + all_paths.append(path) if bsp_root.startswith(rtt_root): # bsp folder is in the RT-Thread root folder, such as the RT-Thread source code on GitHub diff --git a/tools/gcc.py b/tools/gcc.py index 2e29c8f34b..8c9685d52b 100644 --- a/tools/gcc.py +++ b/tools/gcc.py @@ -23,7 +23,7 @@ import os import re -import platform +import platform def GetGCCRoot(rtconfig): exec_path = rtconfig.EXEC_PATH @@ -63,7 +63,7 @@ def CheckHeader(rtconfig, filename): fn = os.path.join(root, prefix, 'include', filename) if os.path.isfile(fn): return True - + return False def GetNewLibVersion(rtconfig): @@ -98,18 +98,18 @@ def GCCResult(rtconfig, str): gcc_cmd = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC) - # use temp file to get more information + # use temp file to get more information f = open('__tmp.c', 'w') if f: f.write(str) f.close() - # '-fdirectives-only', + # '-fdirectives-only', if(platform.system() == 'Windows'): child = subprocess.Popen([gcc_cmd, '-E', '-P', '__tmp.c'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) else: child = subprocess.Popen(gcc_cmd + ' -E -P __tmp.c', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - + stdout, stderr = child.communicate() # print(stdout) @@ -148,7 +148,7 @@ def GCCResult(rtconfig, str): if re.findall('pthread_create', line): posix_thread = 1 - + if have_fdset: result += '#define HAVE_FDSET 1\n' @@ -162,7 +162,7 @@ def GCCResult(rtconfig, str): result += '#define HAVE_SIGVAL 1\n' if version: - result += '#define GCC_VERSION "%s"\n' % version + result += '#define GCC_VERSION_STR "%s"\n' % version result += '#define STDC "%s"\n' % stdc diff --git a/tools/keil.py b/tools/keil.py index 7d4913dcf8..ce6f690085 100644 --- a/tools/keil.py +++ b/tools/keil.py @@ -51,6 +51,9 @@ def _get_filetype(fn): if fn.rfind('.lib') != -1: return 4 + if fn.rfind('.o') != -1: + return 3 + # other filetype return 5 diff --git a/tools/menuconfig.py b/tools/menuconfig.py index b49a2e7120..d2ee2eea5b 100644 --- a/tools/menuconfig.py +++ b/tools/menuconfig.py @@ -27,6 +27,8 @@ import os import re import sys import shutil +import hashlib +import operator # make rtconfig.h from .config @@ -97,6 +99,14 @@ def mk_rtconfig(filename): rtconfig.write('#endif\n') rtconfig.close() + +def get_file_md5(file): + MD5 = hashlib.new('md5') + with open(file, 'r') as fp: + MD5.update(fp.read().encode('utf8')) + fp_md5 = MD5.hexdigest() + return fp_md5 + def config(): mk_rtconfig('.config') @@ -219,22 +229,22 @@ def menuconfig(RTT_ROOT): os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages') fn = '.config' - - if os.path.isfile(fn): - mtime = os.path.getmtime(fn) - else: - mtime = -1 + fn_old = '.config.old' kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf') os.system(kconfig_cmd + ' Kconfig') if os.path.isfile(fn): - mtime2 = os.path.getmtime(fn) + if os.path.isfile(fn_old): + diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old)) + else: + diff_eq = False else: - mtime2 = -1 + sys.exit(-1) # make rtconfig.h - if mtime != mtime2: + if diff_eq == False: + shutil.copyfile(fn, fn_old) mk_rtconfig(fn) # guiconfig for windows and linux @@ -249,22 +259,22 @@ def guiconfig(RTT_ROOT): os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages') fn = '.config' - - if os.path.isfile(fn): - mtime = os.path.getmtime(fn) - else: - mtime = -1 + fn_old = '.config.old' sys.argv = ['guiconfig', 'Kconfig']; pyguiconfig._main() if os.path.isfile(fn): - mtime2 = os.path.getmtime(fn) + if os.path.isfile(fn_old): + diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old)) + else: + diff_eq = False else: - mtime2 = -1 + sys.exit(-1) # make rtconfig.h - if mtime != mtime2: + if diff_eq == False: + shutil.copyfile(fn, fn_old) mk_rtconfig(fn) diff --git a/tools/rtthread.mk b/tools/rtthread.mk index fdc96d4156..7cf018cb52 100644 --- a/tools/rtthread.mk +++ b/tools/rtthread.mk @@ -55,6 +55,20 @@ $(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC) @$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@)) endef +define add_s_file +$(eval S_SRC := $(1:$(BSP_ROOT)/%=%)) \ +$(eval S_SRC := $(S_SRC:$(RTT_ROOT)/%=%)) \ +$(eval SOBJ := $(1:%.s=%.o)) \ +$(eval SOBJ := $(SOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ +$(eval SOBJ := $(SOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ +$(eval LOCALS := $(addprefix $(BUILD_DIR)/,$(SOBJ))) \ +$(eval OBJS += $(LOCALS)) \ +$(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC) + @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi + @echo cc $$< + @$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@)) +endef + add_flg = $(eval CFLAGS += $1) \ $(eval AFLAGS += $1) \ $(eval CXXFLAGS += $1) @@ -89,6 +103,9 @@ $(if $(SRCS),$(foreach f,$(SRCS),$(call add_cxx_file,$(f)))) SRCS := $(strip $(filter %.S,$(SRC_FILES))) $(if $(SRCS),$(foreach f,$(SRCS),$(call add_S_file,$(f)))) +SRCS := $(strip $(filter %.s,$(SRC_FILES))) +$(if $(SRCS),$(foreach f,$(SRCS),$(call add_s_file,$(f)))) + CFLAGS += $(CPPPATHS) CXXFLAGS += $(CPPPATHS) AFLAGS += $(CPPPATHS) diff --git a/tools/utils.py b/tools/utils.py index 9459396544..67ce098ccd 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -273,7 +273,7 @@ def VersionCmp(ver1, ver2): def GCCC99Patch(cflags): import building - gcc_version = building.GetDepend('GCC_VERSION') + gcc_version = building.GetDepend('GCC_VERSION_STR') if gcc_version: gcc_version = gcc_version.replace('"', '') if VersionCmp(gcc_version, "4.8.0") == 1: |
