summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMan, Jianting (Meco) <[email protected]>2021-08-17 16:56:10 -0500
committerGitHub <[email protected]>2021-08-17 16:56:10 -0500
commit3e6578916f892e4456d9dff4bbd44590a0cb4bc8 (patch)
treeb98d9fe601ce62e17b37f5b971f0cc9f965fa0e3 /tools
parent37a9231e6219b94f7cde8bdea9251e260c4bed18 (diff)
parent196f340e5d845efd005b57a2089e0642266a79be (diff)
Merge branch 'master' into security
Diffstat (limited to 'tools')
-rw-r--r--tools/auto-ci.py8
-rw-r--r--tools/buildbot.py16
-rw-r--r--tools/building.py42
-rw-r--r--tools/clang-analyze.py6
-rw-r--r--tools/cmake.py153
-rw-r--r--tools/eclipse.py18
-rw-r--r--tools/file_check.py280
-rw-r--r--tools/formatting.py135
-rw-r--r--tools/keil.py10
-rw-r--r--tools/makefile.py8
-rw-r--r--tools/menuconfig.py27
-rw-r--r--tools/mkdist.py24
-rw-r--r--tools/mkromfs.py15
-rw-r--r--tools/rtthread.mk4
-rw-r--r--tools/ses.py4
-rw-r--r--tools/ua.py2
-rw-r--r--tools/vs.py28
-rw-r--r--tools/vs2012.py74
-rw-r--r--tools/win32spawn.py8
19 files changed, 651 insertions, 211 deletions
diff --git a/tools/auto-ci.py b/tools/auto-ci.py
index 67834544d8..bbb384cec2 100644
--- a/tools/auto-ci.py
+++ b/tools/auto-ci.py
@@ -52,7 +52,7 @@ fail = False
BSP_ROOT = '../bsp'
-for bsp,cpu in bsp_to_cpu.iteritems():
+for bsp,cpu in bsp_to_cpu.items():
project_dir = os.path.join(BSP_ROOT, bsp)
if os.getenv('RTT_CPU') == cpu and os.path.isfile(os.path.join(project_dir, 'SConstruct')):
if os.system('scons --directory=' + project_dir) != 0:
@@ -63,10 +63,10 @@ for bsp,cpu in bsp_to_cpu.iteritems():
else:
results['ignore'].append(bsp)
-for result,bsp_list in results.iteritems():
- print "## {0}: {1}\n".format(result, len(bsp_list))
+for result,bsp_list in results.items():
+ print("## {0}: {1}\n".format(result, len(bsp_list)))
for bsp in bsp_list:
- print "* " + bsp
+ print("* " + bsp)
if fail:
sys.exit(1)
diff --git a/tools/buildbot.py b/tools/buildbot.py
index ecc0031195..bcce3449ec 100644
--- a/tools/buildbot.py
+++ b/tools/buildbot.py
@@ -2,9 +2,9 @@ import os
import sys
def usage():
- print '%s all -- build all bsp' % os.path.basename(sys.argv[0])
- print '%s clean -- clean all bsp' % os.path.basename(sys.argv[0])
- print '%s project -- update all prject files' % os.path.basename(sys.argv[0])
+ print('%s all -- build all bsp' % os.path.basename(sys.argv[0]))
+ print('%s clean -- clean all bsp' % os.path.basename(sys.argv[0]))
+ print('%s project -- update all prject files' % os.path.basename(sys.argv[0]))
BSP_ROOT = os.path.join("..", "bsp")
@@ -25,25 +25,25 @@ elif sys.argv[1] == 'project':
project_dir = os.path.join(BSP_ROOT, item)
if os.path.isfile(os.path.join(project_dir, 'template.Uv2')):
- print ('prepare MDK3 project file on ' + project_dir)
+ print('prepare MDK3 project file on ' + project_dir)
command = ' --target=mdk -s'
os.system('scons --directory=' + project_dir + command)
if os.path.isfile(os.path.join(project_dir, 'template.uvproj')):
- print ('prepare MDK4 project file on ' + project_dir)
+ print('prepare MDK4 project file on ' + project_dir)
command = ' --target=mdk4 -s'
os.system('scons --directory=' + project_dir + command)
if os.path.isfile(os.path.join(project_dir, 'template.uvprojx')):
- print ('prepare MDK5 project file on ' + project_dir)
+ print('prepare MDK5 project file on ' + project_dir)
command = ' --target=mdk5 -s'
os.system('scons --directory=' + project_dir + command)
if os.path.isfile(os.path.join(project_dir, 'template.ewp')):
- print ('prepare IAR project file on ' + project_dir)
+ print('prepare IAR project file on ' + project_dir)
command = ' --target=iar -s'
os.system('scons --directory=' + project_dir + command)
@@ -58,5 +58,5 @@ for item in projects:
project_dir = os.path.join(BSP_ROOT, item)
if os.path.isfile(os.path.join(project_dir, 'SConstruct')):
if os.system('scons --directory=' + project_dir + command) != 0:
- print 'build failed!!'
+ print('build failed!!')
break
diff --git a/tools/building.py b/tools/building.py
index 00a9f04107..e078c1626c 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -85,7 +85,7 @@ class Win32Spawn:
try:
os.remove(f)
except Exception as e:
- print ('Error removing file: ' + e)
+ print('Error removing file: ' + e)
return -1
return 0
@@ -106,8 +106,8 @@ class Win32Spawn:
try:
proc = subprocess.Popen(cmdline, env=_e, shell=False)
except Exception as e:
- print ('Error in calling command:' + cmdline.split(' ')[0])
- print ('Exception: ' + os.strerror(e.errno))
+ print('Error in calling command:' + cmdline.split(' ')[0])
+ print('Exception: ' + os.strerror(e.errno))
if (os.strerror(e.errno) == "No such file or directory"):
print ("\nPlease check Toolchains PATH setting.\n")
@@ -208,7 +208,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
AddOption('--target',
dest = 'target',
type = 'string',
- help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse/codelite')
+ help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse/codelite/cmake')
AddOption('--stackanalysis',
dest = 'stackanalysis',
action = 'store_true',
@@ -257,6 +257,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'makefile':('gcc', 'gcc'),
'eclipse':('gcc', 'gcc'),
'ses' : ('gcc', 'gcc'),
+ 'cmake':('gcc', 'gcc'),
+ 'cmake-armclang':('keil', 'armclang'),
'codelite' : ('gcc', 'gcc')}
tgt_name = GetOption('target')
@@ -274,7 +276,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
os.environ['RTT_CC'] = rtconfig.CROSS_TOOL
utils.ReloadModule(rtconfig)
except KeyError:
- print ('Unknow target: '+ tgt_name+'. Avaible targets: ' +', '.join(tgt_dict.keys()))
+ print('Unknow target: '+ tgt_name+'. Avaible targets: ' +', '.join(tgt_dict.keys()))
sys.exit(1)
# auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed
@@ -446,6 +448,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
variant_dir=kernel_vdir + '/components',
duplicate=0,
exports='remove_components'))
+ # include testcases
+ if os.path.isfile(os.path.join(Rtt_Root, 'examples/utest/testcases/SConscript')):
+ objs.extend(SConscript(Rtt_Root + '/examples/utest/testcases/SConscript',
+ variant_dir=kernel_vdir + '/examples/utest/testcases',
+ duplicate=0))
return objs
@@ -662,7 +669,7 @@ def DefineGroup(name, src, depend, **parameters):
# check whether to clean up library
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
if group['src'] != []:
- print ('Remove library:'+ GroupLibFullName(name, Env))
+ print('Remove library:'+ GroupLibFullName(name, Env))
fn = os.path.join(group['path'], GroupLibFullName(name, Env))
if os.path.exists(fn):
os.unlink(fn)
@@ -735,7 +742,7 @@ def BuildLibInstallAction(target, source, env):
if Group['name'] == lib_name:
lib_name = GroupLibFullName(Group['name'], env)
dst_name = os.path.join(Group['path'], lib_name)
- print ('Copy '+lib_name+' => ' +dst_name)
+ print('Copy '+lib_name+' => ' + dst_name)
do_copy_file(lib_name, dst_name)
break
@@ -877,6 +884,10 @@ def GenTargetProject(program = None):
from codelite import TargetCodelite
TargetCodelite(Projects, program)
+ if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
+ from cmake import CMakeProject
+ CMakeProject(Env,Projects)
+
def EndBuilding(target, program = None):
import rtconfig
@@ -915,14 +926,11 @@ def EndBuilding(target, program = None):
project_name = GetOption('project-name')
if not isinstance(project_path, str) or len(project_path) == 0 :
- print("\nwarning : --project-path=your_project_path parameter is required.")
- print("\nstop!")
- exit(0)
-
+ project_path = os.path.join(BSP_ROOT, 'dist_ide_project')
+ print("\nwarning : --project-path not specified, use default path: {0}.".format(project_path))
if not isinstance(project_name, str) or len(project_name) == 0:
- print("\nwarning : --project-name=your_project_name parameter is required.")
- print("\nstop!")
- exit(0)
+ project_name = "dist_ide_project"
+ print("\nwarning : --project-name not specified, use default project name: {0}.".format(project_name))
rtt_ide = {'project_path' : project_path, 'project_name' : project_name}
MkDist(program, BSP_ROOT, Rtt_Root, Env, rtt_ide)
@@ -996,11 +1004,11 @@ def GetVersion():
prepcessor.process_contents(contents)
def_ns = prepcessor.cpp_namespace
- version = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_VERSION']))
- subversion = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_SUBVERSION']))
+ version = int([ch for ch in def_ns['RT_VERSION'] if ch in '0123456789.'])
+ subversion = int([ch for ch in def_ns['RT_SUBVERSION'] if ch in '0123456789.'])
if 'RT_REVISION' in def_ns:
- revision = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_REVISION']))
+ revision = int([ch for ch in def_ns['RT_REVISION'] if ch in '0123456789.'])
return '%d.%d.%d' % (version, subversion, revision)
return '0.%d.%d' % (version, subversion)
diff --git a/tools/clang-analyze.py b/tools/clang-analyze.py
index e73f30ca31..7004ba610b 100644
--- a/tools/clang-analyze.py
+++ b/tools/clang-analyze.py
@@ -53,9 +53,9 @@ def generate(env):
if rtconfig.EXEC_PATH:
if not os.path.exists(rtconfig.EXEC_PATH):
- print
- print 'warning: rtconfig.EXEC_PATH(%s) does not exists.' % rtconfig.EXEC_PATH
- print
+ print()
+ print('warning: rtconfig.EXEC_PATH(%s) does not exists.' % rtconfig.EXEC_PATH)
+ print()
return
env.AppendENVPath('PATH', rtconfig.EXEC_PATH)
diff --git a/tools/cmake.py b/tools/cmake.py
new file mode 100644
index 0000000000..811b6693cb
--- /dev/null
+++ b/tools/cmake.py
@@ -0,0 +1,153 @@
+"""
+Utils for CMake
+Author: https://github.com/klivelinux
+"""
+
+import os
+import sys
+import re
+import utils
+import rtconfig
+
+
+def GenerateCFiles(env,project):
+ """
+ Generate CMakeLists.txt files
+ """
+ info = utils.ProjectInfo(env)
+
+ CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC).replace('\\', "/")
+ if 'CXX' in dir(rtconfig):
+ CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX).replace('\\', "/")
+ else:
+ CXX = ''
+ AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS).replace('\\', "/")
+ AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR).replace('\\', "/")
+ LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK).replace('\\', "/")
+ if rtconfig.PLATFORM == 'gcc':
+ SIZE = os.path.join(rtconfig.EXEC_PATH, rtconfig.SIZE).replace('\\', "/")
+ OBJDUMP = os.path.join(rtconfig.EXEC_PATH, rtconfig.OBJDUMP).replace('\\', "/")
+ OBJCOPY = os.path.join(rtconfig.EXEC_PATH, rtconfig.OBJCPY).replace('\\', "/")
+ elif rtconfig.CROSS_TOOL == 'keil':
+ FROMELF = os.path.join(rtconfig.EXEC_PATH, 'fromelf').replace('\\', "/")
+
+ CFLAGS = rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"")
+ if 'CXXFLAGS' in dir(rtconfig):
+ CXXFLAGS = rtconfig.CXXFLAGS.replace('\\', "/").replace('\"', "\\\"")
+ else:
+ CXXFLAGS = CFLAGS
+ AFLAGS = rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"")
+ LFLAGS = rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")
+
+ if "win32" in sys.platform:
+ CC += ".exe"
+ if CXX != '':
+ CXX += ".exe"
+ AS += ".exe"
+ AR += ".exe"
+ LINK += ".exe"
+ if rtconfig.PLATFORM == 'gcc':
+ SIZE += ".exe"
+ OBJDUMP += ".exe"
+ OBJCOPY += ".exe"
+ elif rtconfig.CROSS_TOOL == 'keil':
+ FROMELF += ".exe"
+
+ if not os.path.exists(CC) or not os.path.exists(AS) or not os.path.exists(AR) or not os.path.exists(LINK):
+ print("'Cannot found toolchain directory, please check RTT_CC and RTT_EXEC_PATH'")
+ sys.exit(-1)
+
+ cm_file = open('CMakeLists.txt', 'w')
+ if cm_file:
+ cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n")
+
+ cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n")
+ cm_file.write("SET(CMAKE_SYSTEM_PROCESSOR " + rtconfig.CPU +")\n")
+ cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n")
+
+ cm_file.write("SET(CMAKE_C_COMPILER \""+ CC + "\")\n")
+ cm_file.write("SET(CMAKE_ASM_COMPILER \""+ AS + "\")\n")
+ cm_file.write("SET(CMAKE_C_FLAGS \""+ CFLAGS + "\")\n")
+ cm_file.write("SET(CMAKE_ASM_FLAGS \""+ AFLAGS + "\")\n")
+ cm_file.write("SET(CMAKE_C_COMPILER_WORKS TRUE)\n\n")
+
+ if CXX != '':
+ cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n")
+ cm_file.write("SET(CMAKE_CXX_FLAGS \""+ CXXFLAGS + "\")\n")
+ cm_file.write("SET(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n")
+
+ if rtconfig.PLATFORM == 'gcc':
+ cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n")
+ cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n")
+ elif rtconfig.CROSS_TOOL == 'keil':
+ cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\n\n")
+
+ LINKER_FLAGS = ''
+ LINKER_LIBS = ''
+ if rtconfig.PLATFORM == 'gcc':
+ LINKER_FLAGS += '-T'
+ elif rtconfig.CROSS_TOOL == 'keil':
+ LINKER_FLAGS += '--scatter'
+ for group in project:
+ if 'LIBPATH' in group.keys():
+ for f in group['LIBPATH']:
+ LINKER_LIBS += ' --userlibpath ' + f.replace("\\", "/")
+ for group in project:
+ if 'LIBS' in group.keys():
+ for f in group['LIBS']:
+ LINKER_LIBS += ' ' + f.replace("\\", "/") + '.lib'
+ cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub(LINKER_FLAGS + '(\s*)', LINKER_FLAGS + ' ${CMAKE_SOURCE_DIR}/', LFLAGS) + LINKER_LIBS + "\")\n\n")
+
+ if CXX != '':
+ cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n")
+ cm_file.write("PROJECT(rtthread C CXX ASM)\n")
+ else:
+ cm_file.write("PROJECT(rtthread C ASM)\n")
+
+ cm_file.write("INCLUDE_DIRECTORIES(\n")
+ for i in info['CPPPATH']:
+ cm_file.write( "\t" + i.replace("\\", "/") + "\n")
+ cm_file.write(")\n\n")
+
+ cm_file.write("ADD_DEFINITIONS(\n")
+ for i in info['CPPDEFINES']:
+ cm_file.write("\t-D" + i + "\n")
+ cm_file.write(")\n\n")
+
+ cm_file.write("SET(PROJECT_SOURCES\n")
+ for group in project:
+ for f in group['src']:
+ cm_file.write( "\t" + os.path.normpath(f.rfile().abspath).replace("\\", "/") + "\n" )
+ cm_file.write(")\n\n")
+
+ if rtconfig.PLATFORM == 'gcc':
+ cm_file.write("LINK_DIRECTORIES(\n")
+ for group in project:
+ if 'LIBPATH' in group.keys():
+ for f in group['LIBPATH']:
+ cm_file.write( "\t"+ f.replace("\\", "/") + "\n" )
+ cm_file.write(")\n\n")
+
+ cm_file.write("LINK_LIBRARIES(\n")
+ for group in project:
+ if 'LIBS' in group.keys():
+ for f in group['LIBS']:
+ cm_file.write( "\t"+ "{}\n".format(f.replace("\\", "/")))
+ cm_file.write(")\n\n")
+
+ cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})\n")
+ cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD \nCOMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)")
+ elif rtconfig.CROSS_TOOL == 'keil':
+ cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES})\n")
+ cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD \nCOMMAND ${CMAKE_FROMELF} --bin ${CMAKE_PROJECT_NAME}.elf --output ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_FROMELF} -z ${CMAKE_PROJECT_NAME}.elf)")
+
+ cm_file.close()
+
+ return
+
+def CMakeProject(env,project):
+ print('Update setting files for CMakeLists.txt...')
+ GenerateCFiles(env,project)
+ print('Done!')
+
+ return
diff --git a/tools/eclipse.py b/tools/eclipse.py
index 4f3cda92b8..6498c1c9f6 100644
--- a/tools/eclipse.py
+++ b/tools/eclipse.py
@@ -188,7 +188,8 @@ def HandleToolOption(tools, env, project, reset):
options = tool.findall('option')
# find all compile options
for option in options:
- if option.get('id').find('compiler.include.paths') != -1 or option.get('id').find('compiler.option.includepaths') != -1:
+ option_id = option.get('id')
+ if ('compiler.include.paths' in option_id) or ('compiler.option.includepaths' in option_id) or ('compiler.tasking.include' in option_id):
compile_include_paths_options += [option]
elif option.get('id').find('compiler.include.files') != -1 or option.get('id').find('compiler.option.includefiles') != -1 :
compile_include_files_options += [option]
@@ -211,7 +212,7 @@ def HandleToolOption(tools, env, project, reset):
linker_nostart_option = option
elif option.get('id').find('linker.libs') != -1:
linker_libs_option = option
- elif option.get('id').find('linker.paths') != -1 and env.has_key('LIBPATH'):
+ elif option.get('id').find('linker.paths') != -1 and 'LIBPATH' in env:
linker_paths_option = option
elif option.get('id').find('linker.usenewlibnano') != -1:
linker_newlib_nano_option = option
@@ -316,7 +317,7 @@ def HandleToolOption(tools, env, project, reset):
option.remove(item)
# add new libs
- if env.has_key('LIBS'):
+ if 'LIBS' in env:
for lib in env['LIBS']:
formatedLib = ConverToRttEclipseLibFormat(lib)
SubElement(option, 'listOptionValue', {
@@ -448,8 +449,10 @@ def RelativeProjectPath(env, path):
def HandleExcludingOption(entry, sourceEntries, excluding):
old_excluding = []
if entry != None:
- old_excluding = entry.get('excluding').split('|')
- sourceEntries.remove(entry)
+ exclud = entry.get('excluding')
+ if exclud != None:
+ old_excluding = entry.get('excluding').split('|')
+ sourceEntries.remove(entry)
value = ''
for item in old_excluding:
@@ -484,8 +487,9 @@ def UpdateCproject(env, project, excluding, reset, prj_name):
HandleToolOption(tools, env, project, reset)
sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries')
- entry = sourceEntries.find('entry')
- HandleExcludingOption(entry, sourceEntries, excluding)
+ if sourceEntries != None:
+ entry = sourceEntries.find('entry')
+ HandleExcludingOption(entry, sourceEntries, excluding)
# update refreshScope
if prj_name:
prj_name = '/' + prj_name
diff --git a/tools/file_check.py b/tools/file_check.py
new file mode 100644
index 0000000000..63767782b5
--- /dev/null
+++ b/tools/file_check.py
@@ -0,0 +1,280 @@
+#
+# Copyright (c) 2006-2021, RT-Thread Development Team
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Change Logs:
+# Date Author Notes
+# 2021-04-01 LiuKang the first version
+#
+
+import os
+import re
+import sys
+import click
+import yaml
+import chardet
+import logging
+import datetime
+
+
+def init_logger():
+ log_format = "[%(filename)s %(lineno)d %(levelname)s] %(message)s "
+ date_format = '%Y-%m-%d %H:%M:%S %a '
+ logging.basicConfig(level=logging.INFO,
+ format=log_format,
+ datefmt=date_format,
+ )
+
+
+class CheckOut:
+ def __init__(self, rtt_repo, rtt_branch):
+ self.root = os.getcwd()
+ self.rtt_repo = rtt_repo
+ self.rtt_branch = rtt_branch
+
+ def __exclude_file(self, file_path):
+ dir_number = file_path.split('/')
+ ignore_path = file_path
+
+ # gets the file path depth.
+ for i in dir_number:
+ # current directory.
+ dir_name = os.path.dirname(ignore_path)
+ ignore_path = dir_name
+ # judge the ignore file exists in the current directory.
+ ignore_file_path = os.path.join(dir_name, ".ignore_format.yml")
+ if not os.path.exists(ignore_file_path):
+ continue
+ try:
+ with open(ignore_file_path) as f:
+ ignore_config = yaml.safe_load(f.read())
+ file_ignore = ignore_config.get("file_path", [])
+ dir_ignore = ignore_config.get("dir_path", [])
+ except Exception as e:
+ logging.error(e)
+ continue
+ logging.debug("ignore file path: {}".format(ignore_file_path))
+ logging.debug("file_ignore: {}".format(file_ignore))
+ logging.debug("dir_ignore: {}".format(dir_ignore))
+ try:
+ # judge file_path in the ignore file.
+ for file in file_ignore:
+ if file is not None:
+ file_real_path = os.path.join(dir_name, file)
+ if file_real_path == file_path:
+ logging.info("ignore file path: {}".format(file_real_path))
+ return 0
+
+ file_dir_path = os.path.dirname(file_path)
+ for _dir in dir_ignore:
+ if _dir is not None:
+ dir_real_path = os.path.join(dir_name, _dir)
+ if file_dir_path.startswith(dir_real_path):
+ logging.info("ignore dir path: {}".format(dir_real_path))
+ return 0
+ except Exception as e:
+ logging.error(e)
+ continue
+
+ return 1
+
+ def get_new_file(self):
+ file_list = list()
+ try:
+ os.system('git remote add rtt_repo {}'.format(self.rtt_repo))
+ os.system('git fetch rtt_repo')
+ os.system('git merge rtt_repo/{}'.format(self.rtt_branch))
+ os.system('git reset rtt_repo/{} --soft'.format(self.rtt_branch))
+ os.system('git status > git.txt')
+ except Exception as e:
+ logging.error(e)
+ return None
+ try:
+ with open('git.txt', 'r') as f:
+ file_lines = f.readlines()
+ except Exception as e:
+ logging.error(e)
+ return None
+ file_path = ''
+ for line in file_lines:
+ if 'new file' in line:
+ file_path = line.split('new file:')[1].strip()
+ logging.info('new file -> {}'.format(file_path))
+ elif 'deleted' in line:
+ logging.info('deleted file -> {}'.format(line.split('deleted:')[1].strip()))
+ elif 'modified' in line:
+ file_path = line.split('modified:')[1].strip()
+ logging.info('modified file -> {}'.format(file_path))
+ else:
+ continue
+
+ result = self.__exclude_file(file_path)
+ if result != 0:
+ file_list.append(file_path)
+
+ return file_list
+
+
+class FormatCheck:
+ def __init__(self, file_list):
+ self.file_list = file_list
+
+ def __check_file(self, file_lines, file_path):
+ line_num = 1
+ check_result = True
+ for line in file_lines:
+ # check line start
+ line_start = line.replace(' ', '')
+ # find tab
+ if line_start.startswith('\t'):
+ logging.error("{} line[{}]: please use space replace tab at the start of this line.".format(file_path, line_num))
+ check_result = False
+ # check line end
+ lin_end = line.split('\n')[0]
+ if lin_end.endswith(' ') or lin_end.endswith('\t'):
+ logging.error("{} line[{}]: please delete extra space at the end of this line.".format(file_path, line_num))
+ check_result = False
+ line_num += 1
+
+ return check_result
+
+ def check(self):
+ logging.info("Start to check files format.")
+ if len(self.file_list) == 0:
+ logging.warning("There are no files to check format.")
+ return True
+ encoding_check_result = True
+ format_check_fail_files = 0
+ for file_path in self.file_list:
+ code = ''
+ if file_path.endswith(".c") or file_path.endswith(".h"):
+ try:
+ with open(file_path, 'rb') as f:
+ file = f.read()
+ # get file encoding
+ code = chardet.detect(file)['encoding']
+ except Exception as e:
+ logging.error(e)
+ else:
+ continue
+
+ if code != 'utf-8' and code != 'ascii':
+ logging.error("[{0}]: encoding not utf-8, please format it.".format(file_path))
+ encoding_check_result = False
+ else:
+ logging.info('[{0}]: encoding check success.'.format(file_path))
+
+ with open(file_path, 'r', encoding = "utf-8") as f:
+ file_lines = f.readlines()
+ if not self.__check_file(file_lines, file_path):
+ format_check_fail_files += 1
+
+ if (not encoding_check_result) or (format_check_fail_files != 0):
+ logging.error("files format check fail.")
+ return False
+
+ logging.info("files format check success.")
+
+ return True
+
+
+class LicenseCheck:
+ def __init__(self, file_list):
+ self.file_list = file_list
+
+ def check(self):
+ current_year = datetime.date.today().year
+ logging.info("current year: {}".format(current_year))
+ if len(self.file_list) == 0:
+ logging.warning("There are no files to check license.")
+ return 0
+ logging.info("Start to check files license.")
+ check_result = True
+ for file_path in self.file_list:
+ if file_path.endswith(".c") or file_path.endswith(".h"):
+ try:
+ with open(file_path, 'r') as f:
+ file = f.readlines()
+ except Exception as e:
+ logging.error(e)
+ else:
+ continue
+
+ if 'Copyright' in file[1] and 'SPDX-License-Identifier: Apache-2.0' in file[3]:
+ try:
+ license_year = re.search(r'2006-\d{4}', file[1]).group()
+ true_year = '2006-{}'.format(current_year)
+ if license_year != true_year:
+ logging.warning("[{0}]: license year: {} is not true: {}, please update.".format(file_path,
+ license_year,
+ true_year))
+
+ else:
+ logging.info("[{0}]: license check success.".format(file_path))
+ except Exception as e:
+ logging.error(e)
+
+ else:
+ logging.error("[{0}]: license check fail.".format(file_path))
+ check_result = False
+
+ return check_result
+
+
+def cli(ctx):
+ pass
+
+
+ '--license',
+ "check_license",
+ required=False,
+ type=click.BOOL,
+ flag_value=True,
+ help="Enable File license check.",
+)
+ 'repo',
+ nargs=1,
+ type=click.STRING,
+ default='https://github.com/RT-Thread/rt-thread',
+)
+ 'branch',
+ nargs=1,
+ type=click.STRING,
+ default='master',
+)
+def check(check_license, repo, branch):
+ """
+ check files license and format.
+ """
+ init_logger()
+ # get modified files list
+ checkout = CheckOut(repo, branch)
+ file_list = checkout.get_new_file()
+ if file_list is None:
+ logging.error("checkout files fail")
+ sys.exit(1)
+
+ # check modified files format
+ format_check = FormatCheck(file_list)
+ format_check_result = format_check.check()
+ license_check_result = True
+ if check_license:
+ license_check = LicenseCheck(file_list)
+ license_check_result = license_check.check()
+
+ if not format_check_result or not license_check_result:
+ logging.error("file format check or license check fail.")
+ sys.exit(1)
+ logging.info("check success.")
+ sys.exit(0)
+
+
+if __name__ == '__main__':
+ cli()
diff --git a/tools/formatting.py b/tools/formatting.py
deleted file mode 100644
index 0b63e031fa..0000000000
--- a/tools/formatting.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#
-# File : formatting.py
-# This file is part of RT-Thread RTOS
-# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Change Logs:
-# Date Author Notes
-# 2021-03-02 Meco Man The first version
-# 2021-03-04 Meco Man 增加统一转换成UTF-8编码格式功能
-
-
-#本文件会自动对指定路径下的所有文件包括子文件夹的文件(仅针对.c.h)进行扫描
-# 1)将源文件编码统一为UTF-8;
-# 2)将TAB键替换为空格;
-# 3)将每行末尾多余的空格删除,并统一换行符为'\n';
-#使用时只需要双击本文件,输入要扫描的文件夹路径即可
-#不能保证100%全部成功转换为UTF-8,有一些编码特殊或识别不准确会在终端打印信息,需人工转换
-
-#欢迎对本文件的功能继续做出补充,欢迎提交PR
-
-import os
-import chardet
-
-#用空格代替TAB键
-#这里并不是简单的将TAB替换成4个空格
-#空格个数到底是多少需要计算,因为TAB制表本身有自动对齐的功能
-def tab2spaces(line):
- list_str = list(line) #字符串打散成列表,放边操作
- i = list_str.count('\t')
-
- while i > 0:
- ptr = list_str.index('\t')
- del list_str[ptr]
- space_need_to_insert = 4 - (ptr%4)
- j = 0
- while j < space_need_to_insert:
- list_str.insert(ptr,' ')
- j = j+1
-
- i = i-1
-
- line = ''.join(list_str) #列表恢复成字符串
- return line
-
-#删除每行末尾多余的空格 统一使用\n作为结尾
-def formattail(line):
- line = line.rstrip()
- line = line + '\n'
- return line
-
-#对单个文件进行格式整理
-def format_codes(filename):
- try:
- file=open(filename,'r',encoding = 'utf-8')
- file_temp=open('temp','w',encoding = 'utf-8')
- for line in file:
- line = tab2spaces(line)
- line = formattail(line)
- file_temp.write(line)
- file_temp.close()
- file.close()
- os.remove(filename)
- os.rename('temp',filename)
-
-def get_encode_info(file):
- with open(file, 'rb') as f:
- code = chardet.detect(f.read())['encoding']
- #charde库有一定几率对当前文件的编码识别不准确
- if code == 'EUC-JP': #容易将含着少量中文的英文字符文档识别为日语编码格式
- code = 'GB2312'
- elif code == 'ISO-8859-1': #部分文件GB2312码会被识别成ISO-8859-1
- code = 'GB2312'
-
- if not (code == 'ascii' or code == 'utf-8' or code == 'GB2312' #编码识别正确
- or code == 'Windows-1252'): # Windows-1252 是由于意法半导体是法国企业's的'是法语的'导致的
- if code != None:
- print('未处理,需人工确认:'+code+':'+file) #需要人工确认
- code = None
-
- return code
-
-#将单个文件转为UTF-8编码
-def conver_to_utf_8 (path):
- try:
- info = get_encode_info(path)
- if info == None:
- return 0 #0 失败
-
- file=open(path,'rb+')
- data = file.read()
- string = data.decode(info)
- utf = string.encode('utf-8')
- file.seek(0)
- file.write(utf)
- file.close()
- return 1 #1成功
- except UnicodeDecodeError:
- print("UnicodeDecodeError未处理,需人工确认"+path)
- return 0
- except UnicodeEncodeError:
- print("UnicodeEncodeError未处理,需人工确认"+path)
- return 0
-
-# 递归扫描目录下的所有文件
-def traversalallfile(path):
- filelist=os.listdir(path)
- for file in filelist:
- filepath=os.path.join(path,file)
- if os.path.isdir(filepath):
- traversalallfile(filepath)
- elif os.path.isfile(filepath):
- if filepath.endswith(".c") == True or filepath.endswith(".h") == True: #只处理.c和.h文件
- if conver_to_utf_8(filepath) == 1: #先把这个文件转为UTF-8编码,1成功
- format_codes(filepath) #再对这个文件进行格式整理
-
-def formatfiles():
- workpath = input('enter work path: ')
- traversalallfile(workpath)
-
-if __name__ == '__main__':
- formatfiles()
diff --git a/tools/keil.py b/tools/keil.py
index ce6f690085..b3643fbe74 100644
--- a/tools/keil.py
+++ b/tools/keil.py
@@ -122,12 +122,18 @@ def MDK4AddLibToGroup(ProjectFiles, group, name, filename, project_path):
if ProjectFiles.count(obj_name):
name = basename + '_' + name
ProjectFiles.append(obj_name)
- file_name.text = name.decode(fs_encoding)
+ try:
+ file_name.text = name.decode(fs_encoding)
+ except:
+ file_name.text = name
file_type = SubElement(file, 'FileType')
file_type.text = '%d' % _get_filetype(name)
file_path = SubElement(file, 'FilePath')
- file_path.text = path.decode(fs_encoding)
+ try:
+ file_path.text = path.decode(fs_encoding)
+ except:
+ file_path.text = path
return group
diff --git a/tools/makefile.py b/tools/makefile.py
index 655e294575..97001892c9 100644
--- a/tools/makefile.py
+++ b/tools/makefile.py
@@ -51,6 +51,14 @@ def TargetMakefile(env):
if 'CXXFLAGS' in dir(rtconfig):
make.write('CXXFLAGS :=%s' % (rtconfig.CXXFLAGS))
make.write('\n')
+ if env.has_key('LIBS'):
+ make.write('EXTERN_LIB := ')
+ for tlib in env['LIBS']:
+ make.write('-l%s ' % (tlib))
+ if env.has_key('LIBPATH'):
+ for tlibpath in env['LIBPATH']:
+ make.write('-L%s ' % (tlibpath))
+ make.write('\n')
make.write('\n')
diff --git a/tools/menuconfig.py b/tools/menuconfig.py
index c0a33718de..853e4fe7f8 100644
--- a/tools/menuconfig.py
+++ b/tools/menuconfig.py
@@ -217,8 +217,27 @@ def touch_env():
if os.path.exists(os.path.join(env_dir, 'tools', 'scripts')):
os.environ["PATH"] = os.path.join(env_dir, 'tools', 'scripts') + ';' + os.environ["PATH"]
+# Exclude utestcases
+def exclude_utestcases(RTT_ROOT):
+ if os.path.isfile(os.path.join(RTT_ROOT, 'examples/utest/testcases/Kconfig')):
+ return
+
+ if not os.path.isfile(os.path.join(RTT_ROOT, 'Kconfig')):
+ return
+
+ with open(os.path.join(RTT_ROOT, 'Kconfig'), 'r') as f:
+ data = f.readlines()
+ with open(os.path.join(RTT_ROOT, 'Kconfig'), 'w') as f:
+ for line in data:
+ if line.find('examples/utest/testcases/Kconfig') == -1:
+ f.write(line)
+
# menuconfig for Linux
def menuconfig(RTT_ROOT):
+
+ # Exclude utestcases
+ exclude_utestcases(RTT_ROOT)
+
kconfig_dir = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends')
os.system('scons -C ' + kconfig_dir)
@@ -250,6 +269,9 @@ def menuconfig(RTT_ROOT):
def guiconfig(RTT_ROOT):
import pyguiconfig
+ # Exclude utestcases
+ exclude_utestcases(RTT_ROOT)
+
if sys.platform != 'win32':
touch_env()
@@ -260,7 +282,7 @@ def guiconfig(RTT_ROOT):
fn = '.config'
fn_old = '.config.old'
- sys.argv = ['guiconfig', 'Kconfig'];
+ sys.argv = ['guiconfig', 'Kconfig']
pyguiconfig._main()
if os.path.isfile(fn):
@@ -281,6 +303,9 @@ def guiconfig(RTT_ROOT):
def guiconfig_silent(RTT_ROOT):
import defconfig
+ # Exclude utestcases
+ exclude_utestcases(RTT_ROOT)
+
if sys.platform != 'win32':
touch_env()
diff --git a/tools/mkdist.py b/tools/mkdist.py
index a1dafd25cb..e2c2b8da50 100644
--- a/tools/mkdist.py
+++ b/tools/mkdist.py
@@ -105,6 +105,18 @@ def bsp_update_sconstruct(dist_dir):
f.write('if not os.getenv("RTT_ROOT"): \n RTT_ROOT="rt-thread"\n\n')
f.write(line)
+def bsp_update_kconfig_testcases(dist_dir):
+ # delete testcases in rt-thread/Kconfig
+ if not os.path.isfile(os.path.join(dist_dir, 'rt-thread/Kconfig')):
+ return
+
+ with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'r') as f:
+ data = f.readlines()
+ with open(os.path.join(dist_dir, 'rt-thread/Kconfig'), 'w') as f:
+ for line in data:
+ if line.find('examples/utest/testcases/Kconfig') == -1:
+ f.write(line)
+
def bsp_update_kconfig(dist_dir):
# change RTT_ROOT in Kconfig
if not os.path.isfile(os.path.join(dist_dir, 'Kconfig')):
@@ -164,7 +176,8 @@ def bs_update_ide_project(bsp_root, rtt_root, rttide = None):
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
- 'cdk':('gcc', 'gcc')}
+ 'cdk':('gcc', 'gcc'),
+ 'eclipse':('eclipse', 'gcc')}
else:
item = 'eclipse --project-name=' + rttide['project_name']
tgt_dict = {item:('gcc', 'gcc')}
@@ -218,7 +231,7 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
if 'dist_handle' in Env:
print("=> start dist handle")
dist_handle = Env['dist_handle']
- dist_handle(BSP_ROOT)
+ dist_handle(BSP_ROOT, dist_dir)
# get all source files from program
for item in program:
@@ -307,11 +320,14 @@ def MkDist_Strip(program, BSP_ROOT, RTT_ROOT, Env):
do_copy_file(os.path.join(RTT_ROOT, 'libcpu', 'Kconfig'), os.path.join(target_path, 'libcpu', 'Kconfig'))
do_copy_file(os.path.join(RTT_ROOT, 'libcpu', 'SConscript'), os.path.join(target_path, 'libcpu', 'SConscript'))
+ print('Update configuration files...')
# change RTT_ROOT in SConstruct
bsp_update_sconstruct(dist_dir)
# change RTT_ROOT in Kconfig
bsp_update_kconfig(dist_dir)
bsp_update_kconfig_library(dist_dir)
+ # delete testcases in Kconfig
+ bsp_update_kconfig_testcases(dist_dir)
# update all project files
bs_update_ide_project(dist_dir, target_path)
@@ -374,12 +390,14 @@ def MkDist(program, BSP_ROOT, RTT_ROOT, Env, rttide = None):
do_copy_file(os.path.join(RTT_ROOT, 'README.md'), os.path.join(target_path, 'README.md'))
do_copy_file(os.path.join(RTT_ROOT, 'README_zh.md'), os.path.join(target_path, 'README_zh.md'))
+ print('Update configuration files...')
# change RTT_ROOT in SConstruct
bsp_update_sconstruct(dist_dir)
# change RTT_ROOT in Kconfig
bsp_update_kconfig(dist_dir)
bsp_update_kconfig_library(dist_dir)
-
+ # delete testcases in Kconfig
+ bsp_update_kconfig_testcases(dist_dir)
# update all project files
if rttide == None:
bs_update_ide_project(dist_dir, target_path)
diff --git a/tools/mkromfs.py b/tools/mkromfs.py
index 5371106987..9f4f24d0d6 100644
--- a/tools/mkromfs.py
+++ b/tools/mkromfs.py
@@ -5,7 +5,7 @@ import os
import struct
from collections import namedtuple
-import StringIO
+import io
import argparse
parser = argparse.ArgumentParser()
@@ -43,8 +43,10 @@ class File(object):
if self.entry_size == 0:
return ''
-
- return head + ','.join(('0x%02x' % ord(i) for i in self._data)) + tail
+ if len(self._data) > 0 and type(self._data[0]) == int:
+ return head + ','.join(('0x%02x' % i for i in self._data)) + tail
+ else:
+ return head + ','.join(('0x%02x' % ord(i) for i in self._data)) + tail
@property
def entry_size(self):
@@ -85,7 +87,7 @@ class Folder(object):
# TODO: take care of the unicode names
for ent in os.listdir(u'.'):
if os.path.isdir(ent):
- cwd = os.getcwdu()
+ cwd = os.getcwd()
d = Folder(ent)
# depth-first
os.chdir(os.path.join(cwd, ent))
@@ -104,7 +106,8 @@ class Folder(object):
return 1
else:
return -1
- self._children.sort(cmp=_sort)
+ from functools import cmp_to_key
+ self._children.sort(key=cmp_to_key(_sort))
# sort recursively
for c in self._children:
@@ -255,7 +258,7 @@ if __name__ == '__main__':
if args.binary:
data = get_bin_data(tree, int(args.addr, 16))
else:
- data = get_c_data(tree)
+ data = get_c_data(tree).encode()
output = args.output
if not output:
diff --git a/tools/rtthread.mk b/tools/rtthread.mk
index 7cf018cb52..4bb3e2754d 100644
--- a/tools/rtthread.mk
+++ b/tools/rtthread.mk
@@ -122,10 +122,10 @@ $(TARGET): $(OBJS)
@echo ar $(TARGET)
@$(CROSS_COMPILE)ar -rv $@ $(OBJS)
else
-$(TARGET): $(OBJS) $(EXTERN_LIB)
+$(TARGET): $(OBJS)
@echo ------------------------------------------------
@echo link $(TARGET)
- @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB) -lc -lm
+ @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB)
@echo ------------------------------------------------
@$(CROSS_COMPILE)objcopy -O binary $@ rtthread.bin
@$(CROSS_COMPILE)size $@
diff --git a/tools/ses.py b/tools/ses.py
index dcd9d34442..cc513f0baa 100644
--- a/tools/ses.py
+++ b/tools/ses.py
@@ -59,14 +59,14 @@ def SESProject(env) :
group_tree = SDKAddGroup(project_node, group['name'], group['src'], project_path)
# get each group's cc flags
- if group.has_key('CCFLAGS') and group['CCFLAGS']:
+ if 'CCFLAGS' in group and group['CCFLAGS']:
if CCFLAGS:
CCFLAGS += ' ' + group['CCFLAGS']
else:
CCFLAGS += group['CCFLAGS']
# get each group's link flags
- if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
+ if 'LINKFLAGS' in group and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
diff --git a/tools/ua.py b/tools/ua.py
index 0505f3596c..08b0ef8fad 100644
--- a/tools/ua.py
+++ b/tools/ua.py
@@ -45,7 +45,7 @@ def PrepareUA(project, RTT_ROOT, BSP_ROOT):
# ua.write('import sys\n')
ua.write('\n')
- print RTT_ROOT
+ print(RTT_ROOT)
CPPPATH = []
CPPDEFINES = []
diff --git a/tools/vs.py b/tools/vs.py
index f51862b9d9..8025828b64 100644
--- a/tools/vs.py
+++ b/tools/vs.py
@@ -45,9 +45,12 @@ def VS_AddGroup(ProjectFiles, parent, name, files, libs, project_path):
path = _make_path_relative(project_path, path)
path = os.path.join(path, name)
-
+ try:
+ path = path.decode(fs_encoding)
+ except:
+ path = path
File = SubElement(Filter, 'File')
- File.set('RelativePath', path.decode(fs_encoding))
+ File.set('RelativePath', path)
for lib in libs:
name = os.path.basename(lib)
@@ -57,7 +60,11 @@ def VS_AddGroup(ProjectFiles, parent, name, files, libs, project_path):
path = os.path.join(path, name)
File = SubElement(Filter, 'File')
- File.set('RelativePath', path.decode(fs_encoding))
+ try:
+ path = path.decode(fs_encoding)
+ except:
+ path = path
+ File.set('RelativePath', path)
def VS_AddHeadFilesGroup(program, elem, project_path):
utils.source_ext = []
@@ -70,7 +77,11 @@ def VS_AddHeadFilesGroup(program, elem, project_path):
for f in utils.source_list:
path = _make_path_relative(project_path, f)
File = SubElement(elem, 'File')
- File.set('RelativePath', path.decode(fs_encoding))
+ try:
+ path = path.decode(fs_encoding)
+ except:
+ path = path
+ File.set('RelativePath', path)
def VSProject(target, script, program):
project_path = os.path.dirname(os.path.abspath(target))
@@ -158,12 +169,17 @@ def VSProject(target, script, program):
for path in lib_path:
inc = _make_path_relative(project_path, os.path.normpath(path))
paths.add(inc) #.replace('\\', '/')
-
+
paths = [i for i in paths]
paths.sort()
lib_paths = ';'.join(paths)
elem.set('AdditionalLibraryDirectories', lib_paths)
xml_indent(root)
- out.write(etree.tostring(root, encoding='utf-8'))
+ text = etree.tostring(root, encoding='utf-8')
+ try:
+ text = text.decode(encoding="utf-8")
+ except:
+ text = text
+ out.write(text)
out.close()
diff --git a/tools/vs2012.py b/tools/vs2012.py
index 0c6b9d83d0..c9b0c76dc7 100644
--- a/tools/vs2012.py
+++ b/tools/vs2012.py
@@ -44,7 +44,12 @@ fs_encoding = sys.getfilesystemencoding()
filter_project = etree.Element('Project', attrib={'ToolsVersion':'4.0'})
def get_uuid():
id = uuid.uuid1() # UUID('3e5526c0-2841-11e3-a376-20cf3048bcb3')
- idstr = id.get_urn()[9:] #'urn:uuid:3e5526c0-2841-11e3-a376-20cf3048bcb3'[9:]
+ if sys.version > '3':
+ idstr = id.urn[9:] #'urn:uuid:3e5526c0-2841-11e3-a376-20cf3048bcb3'[9:]
+ else:
+ # python3 is no decode function
+ idstr = id.get_urn()[9:] #'urn:uuid:3e5526c0-2841-11e3-a376-20cf3048bcb3'[9:]
+
return '{'+idstr+'}'
def VS2012_AddGroup(parent, group_name, files, project_path):
@@ -57,7 +62,12 @@ def VS2012_AddGroup(parent, group_name, files, project_path):
path = os.path.join(path, name)
ClCompile = SubElement(parent, 'ClCompile')
- ClCompile.set('Include', path.decode(fs_encoding))
+
+ if sys.version > '3':
+ ClCompile.set('Include', path)
+ else:
+ # python3 is no decode function
+ ClCompile.set('Include', path.decode(fs_encoding))
Filter = SubElement(ClCompile, 'Filter')
Filter.text='Source Files\\'+group_name
@@ -119,7 +129,13 @@ def VS_add_ItemGroup(parent, file_type, files, project_path):
path = os.path.join(path, name)
File = SubElement(ItemGroup, item_tag)
- File.set('Include', path.decode(fs_encoding))
+
+ if sys.version > '3':
+ File.set('Include', path)
+ else:
+ # python3 is no decode function
+ File.set('Include', path.decode(fs_encoding))
+
if file_type == 'C' :
ObjName = SubElement(File, 'ObjectFileName')
ObjName.text = ''.join('$(IntDir)'+objpath+'\\')
@@ -137,11 +153,22 @@ def VS_add_HeadFiles(program, elem, project_path):
for f in utils.source_list:
path = _make_path_relative(project_path, f)
File = SubElement(ItemGroup, 'ClInclude')
- File.set('Include', path.decode(fs_encoding))
+
+ if sys.version > '3':
+ File.set('Include', path)
+ else:
+ # python3 is no decode function
+ File.set('Include', path.decode(fs_encoding))
# add project.vcxproj.filter
ClInclude = SubElement(filter_h_ItemGroup, 'ClInclude')
- ClInclude.set('Include', path.decode(fs_encoding))
+
+ if sys.version > '3':
+ ClInclude.set('Include', path)
+ else:
+ # python3 is no decode function
+ ClInclude.set('Include', path.decode(fs_encoding))
+
Filter = SubElement(ClInclude, 'Filter')
Filter.text='Header Files'
@@ -151,12 +178,12 @@ def VS2012Project(target, script, program):
tree = etree.parse('template_vs2012.vcxproj')
root = tree.getroot()
elem = root
-
- out = file(target, 'wb')
+
+ out = open(target, 'w')
out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
-
+
ProjectFiles = []
-
+
# add "*.c or *.h" files
VS2012_CreateFilter(script, project_path)
@@ -187,7 +214,16 @@ def VS2012Project(target, script, program):
# write cppdefinitons flags
if 'CPPDEFINES' in building.Env:
for elem in tree.iter(tag='PreprocessorDefinitions'):
- definitions = ';'.join(building.Env['CPPDEFINES']) + ';%(PreprocessorDefinitions)'
+ CPPDEFINES = building.Env['CPPDEFINES']
+ definitions = []
+ if type(CPPDEFINES[0]) == type(()):
+ for item in CPPDEFINES:
+ definitions += [i for i in item]
+ definitions = ';'.join(definitions)
+ else:
+ definitions = ';'.join(building.Env['CPPDEFINES'])
+
+ definitions = definitions + ';%(PreprocessorDefinitions)'
elem.text = definitions
break
# write link flags
@@ -216,15 +252,27 @@ def VS2012Project(target, script, program):
break
xml_indent(root)
- vcxproj_string = etree.tostring(root, encoding='utf-8')
+
+ if sys.version > '3':
+ vcxproj_string = etree.tostring(root, encoding='unicode')
+ else:
+ # python3 is no decode function
+ vcxproj_string = etree.tostring(root, encoding='utf-8')
+
root_node=r'<Project DefaultTargets="Build" ToolsVersion="4.0">'
out.write(r'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">')
out.write(vcxproj_string[len(root_node):])
out.close()
xml_indent(filter_project)
- filter_string = etree.tostring(filter_project, encoding='utf-8')
- out = file('project.vcxproj.filters', 'wb')
+
+ if sys.version > '3':
+ filter_string = etree.tostring(filter_project, encoding='unicode')
+ else:
+ # python3 is no decode function
+ filter_string = etree.tostring(filter_project, encoding='utf-8')
+
+ out = open('project.vcxproj.filters', 'w')
out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
root_node=r'<Project ToolsVersion="4.0">'
out.write(r'<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">')
diff --git a/tools/win32spawn.py b/tools/win32spawn.py
index 9b878bf69f..1c2cfcf83b 100644
--- a/tools/win32spawn.py
+++ b/tools/win32spawn.py
@@ -24,7 +24,13 @@
import os
import threading
-import Queue
+import sys
+
+_PY2 = sys.version_info[0] < 3
+if _PY2:
+ import Queue
+else:
+ import queue as Queue
# Windows import
import win32file