Skip to content

Commit

Permalink
Reverted changes to build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam committed Jun 18, 2019
1 parent 1302bb7 commit d061e55
Showing 1 changed file with 11 additions and 57 deletions.
68 changes: 11 additions & 57 deletions buildscripts/buildtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ 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]
Expand All @@ -67,51 +66,17 @@ def driver_new_name(self, driver, suffix):
version = self.version_label()
return 'php_' + driver + '_' + version + '_' + self.thread + suffix

def determine_compiler(self, sdk_dir, vs_ver):
"""Return the appropriate compiler version using vswhere.exe."""
filename = 'get-vc.bat'
sdk_bin = os.path.join(sdk_dir, 'php-sdk', 'bin')
vswhere = os.path.join(sdk_bin, 'vswhere.exe')
if not os.path.exists(vswhere):
print('Could not find ' + vswhere)
exit(1)

try:
file = open(filename, 'w')
file.write('@ECHO OFF' + os.linesep)
file.write('SET currDir=%CD%' + os.linesep)
file.write('CD ' + sdk_bin + os.linesep)
command = '@CALL {0} -version [{1},{2}) -property installationVersion '.format('vswhere', vs_ver, vs_ver + 1)
file.write(command + ' > temp.txt' + os.linesep)
file.write('SET /p VER=<temp.txt' + os.linesep)
file.write('SET VC=%VER:~0,2%' + os.linesep)
file.write('CD %currDir%' + os.linesep)
file.close()
os.startfile(filename)
return os.environ.get('VC')
except:
print('Error occurred when writing a batch file for checking compiler versions')
raise

def compiler_version(self, sdk_dir):
def compiler_version(self):
"""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 = 'vc' + self.determine_compiler(sdk_dir, 15)
self.vc = VC
print('Compiler: ' + self.vc)
return self.vc

def phpsrc_root(self, sdk_dir):
VC = 'vc14'
version = self.version_label()
if version >= '72': # Compiler version for PHP 7.2 or above
VC = 'vc15'
return VC

def phpsrc_root(self, sdk_dir):
"""Return the path to the PHP source folder based on *sdk_dir*."""
vc = self.compiler_version(sdk_dir)
vc = self.compiler_version()
return os.path.join(sdk_dir, 'php-sdk', 'phpdev', vc, self.arch, 'php-'+self.phpver+'-src')

def build_abs_path(self, sdk_dir):
Expand All @@ -132,10 +97,6 @@ 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)
Expand All @@ -156,10 +117,6 @@ 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):
Expand Down Expand Up @@ -413,16 +370,13 @@ 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
Expand All @@ -432,7 +386,7 @@ def build_drivers(self, make_clean = False, dest = None, log_file = None):
shutil.move(source_dir, phpSDK)

# Invoke phpsdk-<vc>-<arch>.bat
vc = self.compiler_version(sdk_dir)
vc = self.compiler_version()
starter_script = 'phpsdk-' + vc + '-' + self.arch + '.bat'
print('Running starter script: ', starter_script)
os.system(starter_script + ' -t ' + batch_file)
Expand Down

0 comments on commit d061e55

Please sign in to comment.