From ff072c919c2c532e068dfd3eba4fd2352d91942a Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 18 Jun 2019 08:30:49 -0700 Subject: [PATCH 1/3] Check compiler version for php 74 --- buildscripts/buildtools.py | 69 ++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index c1f9df4cd..c6130e88f 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -42,7 +42,8 @@ def __init__(self, phpver, driver, arch, thread, no_rename, debug_enabled = Fals self.thread = thread.lower() self.no_rename = no_rename self.debug_enabled = debug_enabled - + self.vc = '' + def major_version(self): """Return the major version number based on the PHP version.""" return self.phpver[0:3] @@ -66,17 +67,52 @@ def driver_new_name(self, driver, suffix): version = self.version_label() return 'php_' + driver + '_' + version + '_' + self.thread + suffix - def compiler_version(self): - """Return the appropriate compiler version based on PHP version.""" - VC = 'vc14' - version = self.version_label() - if version >= '72': # Compiler version for PHP 7.2 or above - VC = 'vc15' - return VC + def determine_compiler(self, sdk_dir, vs_ver): + """Return the compiler version using vswhere.exe.""" + vswhere = os.path.join(sdk_dir, 'php-sdk', 'bin', 'vswhere.exe') + if not os.path.exists(vswhere): + print('Could not find ' + vswhere) + exit(1) + + # If both VS 2017 and VS 2019 are installed, both versions are returned. + # For example, temp.txt would have the following values (in this order): + # 16.1.29009.5 + # 15.9.28307.344 + # But if only VS 2017 is present, temp.txt will only have one value like this: + # 15.9.28307.344 + # On the other hand, if only VS 2019 is present, temp.txt will be empty + command = '{0} -version {1} -property installationVersion '.format(vswhere, vs_ver) + os.system(command + ' > temp.txt') + + # Read the first line from temp.txt + with open('temp.txt', 'r') as f: + ver = f.readline() + print('Version: ' + ver) + vc = ver[:2] + if vc == '15': + return 'vc15' + else: + return 'vs16' - def phpsrc_root(self, sdk_dir): + def compiler_version(self, sdk_dir): + """Return the appropriate compiler version based on PHP version.""" + if self.vc is '': + VC = 'vc14' + version = self.version_label() + if version >= '72': # Compiler version for PHP 7.2 or above + VC = 'vc15' + if version == '74': + # Compiler version for PHP 7.4 or above + # Can be compiled using VS 2017 or VS 2019 + print('Checking compiler versions...') + VC = self.determine_compiler(sdk_dir, 15) + self.vc = VC + print('Compiler: ' + self.vc) + return self.vc + + def phpsrc_root(self, sdk_dir): """Return the path to the PHP source folder based on *sdk_dir*.""" - vc = self.compiler_version() + vc = self.compiler_version(sdk_dir) return os.path.join(sdk_dir, 'php-sdk', 'phpdev', vc, self.arch, 'php-'+self.phpver+'-src') def build_abs_path(self, sdk_dir): @@ -97,6 +133,10 @@ def build_abs_path(self, sdk_dir): def remove_old_builds(self, sdk_dir): """Remove the extensions, e.g. the driver subfolders in php-7.*-src\ext.""" + if not os.path.exists(os.path.join(sdk_dir, 'php-sdk')): + print('No old builds to be removed...') + return + print('Removing old builds...') phpsrc = self.phpsrc_root(sdk_dir) @@ -117,6 +157,10 @@ def remove_prev_build(self, sdk_dir): """Remove all binaries and source code in the Release* or Debug* folders according to the current configuration """ + if not os.path.exists(os.path.join(sdk_dir, 'php-sdk')): + print('No old builds to be removed...') + return + print('Removing previous build...') build_dir = self.build_abs_path(sdk_dir) if not os.path.exists(build_dir): @@ -370,13 +414,16 @@ def build_drivers(self, make_clean = False, dest = None, log_file = None): os.system('git clone https://github.com/OSTC/php-sdk-binary-tools.git --branch master --single-branch --depth 1 ' + phpSDK) os.chdir(phpSDK) os.system('git pull ') + print('Done cloning the latest php SDK...') # Move the generated batch file to phpSDK for the php starter script + print('Moving the sdk bath file over...') sdk_batch_file = os.path.join(phpSDK, batch_file) if os.path.exists(sdk_batch_file): os.remove(sdk_batch_file) shutil.move(os.path.join(work_dir, batch_file), phpSDK) + print('Checking if source exists...') sdk_source = os.path.join(phpSDK, 'Source') # Sometimes, for various reasons, the Source folder from previous build # might exist in phpSDK. If so, remove it first @@ -386,7 +433,7 @@ def build_drivers(self, make_clean = False, dest = None, log_file = None): shutil.move(source_dir, phpSDK) # Invoke phpsdk--.bat - vc = self.compiler_version() + vc = self.compiler_version(sdk_dir) starter_script = 'phpsdk-' + vc + '-' + self.arch + '.bat' print('Running starter script: ', starter_script) os.system(starter_script + ' -t ' + batch_file) From 255d1bbd850ddacc7d24c0793638e97b849812de Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 18 Jun 2019 11:46:09 -0700 Subject: [PATCH 2/3] Used a diff way to detect version --- buildscripts/buildtools.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index c6130e88f..1173cb3e2 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -74,14 +74,18 @@ def determine_compiler(self, sdk_dir, vs_ver): print('Could not find ' + vswhere) exit(1) - # If both VS 2017 and VS 2019 are installed, both versions are returned. + # If both VS 2017 and VS 2019 are installed, if we check only version 15, + # both versions are returned. # For example, temp.txt would have the following values (in this order): # 16.1.29009.5 # 15.9.28307.344 # But if only VS 2017 is present, temp.txt will only have one value like this: # 15.9.28307.344 - # On the other hand, if only VS 2019 is present, temp.txt will be empty - command = '{0} -version {1} -property installationVersion '.format(vswhere, vs_ver) + # On the other hand, if only VS 2019 is present, temp.txt will be empty. + # We can achieve the above by checking for version [15,16), in which case + # even if both compilers are present, it only returns one. If only VS 2019 + # exists, it's empty. + command = '{0} -version [{1},{2}) -property installationVersion '.format(vswhere, vs_ver, vs_ver + 1) os.system(command + ' > temp.txt') # Read the first line from temp.txt From c6df9e9f56ec04a27a67336109b276bcb94c4e9e Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 18 Jun 2019 12:48:56 -0700 Subject: [PATCH 3/3] Updated the comments --- buildscripts/buildtools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 1173cb3e2..17713f242 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -81,10 +81,10 @@ def determine_compiler(self, sdk_dir, vs_ver): # 15.9.28307.344 # But if only VS 2017 is present, temp.txt will only have one value like this: # 15.9.28307.344 - # On the other hand, if only VS 2019 is present, temp.txt will be empty. + # Likewise, if only VS 2019 is present, temp.txt contains only the one for 16. # We can achieve the above by checking for version [15,16), in which case # even if both compilers are present, it only returns one. If only VS 2019 - # exists, it's empty. + # exists, temp.txt is empty command = '{0} -version [{1},{2}) -property installationVersion '.format(vswhere, vs_ver, vs_ver + 1) os.system(command + ' > temp.txt') @@ -95,7 +95,7 @@ def determine_compiler(self, sdk_dir, vs_ver): vc = ver[:2] if vc == '15': return 'vc15' - else: + else: # For VS2019, it's 'vs' instead of 'vc' return 'vs16' def compiler_version(self, sdk_dir):