diff options
| author | PhaseMage <phasemage@live.com> | 2022-01-30 11:27:52 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-30 21:27:52 +0200 |
| commit | 8a97807d6812f62db4c3088fecd04a98a84b9943 (patch) | |
| tree | a7658f7e1d412aa5bcede21c21b455b939074174 /test/cli.zig | |
| parent | 336aa3c332067ad7109a60a1276ce7a8f193ed0e (diff) | |
| download | zig-8a97807d6812f62db4c3088fecd04a98a84b9943.tar.gz zig-8a97807d6812f62db4c3088fecd04a98a84b9943.zip | |
Full response file (*.rsp) support
I hit the "quotes in an RSP file" issue when trying to compile gRPC using
"zig cc". As a fun exercise, I decided to see if I could fix it myself.
I'm fully open to this code being flat-out rejected. Or I can take feedback
to fix it up.
This modifies (and renames) _ArgIteratorWindows_ in process.zig such that
it works with arbitrary strings (or the contents of an RSP file).
In main.zig, this new _ArgIteratorGeneral_ is used to address the "TODO"
listed in _ClangArgIterator_.
This change closes #4833.
**Pros:**
- It has the nice attribute of handling "RSP file" arguments in the same way it
handles "cmd_line" arguments.
- High Performance, minimal allocations
- Fixed bug in previous _ArgIteratorWindows_, where final trailing backslashes
in a command line were entirely dropped
- Added a test case for the above bug
- Harmonized the _ArgIteratorXxxx._initWithAllocator()_ and _next()_ interface
across Windows/Posix/Wasi (Moved Windows errors to _initWithAllocator()_
rather than _next()_)
- Likely perf benefit on Windows by doing _utf16leToUtf8AllocZ()_ only once
for the entire cmd_line
**Cons:**
- Breaking Change in std library on Windows: Call
_ArgIterator.initWithAllocator()_ instead of _ArgIterator.init()_
- PhaseMage is new with contributions to Zig, might need a lot of hand-holding
- PhaseMage is a Windows person, non-Windows stuff will need to be double-checked
**Testing Done:**
- Wrote a few new test cases in process.zig
- zig.exe build test -Dskip-release (no new failures seen)
- zig cc now builds gRPC without error
Diffstat (limited to 'test/cli.zig')
| -rw-r--r-- | test/cli.zig | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/test/cli.zig b/test/cli.zig index c99c86b008..5df5696919 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -11,18 +11,17 @@ pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); - var arg_it = process.args(); + a = arena.allocator(); + var arg_it = try process.argsWithAllocator(a); // skip my own exe name _ = arg_it.skip(); - a = arena.allocator(); - - const zig_exe_rel = (try arg_it.next(a)) orelse { + const zig_exe_rel = arg_it.next() orelse { std.debug.print("Expected first argument to be path to zig compiler\n", .{}); return error.InvalidArgs; }; - const cache_root = (try arg_it.next(a)) orelse { + const cache_root = arg_it.next() orelse { std.debug.print("Expected second argument to be cache root directory path\n", .{}); return error.InvalidArgs; }; |
