From 5e989b9296eca989acde165a4ff4b29e20cf5dfd Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 4 Jan 2021 11:37:56 +0100 Subject: [PATCH 1/2] configure osm2pgsql and module location via cmake The default location of osm2pgsql and the postgresql module is decided at compile/installation time and is not necessarily in the project directory. With this change it is now possible to have a project directory that is completely separate from the build directory. --- cmake/script.tmpl | 2 ++ lib/setup/SetupClass.php | 5 +---- lib/setup_functions.php | 7 +------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/cmake/script.tmpl b/cmake/script.tmpl index 4d9224b0..5b7bc6f7 100755 --- a/cmake/script.tmpl +++ b/cmake/script.tmpl @@ -1,5 +1,7 @@ #!@PHP_BIN@ -Cq iCacheMemory = getCacheMemoryMB(); } - $this->sModulePath = getSetting('DATABASE_MODULE_PATH', CONST_InstallDir.'/module'); + $this->sModulePath = getSetting('DATABASE_MODULE_PATH', CONST_Default_ModulePath); info('module path: ' . $this->sModulePath); // parse database string @@ -736,9 +736,6 @@ class SetupFunctions fwriteConstDef($rFile, 'LibDir', CONST_LibDir); fwriteConstDef($rFile, 'DataDir', CONST_DataDir); fwriteConstDef($rFile, 'InstallDir', CONST_InstallDir); - - fwrite($rFile, "if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SETTINGS'));\n\n"); - fwriteConstDef($rFile, 'Database_DSN', getSetting('DATABASE_DSN')); fwriteConstDef($rFile, 'Default_Language', getSetting('DEFAULT_LANGUAGE')); fwriteConstDef($rFile, 'Log_DB', getSettingBool('LOG_DB')); diff --git a/lib/setup_functions.php b/lib/setup_functions.php index a2287d9b..dab6a8e7 100755 --- a/lib/setup_functions.php +++ b/lib/setup_functions.php @@ -17,12 +17,7 @@ function checkInFile($sOSMFile) function getOsm2pgsqlBinary() { - $sBinary = getSetting('OSM2PGSQL_BINARY'); - if (!$sBinary) { - $sBinary = CONST_InstallDir.'/osm2pgsql/osm2pgsql'; - } - - return $sBinary; + return getSetting('OSM2PGSQL_BINARY', CONST_Default_Osm2pgsql); } function getImportStyle() From 4aba70caeef6f574e59ad05972ac4981d07ea26d Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 4 Jan 2021 11:39:45 +0100 Subject: [PATCH 2/2] create a temporary project dir for tests The project directory contains the website script as configured through the test configuration. This means that tests are now completely independet of any configuration that may be contained in the build directory. Also removes the hack to inject additional settings via a environment variable. --- test/bdd/environment.py | 37 ++++++++++++++++++------------------- test/bdd/steps/queries.py | 5 ++--- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/test/bdd/environment.py b/test/bdd/environment.py index 71d0dd2b..0ac92104 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -20,7 +20,6 @@ userconfig = { 'TEMPLATE_DB' : 'test_template_nominatim', 'TEST_DB' : 'test_nominatim', 'API_TEST_DB' : 'test_api_nominatim', - 'TEST_SETTINGS_FILE' : '/tmp/nominatim_settings.php', 'SERVER_MODULE_PATH' : None, 'PHPCOV' : False, # set to output directory to enable code coverage } @@ -43,15 +42,14 @@ class NominatimEnvironment(object): self.test_db = config['TEST_DB'] self.api_test_db = config['API_TEST_DB'] self.server_module_path = config['SERVER_MODULE_PATH'] - self.local_settings_file = config['TEST_SETTINGS_FILE'] self.reuse_template = not config['REMOVE_TEMPLATE'] self.keep_scenario_db = config['KEEP_TEST_DB'] self.code_coverage_path = config['PHPCOV'] self.code_coverage_id = 1 self.test_env = None - os.environ['NOMINATIM_SETTINGS'] = self.local_settings_file self.template_db_done = False + self.website_dir = None def connect_database(self, dbname): dbargs = {'database': dbname} @@ -80,26 +78,24 @@ class NominatimEnvironment(object): (';user=' + self.db_user) if self.db_user else '', (';password=' + self.db_pass) if self.db_pass else '' ) + + if self.website_dir is not None \ + and self.test_env is not None \ + and dsn == self.test_env['NOMINATIM_DATABASE_DSN']: + return # environment already set uo + self.test_env = os.environ self.test_env['NOMINATIM_DATABASE_DSN'] = dsn self.test_env['NOMINATIM_FLATNODE_FILE'] = '' self.test_env['NOMINATIM_IMPORT_STYLE'] = 'full' self.test_env['NOMINATIM_USE_US_TIGER_DATA'] = 'yes' - f = open(self.local_settings_file, 'w') - # https://secure.php.net/manual/en/ref.pdo-pgsql.connection.php - f.write("