Skip to content

Commit 5ab775e

Browse files
authored
Merge pull request #1965 from RT-Thread/fix_py3
[Tools] Change building script for Py3
2 parents 02f006d + d687cfb commit 5ab775e

File tree

15 files changed

+150
-87
lines changed

15 files changed

+150
-87
lines changed

tools/building.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os
2828
import sys
2929
import string
30+
import utils
3031

3132
from SCons.Script import *
3233
from utils import _make_path_relative
@@ -233,7 +234,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
233234
rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
234235
# replace the 'RTT_CC' to 'CROSS_TOOL'
235236
os.environ['RTT_CC'] = rtconfig.CROSS_TOOL
236-
reload(rtconfig)
237+
utils.ReloadModule(rtconfig)
237238
except KeyError:
238239
print ('Unknow target: '+ tgt_name+'. Avaible targets: ' +', '.join(tgt_dict.keys()))
239240
sys.exit(1)
@@ -246,7 +247,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
246247
if 'RTT_EXEC_PATH' in os.environ:
247248
# del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py
248249
del os.environ['RTT_EXEC_PATH']
249-
reload(rtconfig)
250+
utils.ReloadModule(rtconfig)
250251

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

408409
# parse bsp rtconfig.h to get used component
409410
PreProcessor = PatchedPreProcessor()
410-
f = file(bsp_directory + '/rtconfig.h', 'r')
411+
f = open(bsp_directory + '/rtconfig.h', 'r')
411412
contents = f.read()
412413
f.close()
413414
PreProcessor.process_contents(contents)
@@ -458,7 +459,7 @@ def LocalOptions(config_filename):
458459
# parse wiced_config.h to get used component
459460
PreProcessor = SCons.cpp.PreProcessor()
460461

461-
f = file(config_filename, 'r')
462+
f = open(config_filename, 'r')
462463
contents = f.read()
463464
f.close()
464465

@@ -573,13 +574,29 @@ def DefineGroup(name, src, depend, **parameters):
573574
if 'CCFLAGS' in group:
574575
Env.AppendUnique(CCFLAGS = group['CCFLAGS'])
575576
if 'CPPPATH' in group:
577+
paths = []
578+
for item in group['CPPPATH']:
579+
paths.append(os.path.abspath(item))
580+
group['CPPPATH'] = paths
576581
Env.AppendUnique(CPPPATH = group['CPPPATH'])
577582
if 'CPPDEFINES' in group:
578583
Env.AppendUnique(CPPDEFINES = group['CPPDEFINES'])
579584
if 'LINKFLAGS' in group:
580585
Env.AppendUnique(LINKFLAGS = group['LINKFLAGS'])
581586
if 'ASFLAGS' in group:
582587
Env.AppendUnique(ASFLAGS = group['ASFLAGS'])
588+
if 'LOCAL_CPPPATH' in group:
589+
paths = []
590+
for item in group['LOCAL_CPPPATH']:
591+
paths.append(os.path.abspath(item))
592+
group['LOCAL_CPPPATH'] = paths
593+
594+
import rtconfig
595+
if rtconfig.PLATFORM == 'gcc':
596+
if 'CCFLAGS' in group:
597+
group['CCFLAGS'] = utils.GCCC99Patch(group['CCFLAGS'])
598+
if 'LOCAL_CCFLAGS' in group:
599+
group['LOCAL_CCFLAGS'] = utils.GCCC99Patch(group['LOCAL_CCFLAGS'])
583600

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

864881
# parse rtdef.h to get RT-Thread version
865882
prepcessor = PatchedPreProcessor()
866-
f = file(rtdef, 'r')
883+
f = open(rtdef, 'r')
867884
contents = f.read()
868885
f.close()
869886
prepcessor.process_contents(contents)

tools/cdk.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _CDKProject(tree, target, script):
5656
project_path = os.path.dirname(os.path.abspath(target))
5757

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

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

7575
# get each include path
76-
if group.has_key('CPPPATH') and group['CPPPATH']:
76+
if 'CPPPATH' in group and group['CPPPATH']:
7777
if CPPPATH:
7878
CPPPATH += group['CPPPATH']
7979
else:
8080
CPPPATH += group['CPPPATH']
8181

8282
# get each group's definitions
83-
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
83+
if 'CPPDEFINES' in group and group['CPPDEFINES']:
8484
if CPPDEFINES:
8585
CPPDEFINES += group['CPPDEFINES']
8686
else:
8787
CPPDEFINES += group['CPPDEFINES']
8888

8989
# get each group's cc flags
90-
if group.has_key('CCFLAGS') and group['CCFLAGS']:
90+
if 'CCFLAGS' in group and group['CCFLAGS']:
9191
if CCFLAGS:
9292
CCFLAGS += ' ' + group['CCFLAGS']
9393
else:
9494
CCFLAGS += group['CCFLAGS']
9595

9696
# get each group's link flags
97-
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
97+
if 'LINKFLAGS' in group and group['LINKFLAGS']:
9898
if LINKFLAGS:
9999
LINKFLAGS += ' ' + group['LINKFLAGS']
100100
else:

tools/codeblocks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def CBProject(target, script, program):
7373

7474
root = tree.getroot()
7575

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

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

9191
# SECTION 2.
9292
# write head include path
93-
if building.Env.has_key('CPPPATH'):
93+
if 'CPPPATH' in building.Env:
9494
cpp_path = building.Env['CPPPATH']
9595
paths = set()
9696
for path in cpp_path:
@@ -114,7 +114,7 @@ def CBProject(target, script, program):
114114
# write link flags
115115
'''
116116
# write lib dependence
117-
if building.Env.has_key('LIBS'):
117+
if 'LIBS' in building.Env:
118118
for elem in tree.iter(tag='Tool'):
119119
if elem.attrib['Name'] == 'VCLinkerTool':
120120
break
@@ -123,7 +123,7 @@ def CBProject(target, script, program):
123123
elem.set('AdditionalDependencies', libs)
124124
125125
# write lib include path
126-
if building.Env.has_key('LIBPATH'):
126+
if 'LIBPATH' in building.Env:
127127
lib_path = building.Env['LIBPATH']
128128
paths = set()
129129
for path in lib_path:

tools/gcc.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,27 @@ def checkAndGetResult(pattern, string):
105105
posix_thread = 0
106106

107107
for line in stdout.split(b'\n'):
108-
if re.search(b'fd_set', line):
108+
line = line.decode()
109+
if re.search('fd_set', line):
109110
have_fdset = 1
110111

111112
# check for sigal
112-
if re.search(b'struct[ \t]+sigaction', line):
113+
if re.search('struct[ \t]+sigaction', line):
113114
have_sigaction = 1
114-
if re.search(b'struct[ \t]+sigevent', line):
115+
if re.search('struct[ \t]+sigevent', line):
115116
have_sigevent = 1
116-
if re.search(b'siginfo_t', line):
117+
if re.search('siginfo_t', line):
117118
have_siginfo = 1
118-
if re.search(b'union[ \t]+sigval', line):
119+
if re.search('union[ \t]+sigval', line):
119120
have_sigval = 1
120121

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

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

127-
if re.findall(b'pthread_create', line):
128+
if re.findall('pthread_create', line):
128129
posix_thread = 1
129130

130131
if have_fdset:

tools/genconf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def genconfig() :
66
PreProcessor = SCons.cpp.PreProcessor()
77

88
try:
9-
f = file('rtconfig.h', 'r')
9+
f = open('rtconfig.h', 'r')
1010
contents = f.read()
1111
f.close()
1212
except :
@@ -16,7 +16,7 @@ def genconfig() :
1616
options = PreProcessor.cpp_namespace
1717

1818
try:
19-
f = file('.config', 'w')
19+
f = open('.config', 'w')
2020
for (opt, value) in options.items():
2121
if type(value) == type(1):
2222
f.write("CONFIG_%s=%d\n" % (opt, value))

tools/iar.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import sys
2727
import string
28+
import utils
2829

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

6465
if os.path.isabs(path):
65-
file_name.text = path.decode(fs_encoding)
66+
file_name.text = path # path.decode(fs_encoding)
6667
else:
67-
file_name.text = ('$PROJ_DIR$\\' + path).decode(fs_encoding)
68+
file_name.text = '$PROJ_DIR$\\' + path # ('$PROJ_DIR$\\' + path).decode(fs_encoding)
6869

6970
def IARWorkspace(target):
7071
# make an workspace
7172
workspace = target.replace('.ewp', '.eww')
72-
out = file(workspace, 'wb')
73+
out = open(workspace, 'w')
7374
xml = iar_workspace % target
7475
out.write(xml)
7576
out.close()
@@ -80,7 +81,7 @@ def IARProject(target, script):
8081
tree = etree.parse('template.ewp')
8182
root = tree.getroot()
8283

83-
out = file(target, 'wb')
84+
out = open(target, 'w')
8485

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

107108
# get each include path
108-
if group.has_key('CPPPATH') and group['CPPPATH']:
109+
if 'CPPPATH' in group and group['CPPPATH']:
109110
CPPPATH += group['CPPPATH']
110111

111112
# get each group's definitions
112-
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
113+
if 'CPPDEFINES' in group and group['CPPDEFINES']:
113114
CPPDEFINES += group['CPPDEFINES']
114115

115116
# get each group's link flags
116-
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
117+
if 'LINKFLAGS' in group and group['LINKFLAGS']:
117118
LINKFLAGS += group['LINKFLAGS']
118119

119-
if group.has_key('LIBS') and group['LIBS']:
120+
if 'LIBS' in group and group['LIBS']:
120121
for item in group['LIBS']:
121122
lib_path = searchLib(group)
122123
if lib_path != '':
@@ -161,7 +162,7 @@ def searchLib(group):
161162
state.text = path
162163

163164
xml_indent(root)
164-
out.write(etree.tostring(root, encoding='utf-8'))
165+
out.write(etree.tostring(root, encoding='utf-8').decode())
165166
out.close()
166167

167168
IARWorkspace(target)
@@ -176,14 +177,14 @@ def IARPath():
176177
# backup environ
177178
old_environ = os.environ
178179
os.environ['RTT_CC'] = 'iar'
179-
reload(rtconfig)
180+
utils.ReloadModule(rtconfig)
180181

181182
# get iar path
182183
path = rtconfig.EXEC_PATH
183184

184185
# restore environ
185186
os.environ = old_environ
186-
reload(rtconfig)
187+
utils.ReloadModule(rtconfig)
187188

188189
return path
189190

0 commit comments

Comments
 (0)