From b6e1e47e3a92c1b94ef327149068a8a147fc73f5 Mon Sep 17 00:00:00 2001 From: Matthias Hoelzl Date: Sat, 26 Aug 2017 18:53:49 +0200 Subject: Make build scripts Python3 compatible - The Windows, UWP, Android (on Windows) and Linux builds are tested with Scons 3.0 alpha 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. --- platform/android/SCsub | 11 ++++++----- platform/android/detect.py | 24 ++++++++++++------------ platform/iphone/detect.py | 8 ++++---- platform/javascript/detect.py | 2 +- platform/osx/detect.py | 2 +- platform/uwp/detect.py | 4 ++-- 6 files changed, 26 insertions(+), 25 deletions(-) (limited to 'platform') diff --git a/platform/android/SCsub b/platform/android/SCsub index b124a1a5a8..87e7ee4747 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') @@ -40,8 +41,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() @@ -124,8 +125,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) @@ -146,7 +147,7 @@ elif env['android_arch'] == 'arm64v8': elif env['android_arch'] == 'x86': lib_arch_dir = 'x86' else: - print 'WARN: Architecture not suitable for embedding into APK; keeping .so at \\bin' + print('WARN: Architecture not suitable for embedding into APK; keeping .so at \\bin') if lib_arch_dir != '': if env['target'] == 'release': diff --git a/platform/android/detect.py b/platform/android/detect.py index ad5bfb4949..65442bf6f8 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -14,7 +14,7 @@ def get_name(): def can_build(): - return (os.environ.has_key("ANDROID_NDK_ROOT")) + return ("ANDROID_NDK_ROOT" in os.environ) def get_opts(): @@ -55,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, @@ -63,9 +63,9 @@ def configure(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): @@ -183,8 +183,8 @@ def configure(env): ## Compile flags 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': @@ -194,11 +194,11 @@ def configure(env): elif env["android_arch"] == "armv6": 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": 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__']) @@ -225,9 +225,9 @@ def configure(env): env['LINKFLAGS'] = ['-shared', '--sysroot=' + sysroot, '-Wl,--warn-shared-textrel'] if env["android_arch"] == "armv7": - 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/iphone/detect.py b/platform/iphone/detect.py index 1d802ff288..0b81422fa3 100644 --- a/platform/iphone/detect.py +++ b/platform/iphone/detect.py @@ -13,7 +13,7 @@ def get_name(): def can_build(): - 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 @@ -83,11 +83,11 @@ def configure(env): if (env["arch"] == "x86"): env['IPHONEPLATFORM'] = 'iPhoneSimulator' env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.6' - 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"] == "arm"): - 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=9.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=9.0 -MMD -MT dependencies'.split()) elif (env["arch"] == "arm64"): - 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=9.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=9.0 -isysroot $IPHONESDK'.split()) env.Append(CPPFLAGS=['-DNEED_LONG_INT']) env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON']) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 68c8d1eea5..5f066f1b15 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -13,7 +13,7 @@ def get_name(): def can_build(): - return (os.environ.has_key("EMSCRIPTEN_ROOT")) + return ("EMSCRIPTEN_ROOT" in os.environ) def get_opts(): diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 661da6e7c1..d3ebdfe992 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -12,7 +12,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 diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py index 64dac93f1f..23929dd804 100644 --- a/platform/uwp/detect.py +++ b/platform/uwp/detect.py @@ -145,8 +145,8 @@ def configure(env): env.Append(CPPFLAGS=['/AI', vc_base_path + 'lib/store/references']) env.Append(CPPFLAGS=['/AI', vc_base_path + 'lib/x86/store/references']) - env.Append(CCFLAGS=string.split('/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP" /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo')) - env.Append(CXXFLAGS=string.split('/ZW /FS')) + env.Append(CCFLAGS='/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP" /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo'.split()) + env.Append(CXXFLAGS='/ZW /FS'.split()) env.Append(CCFLAGS=['/AI', vc_base_path + '\\vcpackages', '/AI', os.environ['WINDOWSSDKDIR'] + '\\References\\CommonConfiguration\\Neutral']) ## Link flags -- cgit v1.2.3