Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Windows port: pass arguments through a file

Convert POSIX style path names to Windows path names. Normally, this
conversion is done for us by MSYS when spawning a non-MSYS binary from
an MSYS binary, but we're completely sidestepping the usual argv handling
due to the 8192 character command line length limit imposed by CMD.EXE (or
more likely the API used by MSYS bash)...

https://bugzilla.gnome.org/show_bug.cgi?id=620566
  • Loading branch information...
commit d97438a537ada5cf087fb093711f58c510e7cc0f 1 parent b2804a3
@dieterv authored
Showing with 59 additions and 0 deletions.
  1. +16 −0 giscanner/scannermain.py
  2. +43 −0 giscanner/utils.py
View
16 giscanner/scannermain.py
@@ -61,6 +61,11 @@ def get_windows_option_group(parser):
group.add_option("-m", help="some machine dependent option",
action="append", dest='m_option',
default=[])
+ parser.add_option("", "--args-file",
+ action="store", dest="args_file", default=None,
+ help="""File holding real arguments for this process. This option is
+used to work around the 8192 character command line length limit imposed by CMD.EXE when
+building various packages' (notably GTK+) introspection support under MSYS/MinGW""")
return group
@@ -388,6 +393,17 @@ def scanner_main(args):
parser = _get_option_parser()
(options, args) = parser.parse_args(args)
+ if os.environ.get('MSYSTEM') == 'MINGW32' and options.args_file:
+ # Read real arguments from file
+ f = open(options.args_file, "rb")
+ realargs = f.read().strip()
+ f.close()
+
+ realargs = utils.msyspaths2windows(realargs)
+ realargs.insert(0, args[0])
+
+ (options, args) = parser.parse_args(realargs)
+
if options.passthrough_gir:
passthrough_gir(options.passthrough_gir, sys.stdout)
if options.test_codegen:
View
43 giscanner/utils.py
@@ -150,3 +150,46 @@ def __init__(self, args, **kwargs):
def msysjoin(a, *p):
path = _join(a, *p).replace('\\', '/')
return path
+
+def msyspaths2windows(args):
+ """"
+ Converts POSIX path names to Windows path names. Normally, this
+ conversion is done for us by MSYS when spawning a non-MSYS binary from
+ an MSYS binary, but we're completely sidestepping the usual argv handling
+ due to the 8192 character command line length limit imposed by CMD.EXE...
+
+ Note: Let's hope none of the split args itself is larger than the limit.
+ Note: This function is known to be extremely slow, but at least it's results
+ are correct.
+ """
+
+ # Split args on space character, unless the space is inside double quotes
+ splitargs = []
+ tmparg = ''
+ quotes = False
+
+ for char in args:
+ if char == '"':
+ if quotes:
+ quotes = False
+ else:
+ quotes = True
+
+ if char == ' ' and not quotes:
+ if tmparg != '': # Prevent empty arguments, keeps things tidy
+ splitargs.append(tmparg)
+ tmparg = ''
+ else:
+ tmparg += char
+
+ if tmparg != '': # Don't forget to append the last argument
+ splitargs.append(tmparg)
+
+ # Now we can safely convert paths
+ realargs = []
+
+ for arg in splitargs:
+ output = subprocess.check_output(["cmd", "//C", "echo", arg.strip().replace('"', '\\"')])
+ realargs.append(output.strip())
+
+ return realargs
Please sign in to comment.
Something went wrong with that request. Please try again.