4848Rtt_Root = ''
4949Env = None
5050
51+ def _as_unicode (value ):
52+ try :
53+ unicode
54+ except NameError :
55+ return value if isinstance (value , str ) else str (value )
56+
57+ if isinstance (value , unicode ):
58+ return value
59+
60+ for encoding in (sys .getfilesystemencoding (), 'utf-8' ):
61+ if not encoding :
62+ continue
63+ try :
64+ return value .decode (encoding )
65+ except (AttributeError , UnicodeDecodeError ):
66+ pass
67+
68+ return unicode (value )
69+
70+ def _check_invalid_option_dashes ():
71+ # Reject command line options typed with Unicode dash lookalikes.
72+ invalid_dashes = (
73+ u'\u2010 ' , u'\u2011 ' , u'\u2012 ' , u'\u2013 ' , u'\u2014 ' ,
74+ u'\u2015 ' , u'\u2212 ' , u'\ufe58 ' , u'\ufe63 ' , u'\uff0d ' ,
75+ )
76+
77+ entries = []
78+ entries .extend ((key , value ) for key , value in ARGUMENTS .items ())
79+ entries .extend ((target , None ) for target in COMMAND_LINE_TARGETS )
80+
81+ for key , value in entries :
82+ option = _as_unicode (key )
83+ normalized = option
84+ for dash in invalid_dashes :
85+ normalized = normalized .replace (dash , u'-' )
86+
87+ if option != normalized and normalized .startswith (u'-' ):
88+ if value is not None :
89+ display = u'%s=%s' % (option , _as_unicode (value ))
90+ hint = u'%s=%s' % (normalized , _as_unicode (value ))
91+ else :
92+ display = option
93+ hint = normalized
94+
95+ print ("Invalid command line option: %s" % display )
96+ print ("Please use ASCII '-' instead: %s" % hint )
97+ sys .exit (1 )
98+
5199def PrepareBuilding (env , root_directory , has_libcpu = False , remove_components = []):
52100
53101 global BuildOptions
@@ -56,6 +104,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
56104 global Rtt_Root
57105
58106 AddOptions ()
107+ _check_invalid_option_dashes ()
59108
60109 Env = env
61110 # export the default environment
0 commit comments