summarylogtreecommitdiffstats
path: root/py2to3.patch
blob: d26e291f3cfd769422a5ac25bdc5ca81ac458dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
From fb236045de2a57986700a738939c8ee7e9cef1ad Mon Sep 17 00:00:00 2001
From: Matthias Hoelzl <tc@xantira.com>
Date: Sat, 26 Aug 2017 18:53:49 +0200
Subject: [PATCH] Make build scripts Scons 3.0/Python3 compatible

- Cherry picked #10662 and fixed merge conflicts.
- Manualy merged the change from #11904.
- Did not merge #12236 since I'm not sure whether the issue
  affects Godot 2.1 and I don't have VS2013 to test.
- Did not merge #11843 since it doesn't seem relevant (the
  code is only needed for creating DONORS.md, etc.).
- Did not merge #10727 and #11752 since they seem to be
  already included in #11742.
- The Windows and Linux builds have been tested with Scons 3.0
  using Python 3.
- OSX and iOS should hopefully work but are not tested since
  I don't have a Mac.
- Builds using SCons 2.5 and Python 2 should not be impacted.
---
 compat.py                     | 31 ++++++++++++++++++++++++++++
 core/SCsub                    |  4 ++--
 drivers/gles2/shaders/SCsub   |  2 +-
 drivers/unix/SCsub            |  2 +-
 editor/SCsub                  | 34 +++++++++++++++++++------------
 editor/icons/SCsub            |  7 +++----
 methods.py                    | 47 ++++++++++++++++++++++---------------------
 modules/freetype/SCsub        |  3 ++-
 platform/android/SCsub        |  9 +++++----
 platform/android/detect.py    | 36 ++++++++++++---------------------
 platform/bb10/detect.py       |  2 +-
 platform/iphone/detect.py     | 10 ++++-----
 platform/javascript/detect.py |  6 +-----
 platform/osx/detect.py        |  4 ++--
 platform/windows/detect.py    | 10 ++++-----
 platform/winrt/detect.py      | 10 ++++-----
 16 files changed, 121 insertions(+), 96 deletions(-)
 create mode 100644 compat.py

diff --git a/compat.py b/compat.py
new file mode 100644
index 0000000000..7338c479fb
--- /dev/null
+++ b/compat.py
@@ -0,0 +1,31 @@
+import sys
+
+if sys.version_info < (3,):
+    def isbasestring(s):
+        return isinstance(s, basestring)
+    def open_utf8(filename, mode):
+        return open(filename, mode)
+    def byte_to_str(x):
+        return str(ord(x))
+    import cStringIO
+    def StringIO():
+        return cStringIO.StringIO()
+    def encode_utf8(x):
+        return x
+    def iteritems(d):
+        return d.iteritems()
+else:
+    def isbasestring(s):
+        return isinstance(s, (str, bytes))
+    def open_utf8(filename, mode):
+        return open(filename, mode, encoding="utf-8")
+    def byte_to_str(x):
+        return str(x)
+    import io
+    def StringIO():
+        return io.StringIO()
+    import codecs
+    def encode_utf8(x):
+        return codecs.utf_8_encode(x)[0]
+    def iteritems(d):
+        return iter(d.items())
diff --git a/core/SCsub b/core/SCsub
index d4aba34681..b89a1bf171 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -18,7 +18,7 @@ gd_cpp = '#include "globals.h"\n'
 gd_cpp += gd_inc
 gd_cpp += "void Globals::register_global_defaults() {\n" + gd_call + "\n}\n"
 
-f = open("global_defaults.gen.cpp", "wb")
+f = open("global_defaults.gen.cpp", "w")
 f.write(gd_cpp)
 f.close()
 
@@ -47,7 +47,7 @@ if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
         txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
         print("Invalid AES256 encryption key, not 64 bits hex: " + e)
 
-f = open("script_encryption_key.gen.cpp", "wb")
+f = open("script_encryption_key.gen.cpp", "w")
 f.write("#include \"globals.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
 f.close()
 
diff --git a/drivers/gles2/shaders/SCsub b/drivers/gles2/shaders/SCsub
index bf4ec9485d..13e6490b44 100644
--- a/drivers/gles2/shaders/SCsub
+++ b/drivers/gles2/shaders/SCsub
@@ -2,7 +2,7 @@
 
 Import('env')
 
-if env['BUILDERS'].has_key('GLSL120GLES'):
+if 'GLSL120GLES' in env['BUILDERS']:
     env.GLSL120GLES('material.glsl')
     env.GLSL120GLES('canvas.glsl')
     env.GLSL120GLES('canvas_shadow.glsl')
diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub
index 96efc91b7a..5ced44dfda 100644
--- a/drivers/unix/SCsub
+++ b/drivers/unix/SCsub
@@ -8,7 +8,7 @@ g_set_p += 'String OS_Unix::get_global_settings_path() const {\n'
 g_set_p += '\treturn "' + env["unix_global_settings_path"] + '";\n'
 g_set_p += '}\n'
 g_set_p += '#endif'
-f = open("os_unix_global_settings_path.gen.cpp", "wb")
+f = open("os_unix_global_settings_path.gen.cpp", "w")
 f.write(g_set_p)
 f.close()
 
diff --git a/editor/SCsub b/editor/SCsub
index e59293f344..e8096f1267 100644
--- a/editor/SCsub
+++ b/editor/SCsub
@@ -3,13 +3,15 @@
 Import('env')
 env.editor_sources = []
 
+from compat import encode_utf8, byte_to_str, open_utf8
+
 
 def make_certs_header(target, source, env):
 
     src = source[0].srcnode().abspath
     dst = target[0].srcnode().abspath
     f = open(src, "rb")
-    g = open(dst, "wb")
+    g = open_utf8(dst, "w")
     buf = f.read()
     decomp_size = len(buf)
     import zlib
@@ -22,7 +24,7 @@ def make_certs_header(target, source, env):
     g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n")
     g.write("static const unsigned char _certs_compressed[]={\n")
     for i in range(len(buf)):
-        g.write(str(ord(buf[i])) + ",\n")
+        g.write(byte_to_str(buf[i]) + ",\n")
     g.write("};\n")
     g.write("#endif")
 
@@ -31,9 +33,15 @@ def make_doc_header(target, source, env):
 
     src = source[0].srcnode().abspath
     dst = target[0].srcnode().abspath
-    f = open(src, "rb")
-    g = open(dst, "wb")
-    buf = f.read()
+    f = open_utf8(src, "r")
+    g = open_utf8(dst, "w")
+    # Note: As long as we simply read the contents of `f` and immediately call
+    # `zlib.compress` on the result, we could open `f` as binary file and store
+    # the result in `buf` without passing it through `encode_utf8`. However if
+    # we ever perform any string operations on the result (as in Godot 3)
+    # we need the UTF8 decoding/encoding step, so it seems more future proof
+    # to do it this way.
+    buf = encode_utf8(f.read())
     decomp_size = len(buf)
     import zlib
     buf = zlib.compress(buf)
@@ -45,7 +53,7 @@ def make_doc_header(target, source, env):
     g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n")
     g.write("static const unsigned char _doc_data_compressed[]={\n")
     for i in range(len(buf)):
-        g.write(str(ord(buf[i])) + ",\n")
+        g.write(byte_to_str(buf[i]) + ",\n")
     g.write("};\n")
     g.write("#endif")
 
@@ -54,7 +62,7 @@ def make_fonts_header(target, source, env):
 
     dst = target[0].srcnode().abspath
 
-    g = open(dst, "wb")
+    g = open_utf8(dst, "w")
 
     g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
     g.write("#ifndef _EDITOR_FONTS_H\n")
@@ -72,7 +80,7 @@ def make_fonts_header(target, source, env):
         g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n")
         g.write("static const unsigned char _font_" + name + "[]={\n")
         for i in range(len(buf)):
-            g.write(str(ord(buf[i])) + ",\n")
+            g.write(byte_to_str(buf[i]) + ",\n")
 
         g.write("};\n")
 
@@ -83,7 +91,7 @@ def make_translations_header(target, source, env):
 
     dst = target[0].srcnode().abspath
 
-    g = open(dst, "wb")
+    g = open_utf8(dst, "w")
 
     g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
     g.write("#ifndef _EDITOR_TRANSLATIONS_H\n")
@@ -107,7 +115,7 @@ def make_translations_header(target, source, env):
         #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n")
         g.write("static const unsigned char _translation_" + name + "_compressed[]={\n")
         for i in range(len(buf)):
-            g.write(str(ord(buf[i])) + ",\n")
+            g.write(byte_to_str(buf[i]) + ",\n")
 
         g.write("};\n")
 
@@ -131,8 +139,8 @@ def make_authors_header(target, source, env):
 
     src = source[0].srcnode().abspath
     dst = target[0].srcnode().abspath
-    f = open(src, "rb")
-    g = open(dst, "wb")
+    f = open_utf8(src, "r")
+    g = open_utf8(dst, "w")
 
     g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
     g.write("#ifndef _EDITOR_AUTHORS_H\n")
@@ -162,7 +170,7 @@ if (env["tools"] == "yes"):
         reg_exporters += '\tregister_' + e + '_exporter();\n'
         reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n'
     reg_exporters += '}\n'
-    f = open("register_exporters.gen.cpp", "wb")
+    f = open_utf8("register_exporters.gen.cpp", "w")
     f.write(reg_exporters_inc)
     f.write(reg_exporters)
     f.close()
diff --git a/editor/icons/SCsub b/editor/icons/SCsub
index bd67e637cc..5d65a55fb9 100644
--- a/editor/icons/SCsub
+++ b/editor/icons/SCsub
@@ -1,17 +1,16 @@
 #!/usr/bin/env python
 
 Import('env')
-
+from compat import StringIO
 
 def make_editor_icons_action(target, source, env):
 
     import os
-    import cStringIO
 
     dst = target[0].srcnode().abspath
     pixmaps = source
 
-    s = cStringIO.StringIO()
+    s = StringIO()
 
     s.write("#include \"editor_icons.h\"\n\n")
     s.write("#include \"editor_scale.h\"\n\n")
@@ -79,7 +78,7 @@ def make_editor_icons_action(target, source, env):
 
     s.write("\n\n}\n\n")
 
-    f = open(dst, "wb")
+    f = open(dst, "w")
     f.write(s.getvalue())
     f.close()
     s.close()
diff --git a/methods.py b/methods.py
index 9f4bdca4a9..d1ef9b5322 100755
--- a/methods.py
+++ b/methods.py
@@ -1,4 +1,5 @@
 import os
+from compat import iteritems
 
 
 def add_source_files(self, sources, filetype, lib_env=None, shared=False):
@@ -21,7 +22,7 @@ def add_source_files(self, sources, filetype, lib_env=None, shared=False):
 def build_shader_header(target, source, env):
 
     for x in source:
-        print x
+        print(x)
 
         name = str(x)
         name = name[name.rfind("/") + 1:]
@@ -701,11 +702,11 @@ def include_file_in_legacygl_header(filename, header_data, depth):
             if (not included_file in header_data.vertex_included_files and header_data.reading == "vertex"):
                 header_data.vertex_included_files += [included_file]
                 if(include_file_in_legacygl_header(included_file, header_data, depth + 1) == None):
-                    print "Error in file '" + filename + "': #include " + includeline + "could not be found!"
+                    print("Error in file '" + filename + "': #include " + includeline + "could not be found!")
             elif (not included_file in header_data.fragment_included_files and header_data.reading == "fragment"):
                 header_data.fragment_included_files += [included_file]
                 if(include_file_in_legacygl_header(included_file, header_data, depth + 1) == None):
-                    print "Error in file '" + filename + "': #include " + includeline + "could not be found!"
+                    print("Error in file '" + filename + "': #include " + includeline + "could not be found!")
 
             line = fs.readline()
 
@@ -1093,7 +1094,7 @@ def update_version():
         print("Using custom revision: " + rev)
     import version
 
-    f = open("core/version_generated.gen.h", "wb")
+    f = open("core/version_generated.gen.h", "w")
     f.write("#define VERSION_SHORT_NAME " + str(version.short_name) + "\n")
     f.write("#define VERSION_NAME " + str(version.name) + "\n")
     f.write("#define VERSION_MAJOR " + str(version.major) + "\n")
@@ -1225,7 +1226,7 @@ def detect_modules():
 
 """
 
-    f = open("modules/register_module_types.gen.cpp", "wb")
+    f = open("modules/register_module_types.gen.cpp", "w")
     f.write(modules_cpp)
 
     return module_list
@@ -1245,9 +1246,9 @@ def win32_spawn(sh, escape, cmd, args, env):
     data, err = proc.communicate()
     rv = proc.wait()
     if rv:
-        print "====="
-        print err
-        print "====="
+        print("=====")
+        print(err)
+        print("=====")
     return rv
 
 """
@@ -1325,17 +1326,17 @@ def android_add_default_config(self, config):
 
 def android_add_to_manifest(self, file):
     base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
-    f = open(base_path, "rb")
+    f = open(base_path, "r")
     self.android_manifest_chunk += f.read()
 
 def android_add_to_permissions(self, file):
     base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
-    f = open(base_path, "rb")
+    f = open(base_path, "r")
     self.android_permission_chunk += f.read()
 
 def android_add_to_attributes(self, file):
     base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
-    f = open(base_path, "rb")
+    f = open(base_path, "r")
     self.android_appattributes_chunk += f.read()
 
 def disable_module(self):
@@ -1370,9 +1371,9 @@ def mySubProcess(cmdline, env):
         data, err = proc.communicate()
         rv = proc.wait()
         if rv:
-            print "====="
-            print err
-            print "====="
+            print("=====")
+            print(err)
+            print("=====")
         return rv
 
     def mySpawn(sh, escape, cmd, args, env):
@@ -1381,7 +1382,7 @@ def mySpawn(sh, escape, cmd, args, env):
         cmdline = cmd + " " + newargs
 
         rv = 0
-        env = {str(key): str(value) for key, value in env.iteritems()}
+        env = {str(key): str(value) for key, value in iteritems(env)}
         if len(cmdline) > 32000 and cmd.endswith("ar"):
             cmdline = cmd + " " + args[1] + " " + args[2] + " "
             for i in range(3, len(args)):
@@ -1458,7 +1459,7 @@ def save_active_platforms(apnames, ap):
         str += "};\n"
 
         wf = x + "/logo.gen.h"
-        logow = open(wf, "wb")
+        logow = open(wf, "w")
         logow.write(str)
 
 
@@ -1525,7 +1526,7 @@ def detect_visual_c_compiler_version(tools_env):
 
     # Start with Pre VS 2017 checks which uses VCINSTALLDIR:
     if 'VCINSTALLDIR' in tools_env:
-        # print "Checking VCINSTALLDIR"
+        # print("Checking VCINSTALLDIR")
 
         # find() works with -1 so big ifs bellow are needed... the simplest solution, in fact
         # First test if amd64 and amd64_x86 compilers are present in the path
@@ -1558,7 +1559,7 @@ def detect_visual_c_compiler_version(tools_env):
 
     # and for VS 2017 and newer we check VCTOOLSINSTALLDIR:
     if 'VCTOOLSINSTALLDIR' in tools_env:
-        # print "Checking VCTOOLSINSTALLDIR"
+        # print("Checking VCTOOLSINSTALLDIR")
 
         # Newer versions have a different path available
         vc_amd64_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX64\\X64;")
@@ -1588,11 +1589,11 @@ def detect_visual_c_compiler_version(tools_env):
             vc_chosen_compiler_str = "x86_amd64"
 
     # debug help
-    # print vc_amd64_compiler_detection_index
-    # print vc_amd64_x86_compiler_detection_index
-    # print vc_x86_compiler_detection_index
-    # print vc_x86_amd64_compiler_detection_index
-    # print "chosen "+str(vc_chosen_compiler_index)+ " | "+str(vc_chosen_compiler_str)
+    # print(vc_amd64_compiler_detection_index)
+    # print(vc_amd64_x86_compiler_detection_index)
+    # print(vc_x86_compiler_detection_index)
+    # print(vc_x86_amd64_compiler_detection_index)
+    # print("chosen "+str(vc_chosen_compiler_index)+ " | "+str(vc_chosen_compiler_str))
 
     return vc_chosen_compiler_str
 
diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub
index c18c9109cc..d58af230e8 100644
--- a/modules/freetype/SCsub
+++ b/modules/freetype/SCsub
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 Import('env')
+from compat import isbasestring
 
 # Not building in a separate env as scene needs it
 
@@ -74,7 +75,7 @@ if (env['builtin_freetype'] != 'no'):
     # and then plain strings for system library. We insert between the two.
     inserted = False
     for idx, linklib in enumerate(env["LIBS"]):
-        if isinstance(linklib, basestring): # first system lib such as "X11", otherwise SCons lib object
+        if isbasestring(linklib): # first system lib such as "X11", otherwise SCons lib object
             env["LIBS"].insert(idx, lib)
             inserted = True
             break
diff --git a/platform/android/SCsub b/platform/android/SCsub
index dac20afa49..4db25824aa 100644
--- a/platform/android/SCsub
+++ b/platform/android/SCsub
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import shutil
+from compat import open_utf8
 
 Import('env')
 
@@ -39,8 +40,8 @@ prog = None
 abspath = env.Dir(".").abspath
 
 
-gradle_basein = open(abspath + "/build.gradle.template", "rb")
-gradle_baseout = open(abspath + "/java/build.gradle", "wb")
+gradle_basein = open_utf8(abspath + "/build.gradle.template", "r")
+gradle_baseout = open_utf8(abspath + "/java/build.gradle", "w")
 
 gradle_text = gradle_basein.read()
 
@@ -133,8 +134,8 @@ gradle_baseout.write(gradle_text)
 gradle_baseout.close()
 
 
-pp_basein = open(abspath + "/AndroidManifest.xml.template", "rb")
-pp_baseout = open(abspath + "/java/AndroidManifest.xml", "wb")
+pp_basein = open_utf8(abspath + "/AndroidManifest.xml.template", "r")
+pp_baseout = open_utf8(abspath + "/java/AndroidManifest.xml", "w")
 manifest = pp_basein.read()
 manifest = manifest.replace("$$ADD_APPLICATION_CHUNKS$$", env.android_manifest_chunk)
 manifest = manifest.replace("$$ADD_PERMISSION_CHUNKS$$", env.android_permission_chunk)
diff --git a/platform/android/detect.py b/platform/android/detect.py
index 3ae8baacd7..20a4a619ca 100644
--- a/platform/android/detect.py
+++ b/platform/android/detect.py
@@ -13,12 +13,7 @@ def get_name():
 
 
 def can_build():
-
-    import os
-    if (not os.environ.has_key("ANDROID_NDK_ROOT")):
-        return False
-
-    return True
+    return ("ANDROID_NDK_ROOT" in os.environ)
 
 
 def get_opts():
@@ -60,7 +55,7 @@ def configure(env):
         import subprocess
 
         def mySubProcess(cmdline, env):
-            # print "SPAWNED : " + cmdline
+            # print("SPAWNED : " + cmdline)
             startupinfo = subprocess.STARTUPINFO()
             startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
             proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
@@ -68,9 +63,9 @@ def mySubProcess(cmdline, env):
             data, err = proc.communicate()
             rv = proc.wait()
             if rv:
-                print "====="
-                print err
-                print "====="
+                print("=====")
+                print(err)
+                print("=====")
             return rv
 
         def mySpawn(sh, escape, cmd, args, env):
@@ -167,9 +162,8 @@ def mySpawn(sh, escape, cmd, args, env):
     common_opts = ['-fno-integrated-as', '-gcc-toolchain', gcc_toolchain_path]
 
     env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
-    env.Append(CPPFLAGS=string.split(
-        '-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden -fno-strict-aliasing'))
-    env.Append(CPPFLAGS=string.split('-DNO_STATVFS -DGLES2_ENABLED'))
+    env.Append(CPPFLAGS='-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden -fno-strict-aliasing'.split())
+    env.Append(CPPFLAGS='-DNO_STATVFS -DGLES2_ENABLED'.split())
 
     env['neon_enabled'] = False
     if env['android_arch'] == 'x86':
@@ -180,13 +174,12 @@ def mySpawn(sh, escape, cmd, args, env):
     elif env["android_arch"] == "armv6":
         can_vectorize = False
         target_opts = ['-target', 'armv6-none-linux-androideabi']
-        env.Append(CPPFLAGS=string.split(
-            '-D__ARM_ARCH_6__ -march=armv6 -mfpu=vfp -mfloat-abi=softfp'))
+        env.Append(CPPFLAGS='-D__ARM_ARCH_6__ -march=armv6 -mfpu=vfp -mfloat-abi=softfp'.split())
+
     elif env["android_arch"] == "armv7":
         can_vectorize = True
         target_opts = ['-target', 'armv7-none-linux-androideabi']
-        env.Append(CPPFLAGS=string.split(
-            '-D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -march=armv7-a -mfloat-abi=softfp'))
+        env.Append(CPPFLAGS='-D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -march=armv7-a -mfloat-abi=softfp'.split())
         if env['android_neon'] == 'yes':
             env['neon_enabled'] = True
             env.Append(CPPFLAGS=['-mfpu=neon', '-D__ARM_NEON__'])
@@ -205,12 +198,9 @@ def mySpawn(sh, escape, cmd, args, env):
 
     env['LINKFLAGS'] = ['-shared', '--sysroot=' +
                         sysroot, '-Wl,--warn-shared-textrel']
-    env.Append(LINKFLAGS=string.split(
-        '-Wl,--fix-cortex-a8'))
-    env.Append(LINKFLAGS=string.split(
-        '-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'))
-    env.Append(LINKFLAGS=string.split(
-        '-Wl,-soname,libgodot_android.so -Wl,--gc-sections'))
+    env.Append(LINKFLAGS='-Wl,--fix-cortex-a8'.split())
+    env.Append(LINKFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'.split())
+    env.Append(LINKFLAGS='-Wl,-soname,libgodot_android.so -Wl,--gc-sections'.split())
     if mt_link:
         env.Append(LINKFLAGS=['-Wl,--threads'])
     env.Append(LINKFLAGS=target_opts)
diff --git a/platform/bb10/detect.py b/platform/bb10/detect.py
index d3ee9f0124..6031378354 100644
--- a/platform/bb10/detect.py
+++ b/platform/bb10/detect.py
@@ -15,7 +15,7 @@ def get_name():
 def can_build():
 
     import os
-    if (not os.environ.has_key("QNX_TARGET")):
+    if not "QNX_TARGET" in os.environ:
         return False
     return True
 
diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py
index 6aeaaf4736..73d00a9a73 100644
--- a/platform/iphone/detect.py
+++ b/platform/iphone/detect.py
@@ -12,9 +12,7 @@ def get_name():
 
 def can_build():
 
-    import sys
-    import os
-    if sys.platform == 'darwin' or os.environ.has_key("OSXCROSS_IOS"):
+    if sys.platform == 'darwin' or ("OSXCROSS_IOS" in os.environ):
         return True
 
     return False
@@ -58,16 +56,16 @@ def configure(env):
     if (env["ios_sim"] == "yes" or env["arch"] == "x86"):  # i386, simulator
         env["arch"] = "x86"
         env["bits"] = "32"
-        env.Append(CCFLAGS=string.split('-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $IPHONESDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"'))
+        env.Append(CCFLAGS='-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $IPHONESDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"'.split())
     elif (env["arch"] == "arm64"):  # arm64
         env["bits"] = "64"
-        env.Append(CCFLAGS=string.split('-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=7.0 -isysroot $IPHONESDK'))
+        env.Append(CCFLAGS='-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=7.0 -isysroot $IPHONESDK'.split())
         env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
         env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
     else:  # armv7
         env["arch"] = "arm"
         env["bits"] = "32"
-        env.Append(CCFLAGS=string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=7.0 -MMD -MT dependencies'))
+        env.Append(CCFLAGS='-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=7.0 -MMD -MT dependencies'.split())
 
     if (env["arch"] == "x86"):
         env['IPHONEPLATFORM'] = 'iPhoneSimulator'
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 1742e97225..472ff1e4ed 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -12,11 +12,7 @@ def get_name():
 
 
 def can_build():
-
-    import os
-    if (not os.environ.has_key("EMSCRIPTEN_ROOT")):
-        return False
-    return True
+    return ("EMSCRIPTEN_ROOT" in os.environ)
 
 
 def get_opts():
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index b6a9d43650..cbb7863e21 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -13,7 +13,7 @@ def get_name():
 
 def can_build():
 
-    if (sys.platform == "darwin" or os.environ.has_key("OSXCROSS_ROOT")):
+    if (sys.platform == "darwin" or ("OSXCROSS_ROOT" in os.environ)):
         return True
 
     return False
@@ -53,7 +53,7 @@ def configure(env):
 
         env.Append(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
 
-    if (not os.environ.has_key("OSXCROSS_ROOT")):
+    if ("OSXCROSS_ROOT" not in os.environ):
         # regular native build
         if (env["bits"] == "64"):
             env.Append(CCFLAGS=['-arch', 'x86_64'])
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 892349d2ce..219fd4412c 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -281,7 +281,7 @@ def configure(env):
 
         # Note: this detection/override code from here onward should be here instead of in SConstruct because it's platform and compiler specific (MSVC/Windows)
         if(env["bits"] != "default"):
-            print "Error: bits argument is disabled for MSVC"
+            print("Error: bits argument is disabled for MSVC")
             print ("Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console (or Visual Studio settings)"
                    + " that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits argument (example: scons p=windows) and SCons will attempt to detect what MSVC compiler"
                    + " will be executed and inform you.")
@@ -292,16 +292,16 @@ def configure(env):
         env["bits"] = "32"
         env["x86_libtheora_opt_vc"] = True
 
-        print "Detected MSVC compiler: " + compiler_version_str
+        print("Detected MSVC compiler: " + compiler_version_str)
         # If building for 64bit architecture, disable assembly optimisations for 32 bit builds (theora as of writting)... vc compiler for 64bit can not compile _asm
         if(compiler_version_str == "amd64" or compiler_version_str == "x86_amd64"):
             env["bits"] = "64"
             env["x86_libtheora_opt_vc"] = False
-            print "Compiled program architecture will be a 64 bit executable (forcing bits=64)."
+            print("Compiled program architecture will be a 64 bit executable (forcing bits=64).")
         elif (compiler_version_str == "x86" or compiler_version_str == "amd64_x86"):
-            print "Compiled program architecture will be a 32 bit executable. (forcing bits=32)."
+            print("Compiled program architecture will be a 32 bit executable. (forcing bits=32).")
         else:
-            print "Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup."
+            print("Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup.")
         if env["bits"] == "64":
             env.Append(CCFLAGS=['/D_WIN64'])
     else:
diff --git a/platform/winrt/detect.py b/platform/winrt/detect.py
index b056ec6a07..4601a30883 100644
--- a/platform/winrt/detect.py
+++ b/platform/winrt/detect.py
@@ -38,7 +38,7 @@ def get_flags():
 def configure(env):
 
     if(env["bits"] != "default"):
-        print "Error: bits argument is disabled for MSVC"
+        print("Error: bits argument is disabled for MSVC")
         print ("Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console (or Visual Studio settings)"
                +" that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits argument (example: scons p=winrt) and SCons will attempt to detect what MSVC compiler"
                +" will be executed and inform you.")
@@ -58,7 +58,7 @@ def configure(env):
 
     if os.getenv('Platform') == "ARM":
 
-        print "Compiled program architecture will be an ARM executable. (forcing bits=32)."
+        print("Compiled program architecture will be an ARM executable. (forcing bits=32).")
 
         arch="arm"
         env["bits"]="32"
@@ -75,12 +75,12 @@ def configure(env):
 
         if(compiler_version_str == "amd64" or compiler_version_str == "x86_amd64"):
             env["bits"]="64"
-            print "Compiled program architecture will be a x64 executable (forcing bits=64)."
+            print("Compiled program architecture will be a x64 executable (forcing bits=64).")
         elif (compiler_version_str=="x86" or compiler_version_str == "amd64_x86"):
             env["bits"]="32"
-            print "Compiled program architecture will be a x86 executable. (forcing bits=32)."
+            print("Compiled program architecture will be a x86 executable. (forcing bits=32).")
         else:
-            print "Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup."
+            print("Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup.")
             env["bits"]="32"
 
         if (env["bits"] == "32"):