From a2af3a53fa1ba8a785971b5ed2b2792df7fa645a Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Wed, 27 Jun 2018 22:45:58 +0200 Subject: [PATCH 1/5] SConstruct: fixup HarfBuzz configure checks - call .Message before .TryRun - don't silence .Result - report found version even if it's really old and doesn't even define HB_VERSION_ATLEAST macro --- SConstruct | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/SConstruct b/SConstruct index da31c1423..1af27aedf 100644 --- a/SConstruct +++ b/SConstruct @@ -1038,11 +1038,16 @@ int main() return False def harfbuzz_version(context): - ret = context.TryRun(""" + context.Message('Checking for HarfBuzz version >= %s... ' % HARFBUZZ_MIN_VERSION_STRING) + ret, out = context.TryRun(""" #include "harfbuzz/hb.h" #include +#ifndef HB_VERSION_ATLEAST +#define HB_VERSION_ATLEAST(...) 0 +#endif + int main() { std::cout << HB_VERSION_ATLEAST(%s, %s, %s) << ";" << HB_VERSION_STRING; @@ -1050,24 +1055,20 @@ int main() } """ % HARFBUZZ_MIN_VERSION, '.cpp') - # hack to avoid printed output - context.Message('Checking for HarfBuzz version >= %s... ' % HARFBUZZ_MIN_VERSION_STRING) - context.did_show_result=1 - result = ret[1].strip() - if not result: - context.Result('error, could not get version from hb.h') - return False - - items = result.split(';') - if items[0] == '1': - color_print(4,'found: HarfBuzz %s' % items[1]) - return True - - color_print(1,'\nHarfbuzz >= %s required but found ... %s' % (HARFBUZZ_MIN_VERSION_STRING,items[1])) - return False + if not ret: + context.Result('error (could not get version from hb.h)') + else: + ok_str, found_version_str = out.strip().split(';', 1) + ret = int(ok_str) + if ret: + context.Result('yes (found HarfBuzz %s)' % found_version_str) + else: + context.Result('no (found HarfBuzz %s)' % found_version_str) + return ret def harfbuzz_with_freetype_support(context): - ret = context.TryRun(""" + context.Message('Checking for HarfBuzz with freetype support... ') + ret, out = context.TryRun(""" #include "harfbuzz/hb-ft.h" #include @@ -1078,11 +1079,8 @@ int main() } """, '.cpp') - context.Message('Checking for HarfBuzz with freetype support\n') - context.Result(ret[0]) - if ret[0]: - return True - return False + context.Result(ret) + return ret def boost_regex_has_icu(context): if env['RUNTIME_LINK'] == 'static': From a17de02ce4145e1fe8d135b168405de3b8cf628c Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Wed, 27 Jun 2018 23:04:39 +0200 Subject: [PATCH 2/5] SConstruct: fixup ICU min version check - "Say what you mean." The check is for version >= 4.0, not 4.2 - call .Message before .TryRun - don't silence .Result --- SConstruct | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/SConstruct b/SConstruct index 1af27aedf..f3cb2716a 100644 --- a/SConstruct +++ b/SConstruct @@ -1008,8 +1008,9 @@ int main() context.Result(ret) return ret -def icu_at_least_four_two(context): - ret = context.TryRun(""" +def icu_at_least(context, min_version_str): + context.Message('Checking for ICU version >= %s... ' % min_version_str) + ret, out = context.TryRun(""" #include #include @@ -1021,20 +1022,19 @@ int main() } """, '.cpp') - # hack to avoid printed output - context.Message('Checking for ICU version >= 4.2... ') - context.did_show_result=1 - result = ret[1].strip() - if not result: - context.Result('error, could not get major and minor version from unicode/uversion.h') + try: + found_version_str = out.strip() + found_version = tuple(map(int, found_version_str.split('.'))) + min_version = tuple(map(int, min_version_str.split('.'))) + except: + context.Result('error (could not get version from unicode/uversion.h)') return False - major, minor = map(int,result.split('.')) - if major >= 4 and minor >= 0: - color_print(4,'found: icu %s' % result) + if found_version >= min_version: + context.Result('yes (found ICU %s)' % found_version_str) return True - color_print(1,'\nFound insufficient icu version... %s' % result) + context.Result('no (found ICU %s)' % found_version_str) return False def harfbuzz_version(context): @@ -1204,7 +1204,7 @@ conf_tests = { 'prioritize_paths' : prioritize_paths, 'ogr_enabled' : ogr_enabled, 'get_pkg_lib' : get_pkg_lib, 'rollback_option' : rollback_option, - 'icu_at_least_four_two' : icu_at_least_four_two, + 'icu_at_least' : icu_at_least, 'harfbuzz_version' : harfbuzz_version, 'harfbuzz_with_freetype_support': harfbuzz_with_freetype_support, 'boost_regex_has_icu' : boost_regex_has_icu, @@ -1526,7 +1526,7 @@ if not preconfigured: else: if libname == env['ICU_LIB_NAME']: if env['ICU_LIB_NAME'] not in env['MISSING_DEPS']: - if not conf.icu_at_least_four_two(): + if not conf.icu_at_least("4.0"): # expression_string.cpp and map.cpp use fromUTF* function only available in >= ICU 4.2 env['MISSING_DEPS'].append(env['ICU_LIB_NAME']) elif libname == 'harfbuzz': From 16eb8703033d50615ab7a0390eec4126c2a4f389 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Wed, 27 Jun 2018 23:09:42 +0200 Subject: [PATCH 3/5] SConstruct: fixup config.log message order - always call .Message before .TryRun - always unpack .TryRun result tuple --- SConstruct | 73 ++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/SConstruct b/SConstruct index f3cb2716a..6d8bf3c7e 100644 --- a/SConstruct +++ b/SConstruct @@ -812,7 +812,7 @@ def CheckIcuData(context, silent=False): if not silent: context.Message('Checking for ICU data directory...') - ret = context.TryRun(""" + ret, out = context.TryRun(""" #include #include @@ -829,9 +829,10 @@ int main() { """, '.cpp') if silent: context.did_show_result=1 - if ret[0]: - context.Result('u_getDataDirectory returned %s' % ret[1]) - return ret[1].strip() + if ret: + value = out.strip() + context.Result('u_getDataDirectory returned %s' % value) + return value else: ret = call("icu-config --icudatadir", silent=True) if ret: @@ -845,8 +846,8 @@ int main() { def CheckGdalData(context, silent=False): if not silent: - context.Message('Checking for GDAL data directory...') - ret = context.TryRun(""" + context.Message('Checking for GDAL data directory... ') + ret, out = context.TryRun(""" #include "cpl_config.h" #include @@ -857,19 +858,20 @@ int main() { } """, '.cpp') + value = out.strip() if silent: context.did_show_result=1 - if ret[0]: - context.Result('GDAL_PREFIX returned %s' % ret[1]) + if ret: + context.Result('GDAL_PREFIX returned %s' % value) else: context.Result('Failed to detect (mapnik-config will have null value)') - return ret[1].strip() + return value def CheckProjData(context, silent=False): if not silent: context.Message('Checking for PROJ_LIB directory...') - ret = context.TryRun(""" + ret, out = context.TryRun(""" // This is narly, could eventually be replaced using https://github.com/OSGeo/proj.4/pull/551] #include @@ -919,20 +921,21 @@ int main() { } """, '.cpp') + value = out.strip() if silent: context.did_show_result=1 - if ret[0]: - context.Result('pj_open_lib returned %s' % ret[1]) + if ret: + context.Result('pj_open_lib returned %s' % value) else: context.Result('Failed to detect (mapnik-config will have null value)') - return ret[1].strip() + return value def CheckCairoHasFreetype(context, silent=False): if not silent: context.Message('Checking for cairo freetype font support ... ') context.env.AppendUnique(CPPPATH=copy(env['CAIRO_CPPPATHS'])) - ret = context.TryRun(""" + ret, out = context.TryRun(""" #include @@ -945,7 +948,7 @@ int main() #endif } -""", '.cpp')[0] +""", '.cpp') if silent: context.did_show_result=1 context.Result(ret) @@ -972,7 +975,7 @@ int main() return ret def GetBoostLibVersion(context): - ret = context.TryRun(""" + ret, out = context.TryRun(""" #include #include @@ -987,8 +990,8 @@ return 0; """, '.cpp') # hack to avoid printed output context.did_show_result=1 - context.Result(ret[0]) - return ret[1].strip() + context.Result(ret) + return out.strip() def CheckBoostScopedEnum(context, silent=False): if not silent: @@ -1089,7 +1092,8 @@ def boost_regex_has_icu(context): if lib_name in context.env['LIBS']: context.env['LIBS'].remove(lib_name) context.env.Append(LIBS=lib_name) - ret = context.TryRun(""" + context.Message('Checking if boost_regex was built with ICU unicode support... ') + ret, out = context.TryRun(""" #include #include @@ -1109,11 +1113,8 @@ int main() } """, '.cpp') - context.Message('Checking if boost_regex was built with ICU unicode support... ') - context.Result(ret[0]) - if ret[0]: - return True - return False + context.Result(ret) + return ret def sqlite_has_rtree(context, silent=False): """ check an sqlite3 install has rtree support. @@ -1122,7 +1123,9 @@ def sqlite_has_rtree(context, silent=False): http://www.sqlite.org/c3ref/compileoption_get.html """ - ret = context.TryRun(""" + if not silent: + context.Message('Checking if SQLite supports RTREE... ') + ret, out = context.TryRun(""" #include #include @@ -1154,17 +1157,15 @@ int main() } """, '.c') - if not silent: - context.Message('Checking if SQLite supports RTREE... ') if silent: context.did_show_result=1 - context.Result(ret[0]) - if ret[0]: - return True - return False + context.Result(ret) + return ret def supports_cxx14(context,silent=False): - ret = context.TryRun(""" + if not silent: + context.Message('Checking if compiler (%s) supports -std=c++14 flag... ' % context.env.get('CXX','CXX')) + ret, out = context.TryRun(""" int main() { @@ -1176,14 +1177,10 @@ int main() } """, '.cpp') - if not silent: - context.Message('Checking if compiler (%s) supports -std=c++14 flag... ' % context.env.get('CXX','CXX')) if silent: context.did_show_result=1 - context.Result(ret[0]) - if ret[0]: - return True - return False + context.Result(ret) + return ret From 89d0c6da192b5bb338086a2f97faa353b6b970ac Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Fri, 29 Jun 2018 16:24:04 +0200 Subject: [PATCH 4/5] SConstruct: change rollback_option to free function It shouldn't be a conftest. First, it doesn't act like one. Second, calling it as conf.rollback_option from within another conftest before calling context.Result confuses scons, it doesn't expect conftests to be nested and reports "error: no result" for the outer one as soon as the inner is called. --- SConstruct | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/SConstruct b/SConstruct index 6d8bf3c7e..3820c3114 100644 --- a/SConstruct +++ b/SConstruct @@ -491,6 +491,12 @@ for opt in opts.options: if opt.key not in pickle_store: pickle_store.append(opt.key) +def rollback_option(env, variable): + global opts + for item in opts.options: + if item.key == variable: + env[variable] = item.default + # Method of adding configure behavior to Scons adapted from: # http://freeorion.svn.sourceforge.net/svnroot/freeorion/trunk/FreeOrion/SConstruct preconfigured = False @@ -631,7 +637,7 @@ def parse_config(context, config, checks='--libs --cflags'): # optional deps... if tool not in env['SKIPPED_DEPS']: env['SKIPPED_DEPS'].append(tool) - conf.rollback_option(config) + rollback_option(env, config) else: # freetype and libxml2, not optional if tool not in env['MISSING_DEPS']: env['MISSING_DEPS'].append(tool) @@ -681,7 +687,7 @@ def parse_pg_config(context, config): env.Append(LIBS = lpq) else: env['SKIPPED_DEPS'].append(tool) - conf.rollback_option(config) + rollback_option(env, config) context.Result( ret ) return ret @@ -695,13 +701,6 @@ def ogr_enabled(context): context.Result( ret ) return ret -def rollback_option(context,variable): - global opts - env = context.env - for item in opts.options: - if item.key == variable: - env[variable] = item.default - def FindBoost(context, prefixes, thread_flag): """Routine to auto-find boost header dir, lib dir, and library naming structure. @@ -1200,7 +1199,6 @@ conf_tests = { 'prioritize_paths' : prioritize_paths, 'parse_pg_config' : parse_pg_config, 'ogr_enabled' : ogr_enabled, 'get_pkg_lib' : get_pkg_lib, - 'rollback_option' : rollback_option, 'icu_at_least' : icu_at_least, 'harfbuzz_version' : harfbuzz_version, 'harfbuzz_with_freetype_support': harfbuzz_with_freetype_support, From b417ddf32db3f35ed1757aaa97a04809594cda8e Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Fri, 29 Jun 2018 16:43:33 +0200 Subject: [PATCH 5/5] SConstruct: shortest_name is a one-liner --- SConstruct | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/SConstruct b/SConstruct index 3820c3114..93b9f7245 100644 --- a/SConstruct +++ b/SConstruct @@ -188,13 +188,6 @@ def create_uninstall_target(env, path, is_glob=False): ]) env.Alias("uninstall", "uninstall-"+path) -def shortest_name(libs): - name = '-'*200 - for lib in libs: - if len(name) > len(lib): - name = lib - return name - def rm_path(item,set,_env): for i in _env[set]: if i.startswith(item): @@ -726,7 +719,7 @@ def FindBoost(context, prefixes, thread_flag): if len(libItems) >= 1 and len(incItems) >= 1: BOOST_LIB_DIR = os.path.dirname(libItems[0]) BOOST_INCLUDE_DIR = incItems[0].rstrip('boost/') - shortest_lib_name = shortest_name(libItems) + shortest_lib_name = min(libItems, key=len) match = re.search(r'%s(.*)\..*' % search_lib, shortest_lib_name) if hasattr(match,'groups'): BOOST_APPEND = match.groups()[0]