From 5b7fb9c4025c626453c48d7d67a4afffad1d8599 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 2 Oct 2022 19:51:36 +0000 Subject: [PATCH] Reduce use of quotes for passing vers_id defines Windows shells interpret quoting differently from Linux shells, causing some of the generated strings to have ugly escape sequences in them. Switch to passing the defined values as lists of character codes, so that no quoting is needed. This makes the command line uglier, but produces more readable strings in the generated program. --- SConstruct | 29 +++++++++++++++++++++-------- similar/main/vers_id.cpp | 9 +++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/SConstruct b/SConstruct index aa40903c3..d8b5343f9 100644 --- a/SConstruct +++ b/SConstruct @@ -4371,6 +4371,19 @@ class DXXCommon(LazyObjectConstructor): prior = False return '\\"%s\\"' % r + @staticmethod + def _quote_cppdefine_as_char_initializer(k,v): + # - Format the input as `name=value` + # - map(ord, formatted_string) to produce a map object that yields an + # iterable of integers representing the character codes of the + # formatted string + # - map(str, inner_map) to convert the iterable of integers to an + # iterable of strings, where each string is the decimal digits of an + # input integer + # - ','.join(outer_map) to convert the iterable of strings to a + # comma-separated string + return ('DESCENT_%s' % k), ','.join(map(str, map(ord, '%s=%r' % (k, v)))) + @staticmethod def _encode_cppdefine_for_identifier(s,b32encode=base64.b32encode): # Identifiers cannot contain `=`; `z` is not generated by @@ -5181,8 +5194,8 @@ class DXXProgram(DXXCommon): extra_version += git_describe_version_describe_output get_version_head = StaticSubprocess.get_version_head ld_path = ToolchainInformation.get_tool_path(env, 'ld')[1] - _quote_cppdefine = self._quote_cppdefine - versid_cppdefines.extend([('DESCENT_%s' % k, _quote_cppdefine(env.get(k, ''))) for k in versid_build_environ]) + _quote_cppdefine_as_char_initializer = self._quote_cppdefine_as_char_initializer + versid_cppdefines.extend([_quote_cppdefine_as_char_initializer(k, env.get(k, '')) for k in versid_build_environ]) versid_cppdefines.extend(( # VERSION_EXTRA is special. Format it as a string so that # it can be pasted into g_descent_version (in vers_id.cpp) @@ -5190,15 +5203,15 @@ class DXXProgram(DXXCommon): # banner. Since it is pasted into g_descent_version, it is # NOT included in versid_build_environ as an independent # field. - ('DESCENT_VERSION_EXTRA', _quote_cppdefine(extra_version, f=str)), - ('DESCENT_CXX_version', _quote_cppdefine(get_version_head(env['CXX']))), - ('DESCENT_LINK', _quote_cppdefine(ld_path.decode())), - ('DESCENT_git_status', _quote_cppdefine(git_describe_version.status)), - ('DESCENT_git_diffstat', _quote_cppdefine(git_describe_version.diffstat_HEAD)), + ('DESCENT_VERSION_EXTRA', ','.join(map(str, map(ord, extra_version)))), + _quote_cppdefine_as_char_initializer('CXX_version', get_version_head(env['CXX'])), + _quote_cppdefine_as_char_initializer('LINK', ld_path.decode()), + _quote_cppdefine_as_char_initializer('git_status', git_describe_version.status), + _quote_cppdefine_as_char_initializer('git_diffstat', git_describe_version.diffstat_HEAD), )) if ld_path: versid_cppdefines.append( - ('DESCENT_LINK_version', _quote_cppdefine(get_version_head(ld_path))), + _quote_cppdefine_as_char_initializer('LINK_version', get_version_head(ld_path)) ) versid_build_environ.append('LINK_version') versid_build_environ.extend(( diff --git a/similar/main/vers_id.cpp b/similar/main/vers_id.cpp index ca34290f9..bc3ed1a43 100644 --- a/similar/main/vers_id.cpp +++ b/similar/main/vers_id.cpp @@ -8,9 +8,9 @@ #include "vers_id.h" #if defined(DXX_BUILD_DESCENT_I) -#define DXX_NAME_NUMBER "1" +#define DXX_NAME_NUMBER '1' #elif defined(DXX_BUILD_DESCENT_II) -#define DXX_NAME_NUMBER "2" +#define DXX_NAME_NUMBER '2' #else #error "Must set DXX_BUILD_DESCENT_I or DXX_BUILD_DESCENT_II" #endif @@ -23,12 +23,13 @@ #define DXX_VERSID_BUILD_TIME __TIME__ #endif -constexpr char g_descent_version[] = "D" DXX_NAME_NUMBER "X-Rebirth " DESCENT_VERSION_EXTRA; +// "D1X-Rebirth " or "D2X-Rebirth " +constexpr char g_descent_version[] = {'D', DXX_NAME_NUMBER, 'X', '-', 'R', 'e', 'b', 'i', 'r', 't', 'h', ' ', DESCENT_VERSION_EXTRA}; constexpr char g_descent_build_datetime[21] = DXX_VERSID_BUILD_DATE " " DXX_VERSID_BUILD_TIME; #ifdef DXX_RBE #define RECORD_BUILD_VARIABLE(X) extern const char g_descent_##X[]; \ - const char g_descent_##X[] __attribute_used = #X "=" DESCENT_##X; + constexpr char g_descent_##X[] __attribute_used = {DESCENT_##X}; DXX_RBE(RECORD_BUILD_VARIABLE); #endif