From 7a3d6983cd35c77e143dd22fb5b4cc9e7676f337 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Fri, 20 Apr 2018 14:57:24 -0700 Subject: [PATCH] Modify buildscripts to configure php.ini --- buildscripts/builddrivers.py | 24 ++++++++++++++++-------- buildscripts/buildtools.py | 23 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/buildscripts/builddrivers.py b/buildscripts/builddrivers.py index 680f602b9..75fcb5b1a 100644 --- a/buildscripts/builddrivers.py +++ b/buildscripts/builddrivers.py @@ -123,8 +123,13 @@ def build_extensions(self, root_dir, logfile): """ work_dir = os.path.dirname(os.path.realpath(__file__)) - if self.source_path is None: - # This will download from the specified branch on GitHub repo and copy the source + get_source = False if self.source_path is None else True + if self.repo is None or self.branch is None: + # If GitHub repo or branch is None, get the source locally + get_source = True + + if not get_source: + # This will download from the specified branch on GitHub repo and copy the source self.util.download_msphpsql_source(repo, branch) else: source = self.source_path @@ -164,7 +169,8 @@ def build_extensions(self, root_dir, logfile): else: self.util.copy_binary(ext_dir, dest_drivers, self.util.driver, '.dll') self.util.copy_binary(ext_dir, dest_symbols, self.util.driver, '.pdb') - + + return ext_dir def build(self): """This is the main entry point of building drivers for PHP. @@ -186,15 +192,15 @@ def build(self): logfile = self.util.get_logfile_name() try: - self.build_extensions(root_dir, logfile) + ext_dir = self.build_extensions(root_dir, logfile) print('Build Completed') except: print('Something went wrong, launching log file', logfile) # display log file only when not testing if not self.testing: os.startfile(os.path.join(root_dir, 'php-sdk', logfile)) - os.chdir(work_dir) - break + os.chdir(work_dir) + exit(1) if not self.testing: choice = input("Rebuild using the same configuration(yes) or quit (no) [yes/no]: ") @@ -277,8 +283,10 @@ def validate_input(question, values): repo = 'Microsoft' if branch == '': branch = 'dev' - - arch_version = arch_version.lower() + else: + repo = branch = None + + arch_version = arch_version.lower() arch = 'x64' if arch_version == 'yes' or arch_version == 'y' or arch_version == '' else 'x86' debug_mode = debug_mode.lower() diff --git a/buildscripts/buildtools.py b/buildscripts/buildtools.py index 50b2abb43..d617087c9 100644 --- a/buildscripts/buildtools.py +++ b/buildscripts/buildtools.py @@ -445,21 +445,42 @@ def copy_binary(self, from_dir, dest_dir, driver, suffix): else: binary = self.driver_name(driver, suffix) shutil.copy2(os.path.join(from_dir, binary), dest_dir) + if suffix == '.dll': + php_ini_file = os.path.join(from_dir, 'php.ini') + with open(php_ini_file, 'a') as php_ini: + php_ini.write('extension=' + binary + '\n'); def copy_binaries(self, sdk_dir, copy_to_ext): """Copy the sqlsrv and/or pdo_sqlsrv binaries, including the pdb files, to the right place, depending on *copy_to_ext*. The default is to copy them to the 'ext' folder. - """ + """ + + # Get php.ini file from php.ini-production build_dir = self.build_abs_path(sdk_dir) + php_ini_file = os.path.join(build_dir, 'php.ini') + print('Setting up php ini file', php_ini_file) + + # Copy php.ini-production file to php.ini + phpsrc = self.phpsrc_root(sdk_dir) + shutil.copy(os.path.join(phpsrc, 'php.ini-production'), php_ini_file) + + # Copy run-tests.php as well + phpsrc = self.phpsrc_root(sdk_dir) + shutil.copy(os.path.join(phpsrc, 'run-tests.php'), build_dir) + print('Copying the binaries from', build_dir) if copy_to_ext: dest_dir = os.path.join(build_dir, 'ext') + ext_dir_line = 'extension_dir=ext\\' else: + ext_dir_line = 'extension_dir=.\\' # Simply make a copy of the binaries in sdk_dir dest_dir = sdk_dir print('Destination:', dest_dir) + with open(php_ini_file, 'a') as php_ini: + php_ini.write(ext_dir_line + '\n') # Now copy the binaries if self.driver == 'all':