Skip to content

Commit

Permalink
[Tools] Change building script for Py3
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardXiong committed Nov 10, 2018
1 parent b69baa9 commit d687cfb
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 87 deletions.
27 changes: 22 additions & 5 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import sys
import string
import utils

from SCons.Script import *
from utils import _make_path_relative
Expand Down Expand Up @@ -233,7 +234,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
# replace the 'RTT_CC' to 'CROSS_TOOL'
os.environ['RTT_CC'] = rtconfig.CROSS_TOOL
reload(rtconfig)
utils.ReloadModule(rtconfig)
except KeyError:
print ('Unknow target: '+ tgt_name+'. Avaible targets: ' +', '.join(tgt_dict.keys()))
sys.exit(1)
Expand All @@ -246,7 +247,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
if 'RTT_EXEC_PATH' in os.environ:
# del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py
del os.environ['RTT_EXEC_PATH']
reload(rtconfig)
utils.ReloadModule(rtconfig)

# add compability with Keil MDK 4.6 which changes the directory of armcc.exe
if rtconfig.PLATFORM == 'armcc':
Expand Down Expand Up @@ -407,7 +408,7 @@ def PrepareModuleBuilding(env, root_directory, bsp_directory):

# parse bsp rtconfig.h to get used component
PreProcessor = PatchedPreProcessor()
f = file(bsp_directory + '/rtconfig.h', 'r')
f = open(bsp_directory + '/rtconfig.h', 'r')
contents = f.read()
f.close()
PreProcessor.process_contents(contents)
Expand Down Expand Up @@ -458,7 +459,7 @@ def LocalOptions(config_filename):
# parse wiced_config.h to get used component
PreProcessor = SCons.cpp.PreProcessor()

f = file(config_filename, 'r')
f = open(config_filename, 'r')
contents = f.read()
f.close()

Expand Down Expand Up @@ -573,13 +574,29 @@ def DefineGroup(name, src, depend, **parameters):
if 'CCFLAGS' in group:
Env.AppendUnique(CCFLAGS = group['CCFLAGS'])
if 'CPPPATH' in group:
paths = []
for item in group['CPPPATH']:
paths.append(os.path.abspath(item))
group['CPPPATH'] = paths
Env.AppendUnique(CPPPATH = group['CPPPATH'])
if 'CPPDEFINES' in group:
Env.AppendUnique(CPPDEFINES = group['CPPDEFINES'])
if 'LINKFLAGS' in group:
Env.AppendUnique(LINKFLAGS = group['LINKFLAGS'])
if 'ASFLAGS' in group:
Env.AppendUnique(ASFLAGS = group['ASFLAGS'])
if 'LOCAL_CPPPATH' in group:
paths = []
for item in group['LOCAL_CPPPATH']:
paths.append(os.path.abspath(item))
group['LOCAL_CPPPATH'] = paths

import rtconfig
if rtconfig.PLATFORM == 'gcc':
if 'CCFLAGS' in group:
group['CCFLAGS'] = utils.GCCC99Patch(group['CCFLAGS'])
if 'LOCAL_CCFLAGS' in group:
group['LOCAL_CCFLAGS'] = utils.GCCC99Patch(group['LOCAL_CCFLAGS'])

# check whether to clean up library
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
Expand Down Expand Up @@ -863,7 +880,7 @@ def GetVersion():

# parse rtdef.h to get RT-Thread version
prepcessor = PatchedPreProcessor()
f = file(rtdef, 'r')
f = open(rtdef, 'r')
contents = f.read()
f.close()
prepcessor.process_contents(contents)
Expand Down
10 changes: 5 additions & 5 deletions tools/cdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _CDKProject(tree, target, script):
project_path = os.path.dirname(os.path.abspath(target))

root = tree.getroot()
out = file(target, 'wb')
out = open(target, 'w')
out.write('<?xml version="1.0" encoding="UTF-8"?>\n')

CPPPATH = []
Expand All @@ -73,28 +73,28 @@ def _CDKProject(tree, target, script):
group_tree = SDKAddGroup(ProjectFiles, root, group['name'], group['src'], project_path)

# get each include path
if group.has_key('CPPPATH') and group['CPPPATH']:
if 'CPPPATH' in group and group['CPPPATH']:
if CPPPATH:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']

# get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if 'CPPDEFINES' in group and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES += group['CPPDEFINES']

# 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:
Expand Down
8 changes: 4 additions & 4 deletions tools/codeblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def CBProject(target, script, program):

root = tree.getroot()

out = file(target, 'wb')
out = open(target, 'w')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n')

ProjectFiles = []
Expand All @@ -90,7 +90,7 @@ def CBProject(target, script, program):

# SECTION 2.
# write head include path
if building.Env.has_key('CPPPATH'):
if 'CPPPATH' in building.Env:
cpp_path = building.Env['CPPPATH']
paths = set()
for path in cpp_path:
Expand All @@ -114,7 +114,7 @@ def CBProject(target, script, program):
# write link flags
'''
# write lib dependence
if building.Env.has_key('LIBS'):
if 'LIBS' in building.Env:
for elem in tree.iter(tag='Tool'):
if elem.attrib['Name'] == 'VCLinkerTool':
break
Expand All @@ -123,7 +123,7 @@ def CBProject(target, script, program):
elem.set('AdditionalDependencies', libs)
# write lib include path
if building.Env.has_key('LIBPATH'):
if 'LIBPATH' in building.Env:
lib_path = building.Env['LIBPATH']
paths = set()
for path in lib_path:
Expand Down
19 changes: 10 additions & 9 deletions tools/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,27 @@ def checkAndGetResult(pattern, string):
posix_thread = 0

for line in stdout.split(b'\n'):
if re.search(b'fd_set', line):
line = line.decode()
if re.search('fd_set', line):
have_fdset = 1

# check for sigal
if re.search(b'struct[ \t]+sigaction', line):
if re.search('struct[ \t]+sigaction', line):
have_sigaction = 1
if re.search(b'struct[ \t]+sigevent', line):
if re.search('struct[ \t]+sigevent', line):
have_sigevent = 1
if re.search(b'siginfo_t', line):
if re.search('siginfo_t', line):
have_siginfo = 1
if re.search(b'union[ \t]+sigval', line):
if re.search('union[ \t]+sigval', line):
have_sigval = 1

if re.search(b'char\* version', line):
version = re.search(br'\"([^"]+)\"', line).groups()[0]
if re.search('char\* version', line):
version = re.search(r'\"([^"]+)\"', line).groups()[0]

if re.findall(b'iso_c_visible = [\d]+', line):
if re.findall('iso_c_visible = [\d]+', line):
stdc = re.findall('[\d]+', line)[0]

if re.findall(b'pthread_create', line):
if re.findall('pthread_create', line):
posix_thread = 1

if have_fdset:
Expand Down
4 changes: 2 additions & 2 deletions tools/genconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def genconfig() :
PreProcessor = SCons.cpp.PreProcessor()

try:
f = file('rtconfig.h', 'r')
f = open('rtconfig.h', 'r')
contents = f.read()
f.close()
except :
Expand All @@ -16,7 +16,7 @@ def genconfig() :
options = PreProcessor.cpp_namespace

try:
f = file('.config', 'w')
f = open('.config', 'w')
for (opt, value) in options.items():
if type(value) == type(1):
f.write("CONFIG_%s=%d\n" % (opt, value))
Expand Down
23 changes: 12 additions & 11 deletions tools/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import os
import sys
import string
import utils

import xml.etree.ElementTree as etree
from xml.etree.ElementTree import SubElement
Expand Down Expand Up @@ -62,14 +63,14 @@ def IARAddGroup(parent, name, files, project_path):
file_name = SubElement(file, 'name')

if os.path.isabs(path):
file_name.text = path.decode(fs_encoding)
file_name.text = path # path.decode(fs_encoding)
else:
file_name.text = ('$PROJ_DIR$\\' + path).decode(fs_encoding)
file_name.text = '$PROJ_DIR$\\' + path # ('$PROJ_DIR$\\' + path).decode(fs_encoding)

def IARWorkspace(target):
# make an workspace
workspace = target.replace('.ewp', '.eww')
out = file(workspace, 'wb')
out = open(workspace, 'w')
xml = iar_workspace % target
out.write(xml)
out.close()
Expand All @@ -80,7 +81,7 @@ def IARProject(target, script):
tree = etree.parse('template.ewp')
root = tree.getroot()

out = file(target, 'wb')
out = open(target, 'w')

CPPPATH = []
CPPDEFINES = []
Expand All @@ -105,18 +106,18 @@ def searchLib(group):
IARAddGroup(root, group['name'], group['src'], project_path)

# get each include path
if group.has_key('CPPPATH') and group['CPPPATH']:
if 'CPPPATH' in group and group['CPPPATH']:
CPPPATH += group['CPPPATH']

# get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if 'CPPDEFINES' in group and group['CPPDEFINES']:
CPPDEFINES += group['CPPDEFINES']

# get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if 'LINKFLAGS' in group and group['LINKFLAGS']:
LINKFLAGS += group['LINKFLAGS']

if group.has_key('LIBS') and group['LIBS']:
if 'LIBS' in group and group['LIBS']:
for item in group['LIBS']:
lib_path = searchLib(group)
if lib_path != '':
Expand Down Expand Up @@ -161,7 +162,7 @@ def searchLib(group):
state.text = path

xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8'))
out.write(etree.tostring(root, encoding='utf-8').decode())
out.close()

IARWorkspace(target)
Expand All @@ -176,14 +177,14 @@ def IARPath():
# backup environ
old_environ = os.environ
os.environ['RTT_CC'] = 'iar'
reload(rtconfig)
utils.ReloadModule(rtconfig)

# get iar path
path = rtconfig.EXEC_PATH

# restore environ
os.environ = old_environ
reload(rtconfig)
utils.ReloadModule(rtconfig)

return path

Expand Down
Loading

0 comments on commit d687cfb

Please sign in to comment.