Use base32 instead of base64+extended-identifiers
Extended identifiers have proved to cause more problems than they solve. Switch to base32 which, while less commonly supported, is available in Python and uses an alphabet that is almost a subset of the C identifier alphabet. Padding characters are still a problem, but can be remapped to a valid C identifier that is not a valid base32 character.
This commit is contained in:
parent
e20152da11
commit
e2a108bbf5
43
SConstruct
43
SConstruct
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
# needed imports
|
# needed imports
|
||||||
from collections import (defaultdict, Counter as collections_counter)
|
from collections import (defaultdict, Counter as collections_counter)
|
||||||
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import errno
|
import errno
|
||||||
import itertools
|
import itertools
|
||||||
|
@ -139,7 +140,7 @@ class Git(StaticSubprocess):
|
||||||
self.revparse_HEAD = revparse_HEAD
|
self.revparse_HEAD = revparse_HEAD
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'ComputedExtraVersion(%r,%r,%r,%r)' % (self.describe, self.status, self.diffstat_HEAD, self.revparse_HEAD)
|
return 'ComputedExtraVersion(%r,%r,%r,%r)' % (self.describe, self.status, self.diffstat_HEAD, self.revparse_HEAD)
|
||||||
UnknownExtraVersion = ComputedExtraVersion('', None, None, None)
|
UnknownExtraVersion = ComputedExtraVersion(None, None, None, None)
|
||||||
# None when unset. Instance of ComputedExtraVersion once cached.
|
# None when unset. Instance of ComputedExtraVersion once cached.
|
||||||
__computed_extra_version = None
|
__computed_extra_version = None
|
||||||
__path_git = None
|
__path_git = None
|
||||||
|
@ -1466,25 +1467,6 @@ variables to their default-constructed value.
|
||||||
raise SCons.Errors.StopError("C++ compiler errors on {} initialization, even with -Wno-missing-field-initializers.")
|
raise SCons.Errors.StopError("C++ compiler errors on {} initialization, even with -Wno-missing-field-initializers.")
|
||||||
|
|
||||||
@_custom_test
|
@_custom_test
|
||||||
def check_compiler_extended_identifiers(self,context,main=r'''
|
|
||||||
#define DXX_RENAME_IDENTIFIER2(I,N) I##$##N
|
|
||||||
#define DXX_RENAME_IDENTIFIER(I,N) DXX_RENAME_IDENTIFIER2(I,N)
|
|
||||||
#define DXX_extended a\u012b\u012f\u013d
|
|
||||||
#define var DXX_RENAME_IDENTIFIER(var, DXX_extended)
|
|
||||||
int var;
|
|
||||||
(void)var;
|
|
||||||
#undef var
|
|
||||||
#undef DXX_extended
|
|
||||||
#undef DXX_RENAME_IDENTIFIER
|
|
||||||
#undef DXX_RENAME_IDENTIFIER2
|
|
||||||
''',_successflags={'CXXFLAGS' : ['-fextended-identifiers']}):
|
|
||||||
Compile = self.Compile
|
|
||||||
if Compile(context, text='', main=main, msg='whether compiler accepts extended identifiers by default') or \
|
|
||||||
Compile(context, text='', main=main, msg='whether compiler accepts extended identifiers with -fextended-identifiers', successflags=_successflags):
|
|
||||||
return
|
|
||||||
user_settings = self.user_settings
|
|
||||||
user_settings._dxx_extended_identifiers = user_settings._dxx_disable_extended_identifiers
|
|
||||||
@_custom_test
|
|
||||||
def check_attribute_error(self,context):
|
def check_attribute_error(self,context):
|
||||||
"""
|
"""
|
||||||
Test whether the compiler accepts and properly implements gcc's function
|
Test whether the compiler accepts and properly implements gcc's function
|
||||||
|
@ -3494,9 +3476,6 @@ class DXXCommon(LazyObjectConstructor):
|
||||||
_default_prefix = '/usr/local'
|
_default_prefix = '/usr/local'
|
||||||
__stdout_is_not_a_tty = None
|
__stdout_is_not_a_tty = None
|
||||||
__has_git_dir = None
|
__has_git_dir = None
|
||||||
# +/=
|
|
||||||
_dxx_extended_identifiers = (r'\u012b', r'\u012f', r'\u013d')
|
|
||||||
_dxx_disable_extended_identifiers = ('_2b', '_2f', '_3d')
|
|
||||||
def default_poison(self):
|
def default_poison(self):
|
||||||
return 'overwrite' if self.debug else 'none'
|
return 'overwrite' if self.debug else 'none'
|
||||||
def default_builddir(self):
|
def default_builddir(self):
|
||||||
|
@ -4175,14 +4154,15 @@ class DXXCommon(LazyObjectConstructor):
|
||||||
return '\\"%s\\"' % r
|
return '\\"%s\\"' % r
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _encode_cppdefine_for_identifier(user_settings,s,b2a_base64=binascii.b2a_base64):
|
def _encode_cppdefine_for_identifier(s,b32encode=base64.b32encode):
|
||||||
extended_identifiers = user_settings._dxx_extended_identifiers
|
# Identifiers cannot contain `=`; `z` is not generated by
|
||||||
return '"%s"' % (b2a_base64(s.encode()) \
|
# b32encode, so use it in place of the pad character.
|
||||||
|
if not s:
|
||||||
|
return s
|
||||||
|
return (b32encode(s.encode()) \
|
||||||
.rstrip() \
|
.rstrip() \
|
||||||
.decode() \
|
.decode() \
|
||||||
.replace('+', extended_identifiers[0]) \
|
.replace('=', 'z') \
|
||||||
.replace('/', extended_identifiers[1]) \
|
|
||||||
.replace('=', extended_identifiers[2]) \
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare_environment(self):
|
def prepare_environment(self):
|
||||||
|
@ -4946,7 +4926,10 @@ class DXXProgram(DXXCommon):
|
||||||
static_archive_construction = self.static_archive_construction[user_settings.builddir]
|
static_archive_construction = self.static_archive_construction[user_settings.builddir]
|
||||||
objects = static_archive_construction.get_objects_common()
|
objects = static_archive_construction.get_objects_common()
|
||||||
git_describe_version = Git.compute_extra_version() if user_settings.git_describe_version else Git.UnknownExtraVersion
|
git_describe_version = Git.compute_extra_version() if user_settings.git_describe_version else Git.UnknownExtraVersion
|
||||||
env.__dxx_CPPDEFINE_git_version = [('DXX_git_commit', git_describe_version.revparse_HEAD), ('DXX_git_describe', self._encode_cppdefine_for_identifier(user_settings,git_describe_version.describe))]
|
env.__dxx_CPPDEFINE_git_version = [
|
||||||
|
('DXX_git_commit', git_describe_version.revparse_HEAD),
|
||||||
|
('DXX_git_describe', self._encode_cppdefine_for_identifier(git_describe_version.describe))
|
||||||
|
]
|
||||||
objects.extend(self.get_objects_common())
|
objects.extend(self.get_objects_common())
|
||||||
if user_settings.sdlmixer:
|
if user_settings.sdlmixer:
|
||||||
objects.extend(static_archive_construction.get_objects_arch_sdlmixer())
|
objects.extend(static_archive_construction.get_objects_arch_sdlmixer())
|
||||||
|
|
|
@ -429,7 +429,7 @@ namespace dsx {
|
||||||
#define DXX_RENAME_IDENTIFIER2(I,N) I##$##N
|
#define DXX_RENAME_IDENTIFIER2(I,N) I##$##N
|
||||||
#define DXX_RENAME_IDENTIFIER(I,N) DXX_RENAME_IDENTIFIER2(I,N)
|
#define DXX_RENAME_IDENTIFIER(I,N) DXX_RENAME_IDENTIFIER2(I,N)
|
||||||
#define argc DXX_RENAME_IDENTIFIER(argc_gc, DXX_git_commit)
|
#define argc DXX_RENAME_IDENTIFIER(argc_gc, DXX_git_commit)
|
||||||
#define argv DXX_RENAME_IDENTIFIER(argv_gd, DXX_git_describe)
|
#define argv DXX_RENAME_IDENTIFIER(argv_gd$b32, DXX_git_describe)
|
||||||
|
|
||||||
// DESCENT by Parallax Software
|
// DESCENT by Parallax Software
|
||||||
// DESCENT II by Parallax Software
|
// DESCENT II by Parallax Software
|
||||||
|
|
Loading…
Reference in a new issue