Skip to content

Commit e561b08

Browse files
author
Felix "xq" Queißner
committed
Adds fixes for Windows support
1 parent 5047de9 commit e561b08

File tree

5 files changed

+71
-17
lines changed

5 files changed

+71
-17
lines changed

.envrc

-2
This file was deleted.

.github/workflows/validate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-latest, macos-latest, windows-latest
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v2

src/BuildInterface.zig

+16-8
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const ContentWriter = struct {
157157
@tagName(data.format),
158158
});
159159
if (data.label) |label| {
160-
try cw.code.print(" label \"{}\"\n", .{
160+
try cw.code.print(" label {}\n", .{
161161
fmtPath(label),
162162
});
163163
}
@@ -172,16 +172,16 @@ const ContentWriter = struct {
172172
fn renderFileSystemTree(cw: ContentWriter, fs: FileSystem) !void {
173173
for (fs.items) |item| {
174174
switch (item) {
175-
.empty_dir => |dir| try cw.code.print("mkdir \"{}\"\n", .{
175+
.empty_dir => |dir| try cw.code.print("mkdir {}\n", .{
176176
fmtPath(dir),
177177
}),
178178

179-
.copy_dir => |copy| try cw.code.print("copy-dir \"{}\" {}\n", .{
179+
.copy_dir => |copy| try cw.code.print("copy-dir {} {}\n", .{
180180
fmtPath(copy.destination),
181181
cw.fmtLazyPath(copy.source, .directory),
182182
}),
183183

184-
.copy_file => |copy| try cw.code.print("copy-file \"{}\" {}\n", .{
184+
.copy_file => |copy| try cw.code.print("copy-file {} {}\n", .{
185185
fmtPath(copy.destination),
186186
cw.fmtLazyPath(copy.source, .file),
187187
}),
@@ -226,7 +226,7 @@ const ContentWriter = struct {
226226

227227
std.debug.assert(std.fs.path.isAbsolute(full_path));
228228

229-
try writer.print("\"{}\"", .{
229+
try writer.print("{}", .{
230230
fmtPath(full_path),
231231
});
232232
},
@@ -271,9 +271,17 @@ const ContentWriter = struct {
271271
if (is_safe_word) {
272272
try writer.writeAll(path);
273273
} else {
274-
try writer.print("\"{}\"", .{
275-
std.fmt.fmtSliceEscapeLower(path),
276-
});
274+
try writer.writeAll("\"");
275+
276+
for (path) |c| {
277+
if (c == '\\') {
278+
try writer.writeAll("/");
279+
} else {
280+
try writer.print("{}", .{std.zig.fmtEscapes(&[_]u8{c})});
281+
}
282+
}
283+
284+
try writer.writeAll("\"");
277285
}
278286
}
279287
};

src/Parser.zig

+48-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub const Error = Tokenizer.Error || error{
1717
ExpectedIncludePath,
1818
UnknownDirective,
1919
OutOfMemory,
20+
InvalidEscapeSequence,
2021
};
2122

2223
pub const IO = struct {
@@ -197,11 +198,55 @@ fn resolve_value(parser: *Parser, token_type: TokenType, text: []const u8) ![]co
197198
),
198199

199200
.string => {
200-
for (text) |c| {
201+
const content_slice = text[1 .. text.len - 1];
202+
203+
const has_includes = for (content_slice) |c| {
201204
if (c == '\\')
202-
@panic("strings escapes not supported yet!");
205+
break true;
206+
} else false;
207+
208+
if (!has_includes)
209+
return content_slice;
210+
211+
var unescaped: std.ArrayList(u8) = .init(parser.arena.allocator());
212+
defer unescaped.deinit();
213+
214+
try unescaped.ensureTotalCapacityPrecise(content_slice.len);
215+
216+
{
217+
var i: usize = 0;
218+
while (i < content_slice.len) {
219+
const c = content_slice[i];
220+
i += 1;
221+
222+
if (c != '\\') {
223+
try unescaped.append(c);
224+
continue;
225+
}
226+
227+
if (i == content_slice.len)
228+
return error.InvalidEscapeSequence;
229+
230+
const esc_code = content_slice[i];
231+
i += 1;
232+
233+
errdefer std.log.err("invalid escape sequence: \\{s}", .{[_]u8{esc_code}});
234+
235+
switch (esc_code) {
236+
'r' => try unescaped.append('\r'),
237+
'n' => try unescaped.append('\n'),
238+
't' => try unescaped.append('\t'),
239+
'\\' => try unescaped.append('\\'),
240+
'\"' => try unescaped.append('\"'),
241+
'\'' => try unescaped.append('\''),
242+
'e' => try unescaped.append('\x1B'),
243+
244+
else => return error.InvalidEscapeSequence,
245+
}
246+
}
203247
}
204-
return text[1 .. text.len - 1];
248+
249+
return try unescaped.toOwnedSlice();
205250
},
206251

207252
.comment, .directive, .whitespace => unreachable,

src/dim.zig

+6-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ pub fn main() !u8 {
180180
pub fn declare_file_dependency(path: []const u8) !void {
181181
const deps_file = global_deps_file orelse return;
182182

183-
const stat = try std.fs.cwd().statFile(path);
183+
const stat = std.fs.cwd().statFile(path) catch |err| switch (err) {
184+
error.IsDir => return,
185+
else => |e| return e,
186+
};
184187
if (stat.kind != .directory) {
185188
try deps_file.writeAll(" \\\n ");
186189
try deps_file.writeAll(path);
@@ -549,8 +552,8 @@ pub const FileName = struct {
549552
const realpath = name.root_dir.realpath(
550553
name.rel_path,
551554
&buffer,
552-
) catch @panic("failed to determine real path for dependency file!");
553-
declare_file_dependency(realpath) catch @panic("Failed to write to deps file!");
555+
) catch |e| std.debug.panic("failed to determine real path for dependency file: {s}", .{@errorName(e)});
556+
declare_file_dependency(realpath) catch |e| std.debug.panic("Failed to write to deps file: {s}", .{@errorName(e)});
554557
}
555558

556559
pub const GetSizeError = error{ FileNotFound, InvalidPath, IoError };

0 commit comments

Comments
 (0)