authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-06 22:53:34-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-06 22:53:34-05:00
logc804ae2d6b1f62d9cb45db2613d36ef14ac539a0
tree28f614cb43731aef7c018b1d094f4d288d6635fa
parent8a5d3e2eaf72195993e4932bfda66d08a36c6064
parent1e60ca4b752a61e26067b4893be623442836ec6f
signature Commit is signed but in an unrecognized format.

Merge branch 'zig-backport-std.os.path' of https://github.com/kristate/zig into kristate-zig-backport-std.os.path


16 files changed, 114 insertions(+), 91 deletions(-)

build.zig+8-8
......@@ -16,7 +16,7 @@ pub fn build(b: *Builder) !void {
1616 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
1717
1818 const rel_zig_exe = try os.path.relative(b.allocator, b.build_root, b.zig_exe);
19 const langref_out_path = os.path.join(b.allocator, b.cache_root, "langref.html") catch unreachable;
19 const langref_out_path = os.path.join(b.allocator, [][]const u8{ b.cache_root, "langref.html" }) catch unreachable;
2020 var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8{
2121 docgen_exe.getOutputPath(),
2222 rel_zig_exe,
......@@ -125,13 +125,13 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
125125 for (dep.libdirs.toSliceConst()) |lib_dir| {
126126 lib_exe_obj.addLibPath(lib_dir);
127127 }
128 const lib_dir = os.path.join(b.allocator, dep.prefix, "lib") catch unreachable;
128 const lib_dir = os.path.join(b.allocator, [][]const u8{dep.prefix, "lib"}) catch unreachable;
129129 for (dep.system_libs.toSliceConst()) |lib| {
130130 const static_bare_name = if (mem.eql(u8, lib, "curses"))
131131 ([]const u8)("libncurses.a")
132132 else
133133 b.fmt("lib{}.a", lib);
134 const static_lib_name = os.path.join(b.allocator, lib_dir, static_bare_name) catch unreachable;
134 const static_lib_name = os.path.join(b.allocator, [][]const u8{lib_dir, static_bare_name}) catch unreachable;
135135 const have_static = fileExists(static_lib_name) catch unreachable;
136136 if (have_static) {
137137 lib_exe_obj.addObjectFile(static_lib_name);
......@@ -159,7 +159,7 @@ fn fileExists(filename: []const u8) !bool {
159159
160160fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
161161 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
162 lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable);
162 lib_exe_obj.addObjectFile(os.path.join(b.allocator, [][]const u8{ cmake_binary_dir, "zig_cpp", b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()) }) catch unreachable);
163163}
164164
165165const LibraryDep = struct {
......@@ -235,8 +235,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
235235pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
236236 var it = mem.tokenize(stdlib_files, ";");
237237 while (it.next()) |stdlib_file| {
238 const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;
239 const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable;
238 const src_path = os.path.join(b.allocator, [][]const u8{"std", stdlib_file}) catch unreachable;
239 const dest_path = os.path.join(b.allocator, [][]const u8{"lib", "zig", "std", stdlib_file}) catch unreachable;
240240 b.installFile(src_path, dest_path);
241241 }
242242}
......@@ -244,8 +244,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
244244pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
245245 var it = mem.tokenize(c_header_files, ";");
246246 while (it.next()) |c_header_file| {
247 const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;
248 const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable;
247 const src_path = os.path.join(b.allocator, [][]const u8{"c_headers", c_header_file}) catch unreachable;
248 const dest_path = os.path.join(b.allocator, [][]const u8{"lib", "zig", "include", c_header_file}) catch unreachable;
249249 b.installFile(src_path, dest_path);
250250 }
251251}
doc/docgen.zig+5-5
......@@ -990,13 +990,13 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
990990 try tokenizeAndPrint(tokenizer, out, code.source_token);
991991 try out.write("</pre>");
992992 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
993 const tmp_source_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_ext);
993 const tmp_source_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_ext });
994994 try io.writeFile(tmp_source_file_name, trimmed_raw_source);
995995
996996 switch (code.id) {
997997 Code.Id.Exe => |expected_outcome| {
998998 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
999 const tmp_bin_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_bin_ext);
999 const tmp_bin_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_bin_ext });
10001000 var build_args = std.ArrayList([]const u8).init(allocator);
10011001 defer build_args.deinit();
10021002 try build_args.appendSlice([][]const u8{
......@@ -1024,7 +1024,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10241024 }
10251025 for (code.link_objects) |link_object| {
10261026 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
1027 const full_path_object = try os.path.join(allocator, tmp_dir_name, name_with_ext);
1027 const full_path_object = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_with_ext });
10281028 try build_args.append("--object");
10291029 try build_args.append(full_path_object);
10301030 try out.print(" --object {}", name_with_ext);
......@@ -1216,12 +1216,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12161216 },
12171217 Code.Id.Obj => |maybe_error_match| {
12181218 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
1219 const tmp_obj_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_obj_ext);
1219 const tmp_obj_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_obj_ext });
12201220 var build_args = std.ArrayList([]const u8).init(allocator);
12211221 defer build_args.deinit();
12221222
12231223 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
1224 const output_h_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_h_ext);
1224 const output_h_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_h_ext });
12251225
12261226 try build_args.appendSlice([][]const u8{
12271227 zig_exe,
src-self-hosted/compilation.zig+3-3
......@@ -487,7 +487,7 @@ pub const Compilation = struct {
487487 comp.name = try Buffer.init(comp.arena(), name);
488488 comp.llvm_triple = try target.getTriple(comp.arena());
489489 comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple);
490 comp.zig_std_dir = try std.os.path.join(comp.arena(), zig_lib_dir, "std");
490 comp.zig_std_dir = try std.os.path.join(comp.arena(), [][]const u8{ zig_lib_dir, "std" });
491491
492492 const opt_level = switch (build_mode) {
493493 builtin.Mode.Debug => llvm.CodeGenLevelNone,
......@@ -1198,7 +1198,7 @@ pub const Compilation = struct {
11981198 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
11991199 defer self.gpa().free(file_name);
12001200
1201 const full_path = try os.path.join(self.gpa(), tmp_dir, file_name[0..]);
1201 const full_path = try os.path.join(self.gpa(), [][]const u8{ tmp_dir, file_name[0..] });
12021202 errdefer self.gpa().free(full_path);
12031203
12041204 return Buffer.fromOwnedSlice(self.gpa(), full_path);
......@@ -1219,7 +1219,7 @@ pub const Compilation = struct {
12191219 const zig_dir_path = try getZigDir(self.gpa());
12201220 defer self.gpa().free(zig_dir_path);
12211221
1222 const tmp_dir = try os.path.join(self.arena(), zig_dir_path, comp_dir_name[0..]);
1222 const tmp_dir = try os.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] });
12231223 try os.makePath(self.gpa(), tmp_dir);
12241224 return tmp_dir;
12251225 }
src-self-hosted/introspect.zig+2-2
......@@ -8,10 +8,10 @@ const warn = std.debug.warn;
88
99/// Caller must free result
1010pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
11 const test_zig_dir = try os.path.join(allocator, test_path, "lib", "zig");
11 const test_zig_dir = try os.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
1212 errdefer allocator.free(test_zig_dir);
1313
14 const test_index_file = try os.path.join(allocator, test_zig_dir, "std", "index.zig");
14 const test_index_file = try os.path.join(allocator, [][]const u8{ test_zig_dir, "std", "index.zig" });
1515 defer allocator.free(test_index_file);
1616
1717 var file = try os.File.openRead(test_index_file);
src-self-hosted/libc_installation.zig+4-4
......@@ -230,7 +230,7 @@ pub const LibCInstallation = struct {
230230 while (path_i < search_paths.len) : (path_i += 1) {
231231 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
232232 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
233 const stdlib_path = try std.os.path.join(loop.allocator, search_path, "stdlib.h");
233 const stdlib_path = try std.os.path.join(loop.allocator, [][]const u8{ search_path, "stdlib.h" });
234234 defer loop.allocator.free(stdlib_path);
235235
236236 if (try fileExists(stdlib_path)) {
......@@ -254,7 +254,7 @@ pub const LibCInstallation = struct {
254254 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
255255 try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);
256256
257 const stdlib_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "stdlib.h");
257 const stdlib_path = try std.os.path.join(loop.allocator, [][]const u8{ result_buf.toSliceConst(), "stdlib.h" });
258258 defer loop.allocator.free(stdlib_path);
259259
260260 if (try fileExists(stdlib_path)) {
......@@ -283,7 +283,7 @@ pub const LibCInstallation = struct {
283283 builtin.Arch.aarch64v8 => try stream.write("arm"),
284284 else => return error.UnsupportedArchitecture,
285285 }
286 const ucrt_lib_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "ucrt.lib");
286 const ucrt_lib_path = try std.os.path.join(loop.allocator, [][]const u8{ result_buf.toSliceConst(), "ucrt.lib" });
287287 defer loop.allocator.free(ucrt_lib_path);
288288 if (try fileExists(ucrt_lib_path)) {
289289 self.lib_dir = result_buf.toOwnedSlice();
......@@ -358,7 +358,7 @@ pub const LibCInstallation = struct {
358358 builtin.Arch.aarch64v8 => try stream.write("arm\\"),
359359 else => return error.UnsupportedArchitecture,
360360 }
361 const kernel32_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "kernel32.lib");
361 const kernel32_path = try std.os.path.join(loop.allocator, [][]const u8{ result_buf.toSliceConst(), "kernel32.lib" });
362362 defer loop.allocator.free(kernel32_path);
363363 if (try fileExists(kernel32_path)) {
364364 self.kernel32_lib_dir = result_buf.toOwnedSlice();
src-self-hosted/link.zig+1-1
......@@ -315,7 +315,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
315315}
316316
317317fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
318 const full_path = try std.os.path.join(&ctx.arena.allocator, dirname, basename);
318 const full_path = try std.os.path.join(&ctx.arena.allocator, [][]const u8{ dirname, basename });
319319 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
320320 try ctx.args.append(full_path_with_null.ptr);
321321}
src-self-hosted/main.zig+1-1
......@@ -757,7 +757,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
757757 var group = event.Group(FmtError!void).init(fmt.loop);
758758 while (try dir.next()) |entry| {
759759 if (entry.kind == std.os.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
760 const full_path = try os.path.join(fmt.loop.allocator, file_path, entry.name);
760 const full_path = try os.path.join(fmt.loop.allocator, [][]const u8{ file_path, entry.name });
761761 try group.call(fmtPath, fmt, full_path, check_mode);
762762 }
763763 }
src-self-hosted/test.zig+2-2
......@@ -87,7 +87,7 @@ pub const TestContext = struct {
8787 ) !void {
8888 var file_index_buf: [20]u8 = undefined;
8989 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr());
90 const file1_path = try std.os.path.join(allocator, tmp_dir_name, file_index, file1);
90 const file1_path = try std.os.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 });
9191
9292 if (std.os.path.dirname(file1_path)) |dirname| {
9393 try std.os.makePath(allocator, dirname);
......@@ -120,7 +120,7 @@ pub const TestContext = struct {
120120 ) !void {
121121 var file_index_buf: [20]u8 = undefined;
122122 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr());
123 const file1_path = try std.os.path.join(allocator, tmp_dir_name, file_index, file1);
123 const file1_path = try std.os.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 });
124124
125125 const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, Target(Target.Native).exeFileExt());
126126 if (std.os.path.dirname(file1_path)) |dirname| {
std/build.zig+17-17
......@@ -145,8 +145,8 @@ pub const Builder = struct {
145145
146146 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
147147 self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default
148 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
149 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
148 self.lib_dir = os.path.join(self.allocator, [][]const u8{self.prefix, "lib"}) catch unreachable;
149 self.exe_dir = os.path.join(self.allocator, [][]const u8{self.prefix, "bin"}) catch unreachable;
150150 }
151151
152152 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -676,7 +676,7 @@ pub const Builder = struct {
676676 if (os.path.isAbsolute(name)) {
677677 return name;
678678 }
679 const full_path = try os.path.join(self.allocator, search_prefix, "bin", self.fmt("{}{}", name, exe_extension));
679 const full_path = try os.path.join(self.allocator, [][]const u8{search_prefix, "bin", self.fmt("{}{}", name, exe_extension)});
680680 if (os.path.real(self.allocator, full_path)) |real_path| {
681681 return real_path;
682682 } else |_| {
......@@ -691,7 +691,7 @@ pub const Builder = struct {
691691 }
692692 var it = mem.tokenize(PATH, []u8{os.path.delimiter});
693693 while (it.next()) |path| {
694 const full_path = try os.path.join(self.allocator, path, self.fmt("{}{}", name, exe_extension));
694 const full_path = try os.path.join(self.allocator, [][]const u8{path, self.fmt("{}{}", name, exe_extension)});
695695 if (os.path.real(self.allocator, full_path)) |real_path| {
696696 return real_path;
697697 } else |_| {
......@@ -705,7 +705,7 @@ pub const Builder = struct {
705705 return name;
706706 }
707707 for (paths) |path| {
708 const full_path = try os.path.join(self.allocator, path, self.fmt("{}{}", name, exe_extension));
708 const full_path = try os.path.join(self.allocator, [][]const u8{path, self.fmt("{}{}", name, exe_extension)});
709709 if (os.path.real(self.allocator, full_path)) |real_path| {
710710 return real_path;
711711 } else |_| {
......@@ -1113,7 +1113,7 @@ pub const LibExeObjStep = struct {
11131113 }
11141114
11151115 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1116 return if (self.output_path) |output_path| output_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
1116 return if (self.output_path) |output_path| output_path else os.path.join(self.builder.allocator, [][]const u8{self.builder.cache_root, self.out_filename}) catch unreachable;
11171117 }
11181118
11191119 pub fn setOutputHPath(self: *LibExeObjStep, file_path: []const u8) void {
......@@ -1126,7 +1126,7 @@ pub const LibExeObjStep = struct {
11261126 }
11271127
11281128 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
1129 return if (self.output_h_path) |output_h_path| output_h_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
1129 return if (self.output_h_path) |output_h_path| output_h_path else os.path.join(self.builder.allocator, [][]const u8{self.builder.cache_root, self.out_h_filename}) catch unreachable;
11301130 }
11311131
11321132 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
......@@ -1226,7 +1226,7 @@ pub const LibExeObjStep = struct {
12261226 }
12271227
12281228 if (self.build_options_contents.len() > 0) {
1229 const build_options_file = try os.path.join(builder.allocator, builder.cache_root, builder.fmt("{}_build_options.zig", self.name));
1229 const build_options_file = try os.path.join(builder.allocator, [][]const u8{builder.cache_root, builder.fmt("{}_build_options.zig", self.name)});
12301230 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
12311231 try zig_args.append("--pkg-begin");
12321232 try zig_args.append("build_options");
......@@ -1476,7 +1476,7 @@ pub const LibExeObjStep = struct {
14761476 cc_args.append("-c") catch unreachable;
14771477 cc_args.append(abs_source_file) catch unreachable;
14781478
1479 const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable;
1479 const cache_o_src = os.path.join(builder.allocator, [][]const u8{builder.cache_root, source_file}) catch unreachable;
14801480 if (os.path.dirname(cache_o_src)) |cache_o_dir| {
14811481 try builder.makePath(cache_o_dir);
14821482 }
......@@ -1528,7 +1528,7 @@ pub const LibExeObjStep = struct {
15281528 cc_args.append("-current_version") catch unreachable;
15291529 cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch)) catch unreachable;
15301530
1531 const install_name = builder.pathFromRoot(os.path.join(builder.allocator, builder.cache_root, self.major_only_filename) catch unreachable);
1531 const install_name = builder.pathFromRoot(os.path.join(builder.allocator, [][]const u8{builder.cache_root, self.major_only_filename}) catch unreachable);
15321532 cc_args.append("-install_name") catch unreachable;
15331533 cc_args.append(install_name) catch unreachable;
15341534 } else {
......@@ -1594,7 +1594,7 @@ pub const LibExeObjStep = struct {
15941594 cc_args.append("-c") catch unreachable;
15951595 cc_args.append(abs_source_file) catch unreachable;
15961596
1597 const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable;
1597 const cache_o_src = os.path.join(builder.allocator, [][]const u8{builder.cache_root, source_file}) catch unreachable;
15981598 if (os.path.dirname(cache_o_src)) |cache_o_dir| {
15991599 try builder.makePath(cache_o_dir);
16001600 }
......@@ -1757,7 +1757,7 @@ pub const TestStep = struct {
17571757 return output_path;
17581758 } else {
17591759 const basename = self.builder.fmt("test{}", self.target.exeFileExt());
1760 return os.path.join(self.builder.allocator, self.builder.cache_root, basename) catch unreachable;
1760 return os.path.join(self.builder.allocator, [][]const u8{self.builder.cache_root, basename}) catch unreachable;
17611761 }
17621762 }
17631763
......@@ -1980,12 +1980,12 @@ const InstallArtifactStep = struct {
19801980 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
19811981 .artifact = artifact,
19821982 .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable,
1983 };
1983 }) catch unreachable;
19841984 self.step.dependOn(&artifact.step);
19851985 builder.pushInstalledFile(self.dest_file);
19861986 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
1987 builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir, artifact.major_only_filename) catch unreachable);
1988 builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir, artifact.name_only_filename) catch unreachable);
1987 builder.pushInstalledFile(os.path.join(builder.allocator, [][]const u8{builder.lib_dir, artifact.major_only_filename}) catch unreachable);
1988 builder.pushInstalledFile(os.path.join(builder.allocator, [][]const u8{builder.lib_dir, artifact.name_only_filename}) catch unreachable);
19891989 }
19901990 return self;
19911991 }
......@@ -2141,13 +2141,13 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
21412141 const out_dir = os.path.dirname(output_path) orelse ".";
21422142 const out_basename = os.path.basename(output_path);
21432143 // sym link for libfoo.so.1 to libfoo.so.1.2.3
2144 const major_only_path = os.path.join(allocator, out_dir, filename_major_only) catch unreachable;
2144 const major_only_path = os.path.join(allocator, [][]const u8{out_dir, filename_major_only}) catch unreachable;
21452145 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
21462146 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
21472147 return err;
21482148 };
21492149 // sym link for libfoo.so to libfoo.so.1
2150 const name_only_path = os.path.join(allocator, out_dir, filename_name_only) catch unreachable;
2150 const name_only_path = os.path.join(allocator, [][]const u8{out_dir, filename_name_only}) catch unreachable;
21512151 os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
21522152 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
21532153 return err;
std/debug/index.zig+1-1
......@@ -1352,7 +1352,7 @@ const LineNumberProgram = struct {
13521352 return error.InvalidDebugInfo;
13531353 } else
13541354 self.include_dirs[file_entry.dir_index];
1355 const file_name = try os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);
1355 const file_name = try os.path.join(self.file_entries.allocator, [][]const u8{dir_name, file_entry.file_name});
13561356 errdefer self.file_entries.allocator.free(file_name);
13571357 return LineInfo{
13581358 .line = if (self.prev_line >= 0) @intCast(usize, self.prev_line) else 0,
std/event/fs.zig+1-1
......@@ -1336,7 +1336,7 @@ async fn testFsWatchCantFail(loop: *Loop, result: *(anyerror!void)) void {
13361336}
13371337
13381338async fn testFsWatch(loop: *Loop) !void {
1339 const file_path = try os.path.join(loop.allocator, test_tmp_dir, "file.txt");
1339 const file_path = try os.path.join(loop.allocator, [][]const u8{test_tmp_dir, "file.txt"});
13401340 defer loop.allocator.free(file_path);
13411341
13421342 const contents =
std/os/child_process.zig+1-1
......@@ -597,7 +597,7 @@ pub const ChildProcess = struct {
597597
598598 var it = mem.tokenize(PATH, ";");
599599 while (it.next()) |search_path| {
600 const joined_path = try os.path.join(self.allocator, search_path, app_name);
600 const joined_path = try os.path.join(self.allocator, [][]const u8{ search_path, app_name });
601601 defer self.allocator.free(joined_path);
602602
603603 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);
std/os/get_app_data_dir.zig+3-3
......@@ -30,7 +30,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
3030 error.OutOfMemory => return error.OutOfMemory,
3131 };
3232 defer allocator.free(global_dir);
33 return os.path.join(allocator, global_dir, appname);
33 return os.path.join(allocator, [][]const u8{global_dir, appname});
3434 },
3535 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
3636 else => return error.AppDataDirUnavailable,
......@@ -41,14 +41,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
4141 // TODO look in /etc/passwd
4242 return error.AppDataDirUnavailable;
4343 };
44 return os.path.join(allocator, home_dir, "Library", "Application Support", appname);
44 return os.path.join(allocator, [][]const u8{home_dir, "Library", "Application Support", appname});
4545 },
4646 builtin.Os.linux, builtin.Os.freebsd => {
4747 const home_dir = os.getEnvPosix("HOME") orelse {
4848 // TODO look in /etc/passwd
4949 return error.AppDataDirUnavailable;
5050 };
51 return os.path.join(allocator, home_dir, ".local", "share", appname);
51 return os.path.join(allocator, [][]const u8{home_dir, ".local", "share", appname});
5252 },
5353 else => @compileError("Unsupported OS"),
5454 }
std/os/path.zig+51-28
......@@ -35,38 +35,61 @@ pub fn isSep(byte: u8) bool {
3535
3636/// Naively combines a series of paths with the native path seperator.
3737/// Allocates memory for the result, which must be freed by the caller.
38pub fn join(allocator: *Allocator, paths: ...) ![]u8 {
39 if (is_windows) {
40 return joinWindows(allocator, paths);
41 } else {
42 return joinPosix(allocator, paths);
38
39pub fn join(allocator: *Allocator, paths: []const []const u8) ![]u8 {
40 assert(paths.len >= 1);
41 var total_paths_len: usize = paths.len; // 1 sep per path
42 {
43 var path_i: usize = 0;
44 while (path_i < paths.len) : (path_i += 1) {
45 const arg = ([]const u8)(paths[path_i]);
46 total_paths_len += arg.len;
47 }
4348 }
44}
4549
46pub fn joinWindows(allocator: *Allocator, paths: ...) ![]u8 {
47 return mem.join(allocator, sep_windows, paths);
48}
50 const buf = try allocator.alloc(u8, total_paths_len);
51 errdefer allocator.free(buf);
52
53 var buf_index: usize = 0;
54 var path_i: usize = 0;
55 while (true) {
56 const arg = ([]const u8)(paths[path_i]);
57 path_i += 1;
58 mem.copy(u8, buf[buf_index..], arg);
59 buf_index += arg.len;
60 if (path_i >= paths.len) break;
61 if (buf_index > 0 and buf[buf_index - 1] != sep) {
62 buf[buf_index] = sep;
63 buf_index += 1;
64 }
65 }
4966
50pub fn joinPosix(allocator: *Allocator, paths: ...) ![]u8 {
51 return mem.join(allocator, sep_posix, paths);
67 return allocator.shrink(u8, buf, buf_index);
5268}
5369
5470test "os.path.join" {
55 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
56 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
57
58 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
59 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
60
61 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"), "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
62
63 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
64 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
65
66 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
67 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
68
69 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
71 switch (builtin.os) {
72 Os.windows => {
73 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\a\\b", "c"}), "c:\\a\\b\\c"));
74 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\a\\b\\", "c"}), "c:\\a\\b\\c"));
75 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\", "a", "b\\", "c"}), "c:\\a\\b\\c"));
76 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\a\\", "b\\", "c"}), "c:\\a\\b\\c"));
77 assert(mem.eql(u8, try join( debug.global_allocator
78 , [][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std"
79 , "io.zig"})
80 , "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
81 },
82 else => {
83 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/a/b", "c"}), "/a/b/c"));
84 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/a/b/", "c"}), "/a/b/c"));
85 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/", "a", "b/", "c"}), "/a/b/c"));
86 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/a/", "b/", "c"}), "/a/b/c"));
87 assert(mem.eql(u8, try join( debug.global_allocator
88 , [][]const u8{ "/home/andy/dev/zig/build/lib/zig/std"
89 , "io.zig"})
90 , "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
91 }
92 }
7093}
7194
7295pub fn isAbsolute(path: []const u8) bool {
......@@ -602,7 +625,7 @@ test "os.path.resolveWindows" {
602625 const parsed_cwd = windowsParsePath(cwd);
603626 {
604627 const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
605 const expected = try join(debug.global_allocator, parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
628 const expected = try join(debug.global_allocator, [][]const u8{ parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig"});
606629 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
607630 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
608631 }
......@@ -610,7 +633,7 @@ test "os.path.resolveWindows" {
610633 }
611634 {
612635 const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
613 const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
636 const expected = try join(debug.global_allocator, [][]const u8{ cwd, "usr\\local\\lib\\zig" });
614637 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
615638 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
616639 }
test/cli.zig+3-3
......@@ -29,7 +29,7 @@ pub fn main() !void {
2929 });
3030 const zig_exe = try os.path.resolve(a, zig_exe_rel);
3131
32 const dir_path = try os.path.join(a, cache_root, "clitest");
32 const dir_path = try os.path.join(a, [][]const u8{ cache_root, "clitest" });
3333 const TestFn = fn ([]const u8, []const u8) anyerror!void;
3434 const test_fns = []TestFn{
3535 testZigInitLib,
......@@ -99,8 +99,8 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
9999fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
100100 if (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64) return;
101101
102 const example_zig_path = try os.path.join(a, dir_path, "example.zig");
103 const example_s_path = try os.path.join(a, dir_path, "example.s");
102 const example_zig_path = try os.path.join(a, [][]const u8{ dir_path, "example.zig" });
103 const example_s_path = try os.path.join(a, [][]const u8{ dir_path, "example.s" });
104104
105105 try std.io.writeFile(example_zig_path,
106106 \\// Type your code here, or load an example.
test/tests.zig+11-11
......@@ -439,7 +439,7 @@ pub const CompareOutputContext = struct {
439439 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
440440 const b = self.b;
441441
442 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
442 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, case.sources.items[0].filename}) catch unreachable;
443443
444444 switch (case.special) {
445445 Special.Asm => {
......@@ -452,7 +452,7 @@ pub const CompareOutputContext = struct {
452452 exe.addAssemblyFile(root_src);
453453
454454 for (case.sources.toSliceConst()) |src_file| {
455 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
455 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
456456 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
457457 exe.step.dependOn(&write_src.step);
458458 }
......@@ -476,7 +476,7 @@ pub const CompareOutputContext = struct {
476476 }
477477
478478 for (case.sources.toSliceConst()) |src_file| {
479 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
479 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
480480 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
481481 exe.step.dependOn(&write_src.step);
482482 }
......@@ -499,7 +499,7 @@ pub const CompareOutputContext = struct {
499499 }
500500
501501 for (case.sources.toSliceConst()) |src_file| {
502 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
502 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
503503 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
504504 exe.step.dependOn(&write_src.step);
505505 }
......@@ -572,8 +572,8 @@ pub const CompileErrorContext = struct {
572572 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
573573 const b = self.context.b;
574574
575 const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
576 const obj_path = os.path.join(b.allocator, b.cache_root, "test.o") catch unreachable;
575 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, self.case.sources.items[0].filename}) catch unreachable;
576 const obj_path = os.path.join(b.allocator, [][]const u8{b.cache_root, "test.o"}) catch unreachable;
577577
578578 var zig_args = ArrayList([]const u8).init(b.allocator);
579579 zig_args.append(b.zig_exe) catch unreachable;
......@@ -721,7 +721,7 @@ pub const CompileErrorContext = struct {
721721 self.step.dependOn(&compile_and_cmp_errors.step);
722722
723723 for (case.sources.toSliceConst()) |src_file| {
724 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
724 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
725725 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
726726 compile_and_cmp_errors.step.dependOn(&write_src.step);
727727 }
......@@ -852,7 +852,7 @@ pub const TranslateCContext = struct {
852852 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
853853 const b = self.context.b;
854854
855 const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
855 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, self.case.sources.items[0].filename}) catch unreachable;
856856
857857 var zig_args = ArrayList([]const u8).init(b.allocator);
858858 zig_args.append(b.zig_exe) catch unreachable;
......@@ -986,7 +986,7 @@ pub const TranslateCContext = struct {
986986 self.step.dependOn(&translate_c_and_cmp.step);
987987
988988 for (case.sources.toSliceConst()) |src_file| {
989 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
989 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
990990 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
991991 translate_c_and_cmp.step.dependOn(&write_src.step);
992992 }
......@@ -1101,7 +1101,7 @@ pub const GenHContext = struct {
11011101
11021102 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
11031103 const b = self.b;
1104 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
1104 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, case.sources.items[0].filename}) catch unreachable;
11051105
11061106 const mode = builtin.Mode.Debug;
11071107 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable;
......@@ -1113,7 +1113,7 @@ pub const GenHContext = struct {
11131113 obj.setBuildMode(mode);
11141114
11151115 for (case.sources.toSliceConst()) |src_file| {
1116 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
1116 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
11171117 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
11181118 obj.step.dependOn(&write_src.step);
11191119 }