mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
remove %% prefix operator
See #632 closes #545 closes #510 this makes #651 higher priority
This commit is contained in:
@@ -18,14 +18,14 @@ pub fn build(b: &Builder) {
|
||||
var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8 {
|
||||
docgen_exe.getOutputPath(),
|
||||
"doc/langref.html.in",
|
||||
%%os.path.join(b.allocator, b.cache_root, "langref.html"),
|
||||
os.path.join(b.allocator, b.cache_root, "langref.html") catch unreachable,
|
||||
});
|
||||
docgen_cmd.step.dependOn(&docgen_exe.step);
|
||||
|
||||
var docgen_home_cmd = b.addCommand(null, b.env_map, [][]const u8 {
|
||||
docgen_exe.getOutputPath(),
|
||||
"doc/home.html.in",
|
||||
%%os.path.join(b.allocator, b.cache_root, "home.html"),
|
||||
os.path.join(b.allocator, b.cache_root, "home.html") catch unreachable,
|
||||
});
|
||||
docgen_home_cmd.step.dependOn(&docgen_exe.step);
|
||||
|
||||
@@ -47,7 +47,7 @@ pub fn build(b: &Builder) {
|
||||
const c_header_files = nextValue(&index, build_info);
|
||||
const dia_guids_lib = nextValue(&index, build_info);
|
||||
|
||||
const llvm = findLLVM(b, llvm_config_exe);
|
||||
const llvm = findLLVM(b, llvm_config_exe) catch unreachable;
|
||||
|
||||
var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
|
||||
exe.setBuildMode(mode);
|
||||
@@ -143,8 +143,8 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
|
||||
|
||||
fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) {
|
||||
const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
|
||||
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())));
|
||||
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);
|
||||
}
|
||||
|
||||
const LibraryDep = struct {
|
||||
@@ -154,7 +154,7 @@ const LibraryDep = struct {
|
||||
includes: ArrayList([]const u8),
|
||||
};
|
||||
|
||||
fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep {
|
||||
const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
|
||||
const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
|
||||
const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});
|
||||
@@ -169,12 +169,12 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
var it = mem.split(libs_output, " \r\n");
|
||||
while (it.next()) |lib_arg| {
|
||||
if (mem.startsWith(u8, lib_arg, "-l")) {
|
||||
%%result.system_libs.append(lib_arg[2..]);
|
||||
try result.system_libs.append(lib_arg[2..]);
|
||||
} else {
|
||||
if (os.path.isAbsolute(lib_arg)) {
|
||||
%%result.libs.append(lib_arg);
|
||||
try result.libs.append(lib_arg);
|
||||
} else {
|
||||
%%result.system_libs.append(lib_arg);
|
||||
try result.system_libs.append(lib_arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,9 +183,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
var it = mem.split(includes_output, " \r\n");
|
||||
while (it.next()) |include_arg| {
|
||||
if (mem.startsWith(u8, include_arg, "-I")) {
|
||||
%%result.includes.append(include_arg[2..]);
|
||||
try result.includes.append(include_arg[2..]);
|
||||
} else {
|
||||
%%result.includes.append(include_arg);
|
||||
try result.includes.append(include_arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,9 +193,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
var it = mem.split(libdir_output, " \r\n");
|
||||
while (it.next()) |libdir| {
|
||||
if (mem.startsWith(u8, libdir, "-L")) {
|
||||
%%result.libdirs.append(libdir[2..]);
|
||||
try result.libdirs.append(libdir[2..]);
|
||||
} else {
|
||||
%%result.libdirs.append(libdir);
|
||||
try result.libdirs.append(libdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,8 +205,8 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {
|
||||
var it = mem.split(stdlib_files, ";");
|
||||
while (it.next()) |stdlib_file| {
|
||||
const src_path = %%os.path.join(b.allocator, "std", stdlib_file);
|
||||
const dest_path = %%os.path.join(b.allocator, "lib", "zig", "std", stdlib_file);
|
||||
const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;
|
||||
const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable;
|
||||
b.installFile(src_path, dest_path);
|
||||
}
|
||||
}
|
||||
@@ -214,8 +214,8 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {
|
||||
pub fn installCHeaders(b: &Builder, c_header_files: []const u8) {
|
||||
var it = mem.split(c_header_files, ";");
|
||||
while (it.next()) |c_header_file| {
|
||||
const src_path = %%os.path.join(b.allocator, "c_headers", c_header_file);
|
||||
const dest_path = %%os.path.join(b.allocator, "lib", "zig", "include", c_header_file);
|
||||
const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;
|
||||
const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable;
|
||||
b.installFile(src_path, dest_path);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -4,7 +4,7 @@ const os = std.os;
|
||||
|
||||
pub fn main() -> %void {
|
||||
// TODO use a more general purpose allocator here
|
||||
var inc_allocator = %%std.heap.IncrementingAllocator.init(5 * 1024 * 1024);
|
||||
var inc_allocator = try std.heap.IncrementingAllocator.init(5 * 1024 * 1024);
|
||||
defer inc_allocator.deinit();
|
||||
const allocator = &inc_allocator.allocator;
|
||||
|
||||
@@ -12,16 +12,16 @@ pub fn main() -> %void {
|
||||
|
||||
if (!args_it.skip()) @panic("expected self arg");
|
||||
|
||||
const in_file_name = %%(args_it.next(allocator) ?? @panic("expected input arg"));
|
||||
const in_file_name = try (args_it.next(allocator) ?? @panic("expected input arg"));
|
||||
defer allocator.free(in_file_name);
|
||||
|
||||
const out_file_name = %%(args_it.next(allocator) ?? @panic("expected output arg"));
|
||||
const out_file_name = try (args_it.next(allocator) ?? @panic("expected output arg"));
|
||||
defer allocator.free(out_file_name);
|
||||
|
||||
var in_file = %%io.File.openRead(in_file_name, allocator);
|
||||
var in_file = try io.File.openRead(in_file_name, allocator);
|
||||
defer in_file.close();
|
||||
|
||||
var out_file = %%io.File.openWrite(out_file_name, allocator);
|
||||
var out_file = try io.File.openWrite(out_file_name, allocator);
|
||||
defer out_file.close();
|
||||
|
||||
var file_in_stream = io.FileInStream.init(&in_file);
|
||||
@@ -31,7 +31,7 @@ pub fn main() -> %void {
|
||||
var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);
|
||||
|
||||
gen(&buffered_in_stream.stream, &buffered_out_stream.stream);
|
||||
%%buffered_out_stream.flush();
|
||||
try buffered_out_stream.flush();
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) {
|
||||
switch (state) {
|
||||
State.Start => switch (byte) {
|
||||
else => {
|
||||
%%out.writeByte(byte);
|
||||
out.writeByte(byte) catch unreachable;
|
||||
},
|
||||
},
|
||||
State.Derp => unreachable,
|
||||
|
||||
+1
-1
@@ -5989,7 +5989,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
|
||||
|
||||
StructLiteralField = "." Symbol "=" Expression
|
||||
|
||||
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%" | "try"
|
||||
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "??" | "-%" | "try"
|
||||
|
||||
PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." Symbol) | ContainerDecl | ("continue" option(":" Symbol))
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ pub fn main() -> %void {
|
||||
try stdout.print("Welcome to the Guess Number Game in Zig.\n");
|
||||
|
||||
var seed_bytes: [@sizeOf(usize)]u8 = undefined;
|
||||
%%os.getRandomBytes(seed_bytes[0..]);
|
||||
os.getRandomBytes(seed_bytes[0..]) catch |err| {
|
||||
std.debug.warn("unable to seed random number generator: {}", err);
|
||||
return err;
|
||||
};
|
||||
const seed = std.mem.readInt(seed_bytes, usize, builtin.Endian.Big);
|
||||
var rand = Rand.init(seed);
|
||||
|
||||
|
||||
@@ -594,7 +594,6 @@ enum PrefixOp {
|
||||
PrefixOpDereference,
|
||||
PrefixOpMaybe,
|
||||
PrefixOpError,
|
||||
PrefixOpUnwrapError,
|
||||
PrefixOpUnwrapMaybe,
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -2587,7 +2587,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
|
||||
return g->test_fn_type;
|
||||
|
||||
FnTypeId fn_type_id = {0};
|
||||
fn_type_id.return_type = g->builtin_types.entry_void;
|
||||
fn_type_id.return_type = get_error_type(g, g->builtin_types.entry_void);
|
||||
g->test_fn_type = get_fn_type(g, &fn_type_id);
|
||||
return g->test_fn_type;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
|
||||
case PrefixOpDereference: return "*";
|
||||
case PrefixOpMaybe: return "?";
|
||||
case PrefixOpError: return "%";
|
||||
case PrefixOpUnwrapError: return "catch";
|
||||
case PrefixOpUnwrapMaybe: return "??";
|
||||
}
|
||||
zig_unreachable();
|
||||
|
||||
@@ -3963,8 +3963,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
|
||||
return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);
|
||||
case PrefixOpError:
|
||||
return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpError), lval);
|
||||
case PrefixOpUnwrapError:
|
||||
return ir_gen_err_assert_ok(irb, scope, node, node->data.prefix_op_expr.primary_expr, lval);
|
||||
case PrefixOpUnwrapMaybe:
|
||||
return ir_gen_maybe_assert_ok(irb, scope, node, lval);
|
||||
}
|
||||
|
||||
@@ -956,7 +956,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {
|
||||
case TokenIdStar: return PrefixOpDereference;
|
||||
case TokenIdMaybe: return PrefixOpMaybe;
|
||||
case TokenIdPercent: return PrefixOpError;
|
||||
case TokenIdPercentPercent: return PrefixOpUnwrapError;
|
||||
case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
|
||||
case TokenIdStarStar: return PrefixOpDereference;
|
||||
default: return PrefixOpInvalid;
|
||||
|
||||
@@ -816,11 +816,6 @@ void tokenize(Buf *buf, Tokenization *out) {
|
||||
end_token(&t);
|
||||
t.state = TokenizeStateStart;
|
||||
break;
|
||||
case '%':
|
||||
set_token_id(&t, t.cur_tok, TokenIdPercentPercent);
|
||||
end_token(&t);
|
||||
t.state = TokenizeStateStart;
|
||||
break;
|
||||
default:
|
||||
t.pos -= 1;
|
||||
end_token(&t);
|
||||
@@ -1564,7 +1559,6 @@ const char * token_name(TokenId id) {
|
||||
case TokenIdNumberSign: return "#";
|
||||
case TokenIdPercent: return "%";
|
||||
case TokenIdPercentDot: return "%.";
|
||||
case TokenIdPercentPercent: return "%%";
|
||||
case TokenIdPlus: return "+";
|
||||
case TokenIdPlusEq: return "+=";
|
||||
case TokenIdPlusPercent: return "+%";
|
||||
|
||||
@@ -101,7 +101,6 @@ enum TokenId {
|
||||
TokenIdNumberSign,
|
||||
TokenIdPercent,
|
||||
TokenIdPercentDot,
|
||||
TokenIdPercentPercent,
|
||||
TokenIdPlus,
|
||||
TokenIdPlusEq,
|
||||
TokenIdPlusPercent,
|
||||
|
||||
+3
-3
@@ -116,7 +116,7 @@ test "basic ArrayList test" {
|
||||
defer list.deinit();
|
||||
|
||||
{var i: usize = 0; while (i < 10) : (i += 1) {
|
||||
%%list.append(i32(i + 1));
|
||||
list.append(i32(i + 1)) catch unreachable;
|
||||
}}
|
||||
|
||||
{var i: usize = 0; while (i < 10) : (i += 1) {
|
||||
@@ -126,13 +126,13 @@ test "basic ArrayList test" {
|
||||
assert(list.pop() == 10);
|
||||
assert(list.len == 9);
|
||||
|
||||
%%list.appendSlice([]const i32 { 1, 2, 3 });
|
||||
list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable;
|
||||
assert(list.len == 12);
|
||||
assert(list.pop() == 3);
|
||||
assert(list.pop() == 2);
|
||||
assert(list.pop() == 1);
|
||||
assert(list.len == 9);
|
||||
|
||||
%%list.appendSlice([]const i32 {});
|
||||
list.appendSlice([]const i32 {}) catch unreachable;
|
||||
assert(list.len == 9);
|
||||
}
|
||||
|
||||
+3
-3
@@ -120,7 +120,7 @@ pub const Base64Decoder = struct {
|
||||
/// invalid characters result in error.InvalidCharacter.
|
||||
/// invalid padding results in error.InvalidPadding.
|
||||
pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) -> %void {
|
||||
assert(dest.len == %%decoder.calcSize(source));
|
||||
assert(dest.len == (decoder.calcSize(source) catch unreachable));
|
||||
assert(source.len % 4 == 0);
|
||||
|
||||
var src_cursor: usize = 0;
|
||||
@@ -374,8 +374,8 @@ fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize {
|
||||
|
||||
test "base64" {
|
||||
@setEvalBranchQuota(5000);
|
||||
%%testBase64();
|
||||
comptime %%testBase64();
|
||||
testBase64() catch unreachable;
|
||||
comptime (testBase64() catch unreachable);
|
||||
}
|
||||
|
||||
fn testBase64() -> %void {
|
||||
|
||||
+6
-6
@@ -151,20 +151,20 @@ pub const Buffer = struct {
|
||||
test "simple Buffer" {
|
||||
const cstr = @import("cstr.zig");
|
||||
|
||||
var buf = %%Buffer.init(debug.global_allocator, "");
|
||||
var buf = try Buffer.init(debug.global_allocator, "");
|
||||
assert(buf.len() == 0);
|
||||
%%buf.append("hello");
|
||||
%%buf.appendByte(' ');
|
||||
%%buf.append("world");
|
||||
try buf.append("hello");
|
||||
try buf.appendByte(' ');
|
||||
try buf.append("world");
|
||||
assert(buf.eql("hello world"));
|
||||
assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
|
||||
|
||||
var buf2 = %%Buffer.initFromBuffer(&buf);
|
||||
var buf2 = try Buffer.initFromBuffer(&buf);
|
||||
assert(buf.eql(buf2.toSliceConst()));
|
||||
|
||||
assert(buf.startsWith("hell"));
|
||||
assert(buf.endsWith("orld"));
|
||||
|
||||
%%buf2.resize(4);
|
||||
try buf2.resize(4);
|
||||
assert(buf.startsWith(buf2.toSliceConst()));
|
||||
}
|
||||
|
||||
+249
-249
@@ -95,7 +95,7 @@ pub const Builder = struct {
|
||||
var self = Builder {
|
||||
.zig_exe = zig_exe,
|
||||
.build_root = build_root,
|
||||
.cache_root = %%os.path.relative(allocator, build_root, cache_root),
|
||||
.cache_root = os.path.relative(allocator, build_root, cache_root) catch unreachable,
|
||||
.verbose = false,
|
||||
.verbose_tokenize = false,
|
||||
.verbose_ast = false,
|
||||
@@ -113,7 +113,7 @@ pub const Builder = struct {
|
||||
.available_options_list = ArrayList(AvailableOption).init(allocator),
|
||||
.top_level_steps = ArrayList(&TopLevelStep).init(allocator),
|
||||
.default_step = undefined,
|
||||
.env_map = %%os.getEnvMap(allocator),
|
||||
.env_map = os.getEnvMap(allocator) catch unreachable,
|
||||
.prefix = undefined,
|
||||
.search_prefixes = ArrayList([]const u8).init(allocator),
|
||||
.lib_dir = undefined,
|
||||
@@ -146,8 +146,8 @@ pub const Builder = struct {
|
||||
|
||||
pub fn setInstallPrefix(self: &Builder, maybe_prefix: ?[]const u8) {
|
||||
self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default
|
||||
self.lib_dir = %%os.path.join(self.allocator, self.prefix, "lib");
|
||||
self.exe_dir = %%os.path.join(self.allocator, self.prefix, "bin");
|
||||
self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
|
||||
self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExecutable(self: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
|
||||
@@ -169,7 +169,7 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addTest(self: &Builder, root_src: []const u8) -> &TestStep {
|
||||
const test_step = %%self.allocator.create(TestStep);
|
||||
const test_step = self.allocator.create(TestStep) catch unreachable;
|
||||
*test_step = TestStep.init(self, root_src);
|
||||
return test_step;
|
||||
}
|
||||
@@ -204,20 +204,20 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addWriteFile(self: &Builder, file_path: []const u8, data: []const u8) -> &WriteFileStep {
|
||||
const write_file_step = %%self.allocator.create(WriteFileStep);
|
||||
const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
|
||||
*write_file_step = WriteFileStep.init(self, file_path, data);
|
||||
return write_file_step;
|
||||
}
|
||||
|
||||
pub fn addLog(self: &Builder, comptime format: []const u8, args: ...) -> &LogStep {
|
||||
const data = self.fmt(format, args);
|
||||
const log_step = %%self.allocator.create(LogStep);
|
||||
const log_step = self.allocator.create(LogStep) catch unreachable;
|
||||
*log_step = LogStep.init(self, data);
|
||||
return log_step;
|
||||
}
|
||||
|
||||
pub fn addRemoveDirTree(self: &Builder, dir_path: []const u8) -> &RemoveDirStep {
|
||||
const remove_dir_step = %%self.allocator.create(RemoveDirStep);
|
||||
const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
|
||||
*remove_dir_step = RemoveDirStep.init(self, dir_path);
|
||||
return remove_dir_step;
|
||||
}
|
||||
@@ -231,15 +231,15 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addCIncludePath(self: &Builder, path: []const u8) {
|
||||
%%self.include_paths.append(path);
|
||||
self.include_paths.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addRPath(self: &Builder, path: []const u8) {
|
||||
%%self.rpaths.append(path);
|
||||
self.rpaths.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addLibPath(self: &Builder, path: []const u8) {
|
||||
%%self.lib_paths.append(path);
|
||||
self.lib_paths.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn make(self: &Builder, step_names: []const []const u8) -> %void {
|
||||
@@ -247,11 +247,11 @@ pub const Builder = struct {
|
||||
defer wanted_steps.deinit();
|
||||
|
||||
if (step_names.len == 0) {
|
||||
%%wanted_steps.append(&self.default_step);
|
||||
wanted_steps.append(&self.default_step) catch unreachable;
|
||||
} else {
|
||||
for (step_names) |step_name| {
|
||||
const s = try self.getTopLevelStepByName(step_name);
|
||||
%%wanted_steps.append(s);
|
||||
wanted_steps.append(s) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ pub const Builder = struct {
|
||||
if (self.have_install_step)
|
||||
return &self.install_tls.step;
|
||||
|
||||
%%self.top_level_steps.append(&self.install_tls);
|
||||
self.top_level_steps.append(&self.install_tls) catch unreachable;
|
||||
self.have_install_step = true;
|
||||
return &self.install_tls.step;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ pub const Builder = struct {
|
||||
if (self.have_uninstall_step)
|
||||
return &self.uninstall_tls.step;
|
||||
|
||||
%%self.top_level_steps.append(&self.uninstall_tls);
|
||||
self.top_level_steps.append(&self.uninstall_tls) catch unreachable;
|
||||
self.have_uninstall_step = true;
|
||||
return &self.uninstall_tls.step;
|
||||
}
|
||||
@@ -372,10 +372,10 @@ pub const Builder = struct {
|
||||
.type_id = type_id,
|
||||
.description = description,
|
||||
};
|
||||
if (%%self.available_options_map.put(name, available_option) != null) {
|
||||
if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
|
||||
debug.panic("Option '{}' declared twice", name);
|
||||
}
|
||||
%%self.available_options_list.append(available_option);
|
||||
self.available_options_list.append(available_option) catch unreachable;
|
||||
|
||||
const entry = self.user_input_options.get(name) ?? return null;
|
||||
entry.value.used = true;
|
||||
@@ -419,12 +419,12 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn step(self: &Builder, name: []const u8, description: []const u8) -> &Step {
|
||||
const step_info = %%self.allocator.create(TopLevelStep);
|
||||
const step_info = self.allocator.create(TopLevelStep) catch unreachable;
|
||||
*step_info = TopLevelStep {
|
||||
.step = Step.initNoOp(name, self.allocator),
|
||||
.description = description,
|
||||
};
|
||||
%%self.top_level_steps.append(step_info);
|
||||
self.top_level_steps.append(step_info) catch unreachable;
|
||||
return &step_info.step;
|
||||
}
|
||||
|
||||
@@ -450,32 +450,32 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addUserInputOption(self: &Builder, name: []const u8, value: []const u8) -> bool {
|
||||
if (%%self.user_input_options.put(name, UserInputOption {
|
||||
if (self.user_input_options.put(name, UserInputOption {
|
||||
.name = name,
|
||||
.value = UserValue { .Scalar = value },
|
||||
.used = false,
|
||||
})) |*prev_value| {
|
||||
}) catch unreachable) |*prev_value| {
|
||||
// option already exists
|
||||
switch (prev_value.value) {
|
||||
UserValue.Scalar => |s| {
|
||||
// turn it into a list
|
||||
var list = ArrayList([]const u8).init(self.allocator);
|
||||
%%list.append(s);
|
||||
%%list.append(value);
|
||||
_ = %%self.user_input_options.put(name, UserInputOption {
|
||||
list.append(s) catch unreachable;
|
||||
list.append(value) catch unreachable;
|
||||
_ = self.user_input_options.put(name, UserInputOption {
|
||||
.name = name,
|
||||
.value = UserValue { .List = list },
|
||||
.used = false,
|
||||
});
|
||||
}) catch unreachable;
|
||||
},
|
||||
UserValue.List => |*list| {
|
||||
// append to the list
|
||||
%%list.append(value);
|
||||
_ = %%self.user_input_options.put(name, UserInputOption {
|
||||
list.append(value) catch unreachable;
|
||||
_ = self.user_input_options.put(name, UserInputOption {
|
||||
.name = name,
|
||||
.value = UserValue { .List = *list },
|
||||
.used = false,
|
||||
});
|
||||
}) catch unreachable;
|
||||
},
|
||||
UserValue.Flag => {
|
||||
warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name);
|
||||
@@ -487,11 +487,11 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addUserInputFlag(self: &Builder, name: []const u8) -> bool {
|
||||
if (%%self.user_input_options.put(name, UserInputOption {
|
||||
if (self.user_input_options.put(name, UserInputOption {
|
||||
.name = name,
|
||||
.value = UserValue {.Flag = {} },
|
||||
.used = false,
|
||||
})) |*prev_value| {
|
||||
}) catch unreachable) |*prev_value| {
|
||||
switch (prev_value.value) {
|
||||
UserValue.Scalar => |s| {
|
||||
warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s);
|
||||
@@ -567,7 +567,7 @@ pub const Builder = struct {
|
||||
printCmd(cwd, argv);
|
||||
}
|
||||
|
||||
const child = %%os.ChildProcess.init(argv, self.allocator);
|
||||
const child = os.ChildProcess.init(argv, self.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.cwd = cwd;
|
||||
@@ -617,17 +617,17 @@ pub const Builder = struct {
|
||||
|
||||
///::dest_rel_path is relative to prefix path or it can be an absolute path
|
||||
pub fn addInstallFile(self: &Builder, src_path: []const u8, dest_rel_path: []const u8) -> &InstallFileStep {
|
||||
const full_dest_path = %%os.path.resolve(self.allocator, self.prefix, dest_rel_path);
|
||||
const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;
|
||||
self.pushInstalledFile(full_dest_path);
|
||||
|
||||
const install_step = %%self.allocator.create(InstallFileStep);
|
||||
const install_step = self.allocator.create(InstallFileStep) catch unreachable;
|
||||
*install_step = InstallFileStep.init(self, src_path, full_dest_path);
|
||||
return install_step;
|
||||
}
|
||||
|
||||
pub fn pushInstalledFile(self: &Builder, full_path: []const u8) {
|
||||
_ = self.getUninstallStep();
|
||||
%%self.installed_files.append(full_path);
|
||||
self.installed_files.append(full_path) catch unreachable;
|
||||
}
|
||||
|
||||
fn copyFile(self: &Builder, source_path: []const u8, dest_path: []const u8) -> %void {
|
||||
@@ -652,11 +652,11 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
fn pathFromRoot(self: &Builder, rel_path: []const u8) -> []u8 {
|
||||
return %%os.path.resolve(self.allocator, self.build_root, rel_path);
|
||||
return os.path.resolve(self.allocator, self.build_root, rel_path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn fmt(self: &Builder, comptime format: []const u8, args: ...) -> []u8 {
|
||||
return %%fmt_lib.allocPrint(self.allocator, format, args);
|
||||
return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
|
||||
}
|
||||
|
||||
fn getCCExe(self: &Builder) -> []const u8 {
|
||||
@@ -746,7 +746,7 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addSearchPrefix(self: &Builder, search_prefix: []const u8) {
|
||||
%%self.search_prefixes.append(search_prefix);
|
||||
self.search_prefixes.append(search_prefix) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -869,50 +869,50 @@ pub const LibExeObjStep = struct {
|
||||
pub fn createSharedLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8,
|
||||
ver: &const Version) -> &LibExeObjStep
|
||||
{
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createCSharedLibrary(builder: &Builder, name: []const u8, version: &const Version) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initC(builder, name, Kind.Lib, version, false);
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createStaticLibrary(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createCStaticLibrary(builder: &Builder, name: []const u8) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createObject(builder: &Builder, name: []const u8, root_src: []const u8) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createCObject(builder: &Builder, name: []const u8, src: []const u8) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
|
||||
self.object_src = src;
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createExecutable(builder: &Builder, name: []const u8, root_src: ?[]const u8) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createCExecutable(builder: &Builder, name: []const u8) -> &LibExeObjStep {
|
||||
const self = %%builder.allocator.create(LibExeObjStep);
|
||||
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
||||
*self = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
|
||||
return self;
|
||||
}
|
||||
@@ -1052,7 +1052,7 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) {
|
||||
assert(self.target.isDarwin());
|
||||
%%self.frameworks.put(framework_name);
|
||||
self.frameworks.put(framework_name) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) {
|
||||
@@ -1061,30 +1061,30 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
self.step.dependOn(&lib.step);
|
||||
|
||||
%%self.full_path_libs.append(lib.getOutputPath());
|
||||
self.full_path_libs.append(lib.getOutputPath()) catch unreachable;
|
||||
|
||||
// TODO should be some kind of isolated directory that only has this header in it
|
||||
%%self.include_dirs.append(self.builder.cache_root);
|
||||
self.include_dirs.append(self.builder.cache_root) catch unreachable;
|
||||
self.need_flat_namespace_hack = true;
|
||||
|
||||
// inherit the object's frameworks
|
||||
if (self.target.isDarwin() and lib.static) {
|
||||
var it = lib.frameworks.iterator();
|
||||
while (it.next()) |entry| {
|
||||
%%self.frameworks.put(entry.key);
|
||||
self.frameworks.put(entry.key) catch unreachable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) {
|
||||
assert(self.kind != Kind.Obj);
|
||||
%%self.link_libs.put(name);
|
||||
self.link_libs.put(name) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addSourceFile(self: &LibExeObjStep, file: []const u8) {
|
||||
assert(self.kind != Kind.Obj);
|
||||
assert(!self.is_zig);
|
||||
%%self.source_files.append(file);
|
||||
self.source_files.append(file) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setVerboseLink(self: &LibExeObjStep, value: bool) {
|
||||
@@ -1108,7 +1108,7 @@ pub const LibExeObjStep = struct {
|
||||
return if (self.output_path) |output_path|
|
||||
output_path
|
||||
else
|
||||
%%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename);
|
||||
os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {
|
||||
@@ -1124,17 +1124,17 @@ pub const LibExeObjStep = struct {
|
||||
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);
|
||||
os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) {
|
||||
%%self.assembly_files.append(path);
|
||||
self.assembly_files.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addObjectFile(self: &LibExeObjStep, path: []const u8) {
|
||||
assert(self.kind != Kind.Obj);
|
||||
|
||||
%%self.object_files.append(path);
|
||||
self.object_files.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addObject(self: &LibExeObjStep, obj: &LibExeObjStep) {
|
||||
@@ -1143,7 +1143,7 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
self.step.dependOn(&obj.step);
|
||||
|
||||
%%self.object_files.append(obj.getOutputPath());
|
||||
self.object_files.append(obj.getOutputPath()) catch unreachable;
|
||||
|
||||
// TODO make this lazy instead of stateful
|
||||
if (!obj.disable_libc) {
|
||||
@@ -1151,29 +1151,29 @@ pub const LibExeObjStep = struct {
|
||||
}
|
||||
|
||||
// TODO should be some kind of isolated directory that only has this header in it
|
||||
%%self.include_dirs.append(self.builder.cache_root);
|
||||
self.include_dirs.append(self.builder.cache_root) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addIncludeDir(self: &LibExeObjStep, path: []const u8) {
|
||||
%%self.include_dirs.append(path);
|
||||
self.include_dirs.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addLibPath(self: &LibExeObjStep, path: []const u8) {
|
||||
%%self.lib_paths.append(path);
|
||||
self.lib_paths.append(path) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addPackagePath(self: &LibExeObjStep, name: []const u8, pkg_index_path: []const u8) {
|
||||
assert(self.is_zig);
|
||||
|
||||
%%self.packages.append(Pkg {
|
||||
self.packages.append(Pkg {
|
||||
.name = name,
|
||||
.path = pkg_index_path,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addCompileFlags(self: &LibExeObjStep, flags: []const []const u8) {
|
||||
for (flags) |flag| {
|
||||
%%self.cflags.append(flag);
|
||||
self.cflags.append(flag) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1200,148 +1200,148 @@ pub const LibExeObjStep = struct {
|
||||
var zig_args = ArrayList([]const u8).init(builder.allocator);
|
||||
defer zig_args.deinit();
|
||||
|
||||
%%zig_args.append(builder.zig_exe);
|
||||
zig_args.append(builder.zig_exe) catch unreachable;
|
||||
|
||||
const cmd = switch (self.kind) {
|
||||
Kind.Lib => "build-lib",
|
||||
Kind.Exe => "build-exe",
|
||||
Kind.Obj => "build-obj",
|
||||
};
|
||||
%%zig_args.append(cmd);
|
||||
zig_args.append(cmd) catch unreachable;
|
||||
|
||||
if (self.root_src) |root_src| {
|
||||
%%zig_args.append(builder.pathFromRoot(root_src));
|
||||
zig_args.append(builder.pathFromRoot(root_src)) catch unreachable;
|
||||
}
|
||||
|
||||
for (self.object_files.toSliceConst()) |object_file| {
|
||||
%%zig_args.append("--object");
|
||||
%%zig_args.append(builder.pathFromRoot(object_file));
|
||||
zig_args.append("--object") catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(object_file)) catch unreachable;
|
||||
}
|
||||
|
||||
for (self.assembly_files.toSliceConst()) |asm_file| {
|
||||
%%zig_args.append("--assembly");
|
||||
%%zig_args.append(builder.pathFromRoot(asm_file));
|
||||
zig_args.append("--assembly") catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(asm_file)) catch unreachable;
|
||||
}
|
||||
|
||||
if (builder.verbose_tokenize) %%zig_args.append("--verbose-tokenize");
|
||||
if (builder.verbose_ast) %%zig_args.append("--verbose-ast");
|
||||
if (builder.verbose_cimport) %%zig_args.append("--verbose-cimport");
|
||||
if (builder.verbose_ir) %%zig_args.append("--verbose-ir");
|
||||
if (builder.verbose_llvm_ir) %%zig_args.append("--verbose-llvm-ir");
|
||||
if (builder.verbose_link or self.verbose_link) %%zig_args.append("--verbose-link");
|
||||
if (builder.verbose_tokenize) zig_args.append("--verbose-tokenize") catch unreachable;
|
||||
if (builder.verbose_ast) zig_args.append("--verbose-ast") catch unreachable;
|
||||
if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable;
|
||||
if (builder.verbose_ir) zig_args.append("--verbose-ir") catch unreachable;
|
||||
if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable;
|
||||
if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable;
|
||||
|
||||
if (self.strip) {
|
||||
%%zig_args.append("--strip");
|
||||
zig_args.append("--strip") catch unreachable;
|
||||
}
|
||||
|
||||
switch (self.build_mode) {
|
||||
builtin.Mode.Debug => {},
|
||||
builtin.Mode.ReleaseSafe => %%zig_args.append("--release-safe"),
|
||||
builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),
|
||||
builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
|
||||
builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
|
||||
}
|
||||
|
||||
%%zig_args.append("--cache-dir");
|
||||
%%zig_args.append(builder.pathFromRoot(builder.cache_root));
|
||||
zig_args.append("--cache-dir") catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(builder.cache_root)) catch unreachable;
|
||||
|
||||
const output_path = builder.pathFromRoot(self.getOutputPath());
|
||||
%%zig_args.append("--output");
|
||||
%%zig_args.append(output_path);
|
||||
zig_args.append("--output") catch unreachable;
|
||||
zig_args.append(output_path) catch unreachable;
|
||||
|
||||
if (self.kind != Kind.Exe) {
|
||||
const output_h_path = self.getOutputHPath();
|
||||
%%zig_args.append("--output-h");
|
||||
%%zig_args.append(builder.pathFromRoot(output_h_path));
|
||||
zig_args.append("--output-h") catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(output_h_path)) catch unreachable;
|
||||
}
|
||||
|
||||
%%zig_args.append("--name");
|
||||
%%zig_args.append(self.name);
|
||||
zig_args.append("--name") catch unreachable;
|
||||
zig_args.append(self.name) catch unreachable;
|
||||
|
||||
if (self.kind == Kind.Lib and !self.static) {
|
||||
%%zig_args.append("--ver-major");
|
||||
%%zig_args.append(builder.fmt("{}", self.version.major));
|
||||
zig_args.append("--ver-major") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable;
|
||||
|
||||
%%zig_args.append("--ver-minor");
|
||||
%%zig_args.append(builder.fmt("{}", self.version.minor));
|
||||
zig_args.append("--ver-minor") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable;
|
||||
|
||||
%%zig_args.append("--ver-patch");
|
||||
%%zig_args.append(builder.fmt("{}", self.version.patch));
|
||||
zig_args.append("--ver-patch") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
|
||||
}
|
||||
|
||||
switch (self.target) {
|
||||
Target.Native => {},
|
||||
Target.Cross => |cross_target| {
|
||||
%%zig_args.append("--target-arch");
|
||||
%%zig_args.append(@tagName(cross_target.arch));
|
||||
zig_args.append("--target-arch") catch unreachable;
|
||||
zig_args.append(@tagName(cross_target.arch)) catch unreachable;
|
||||
|
||||
%%zig_args.append("--target-os");
|
||||
%%zig_args.append(@tagName(cross_target.os));
|
||||
zig_args.append("--target-os") catch unreachable;
|
||||
zig_args.append(@tagName(cross_target.os)) catch unreachable;
|
||||
|
||||
%%zig_args.append("--target-environ");
|
||||
%%zig_args.append(@tagName(cross_target.environ));
|
||||
zig_args.append("--target-environ") catch unreachable;
|
||||
zig_args.append(@tagName(cross_target.environ)) catch unreachable;
|
||||
},
|
||||
}
|
||||
|
||||
if (self.linker_script) |linker_script| {
|
||||
%%zig_args.append("--linker-script");
|
||||
%%zig_args.append(linker_script);
|
||||
zig_args.append("--linker-script") catch unreachable;
|
||||
zig_args.append(linker_script) catch unreachable;
|
||||
}
|
||||
|
||||
{
|
||||
var it = self.link_libs.iterator();
|
||||
while (true) {
|
||||
const entry = it.next() ?? break;
|
||||
%%zig_args.append("--library");
|
||||
%%zig_args.append(entry.key);
|
||||
zig_args.append("--library") catch unreachable;
|
||||
zig_args.append(entry.key) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
if (!self.disable_libc) {
|
||||
%%zig_args.append("--library");
|
||||
%%zig_args.append("c");
|
||||
zig_args.append("--library") catch unreachable;
|
||||
zig_args.append("c") catch unreachable;
|
||||
}
|
||||
|
||||
for (self.packages.toSliceConst()) |pkg| {
|
||||
%%zig_args.append("--pkg-begin");
|
||||
%%zig_args.append(pkg.name);
|
||||
%%zig_args.append(builder.pathFromRoot(pkg.path));
|
||||
%%zig_args.append("--pkg-end");
|
||||
zig_args.append("--pkg-begin") catch unreachable;
|
||||
zig_args.append(pkg.name) catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(pkg.path)) catch unreachable;
|
||||
zig_args.append("--pkg-end") catch unreachable;
|
||||
}
|
||||
|
||||
for (self.include_dirs.toSliceConst()) |include_path| {
|
||||
%%zig_args.append("-isystem");
|
||||
%%zig_args.append(self.builder.pathFromRoot(include_path));
|
||||
zig_args.append("-isystem") catch unreachable;
|
||||
zig_args.append(self.builder.pathFromRoot(include_path)) catch unreachable;
|
||||
}
|
||||
|
||||
for (builder.include_paths.toSliceConst()) |include_path| {
|
||||
%%zig_args.append("-isystem");
|
||||
%%zig_args.append(builder.pathFromRoot(include_path));
|
||||
zig_args.append("-isystem") catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(include_path)) catch unreachable;
|
||||
}
|
||||
|
||||
for (builder.rpaths.toSliceConst()) |rpath| {
|
||||
%%zig_args.append("-rpath");
|
||||
%%zig_args.append(rpath);
|
||||
zig_args.append("-rpath") catch unreachable;
|
||||
zig_args.append(rpath) catch unreachable;
|
||||
}
|
||||
|
||||
for (self.lib_paths.toSliceConst()) |lib_path| {
|
||||
%%zig_args.append("--library-path");
|
||||
%%zig_args.append(lib_path);
|
||||
zig_args.append("--library-path") catch unreachable;
|
||||
zig_args.append(lib_path) catch unreachable;
|
||||
}
|
||||
|
||||
for (builder.lib_paths.toSliceConst()) |lib_path| {
|
||||
%%zig_args.append("--library-path");
|
||||
%%zig_args.append(lib_path);
|
||||
zig_args.append("--library-path") catch unreachable;
|
||||
zig_args.append(lib_path) catch unreachable;
|
||||
}
|
||||
|
||||
for (self.full_path_libs.toSliceConst()) |full_path_lib| {
|
||||
%%zig_args.append("--library");
|
||||
%%zig_args.append(builder.pathFromRoot(full_path_lib));
|
||||
zig_args.append("--library") catch unreachable;
|
||||
zig_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable;
|
||||
}
|
||||
|
||||
if (self.target.isDarwin()) {
|
||||
var it = self.frameworks.iterator();
|
||||
while (it.next()) |entry| {
|
||||
%%zig_args.append("-framework");
|
||||
%%zig_args.append(entry.key);
|
||||
zig_args.append("-framework") catch unreachable;
|
||||
zig_args.append(entry.key) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1355,46 +1355,46 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
fn appendCompileFlags(self: &LibExeObjStep, args: &ArrayList([]const u8)) {
|
||||
if (!self.strip) {
|
||||
%%args.append("-g");
|
||||
args.append("-g") catch unreachable;
|
||||
}
|
||||
switch (self.build_mode) {
|
||||
builtin.Mode.Debug => {
|
||||
if (self.disable_libc) {
|
||||
%%args.append("-fno-stack-protector");
|
||||
args.append("-fno-stack-protector") catch unreachable;
|
||||
} else {
|
||||
%%args.append("-fstack-protector-strong");
|
||||
%%args.append("--param");
|
||||
%%args.append("ssp-buffer-size=4");
|
||||
args.append("-fstack-protector-strong") catch unreachable;
|
||||
args.append("--param") catch unreachable;
|
||||
args.append("ssp-buffer-size=4") catch unreachable;
|
||||
}
|
||||
},
|
||||
builtin.Mode.ReleaseSafe => {
|
||||
%%args.append("-O2");
|
||||
args.append("-O2") catch unreachable;
|
||||
if (self.disable_libc) {
|
||||
%%args.append("-fno-stack-protector");
|
||||
args.append("-fno-stack-protector") catch unreachable;
|
||||
} else {
|
||||
%%args.append("-D_FORTIFY_SOURCE=2");
|
||||
%%args.append("-fstack-protector-strong");
|
||||
%%args.append("--param");
|
||||
%%args.append("ssp-buffer-size=4");
|
||||
args.append("-D_FORTIFY_SOURCE=2") catch unreachable;
|
||||
args.append("-fstack-protector-strong") catch unreachable;
|
||||
args.append("--param") catch unreachable;
|
||||
args.append("ssp-buffer-size=4") catch unreachable;
|
||||
}
|
||||
},
|
||||
builtin.Mode.ReleaseFast => {
|
||||
%%args.append("-O2");
|
||||
%%args.append("-fno-stack-protector");
|
||||
args.append("-O2") catch unreachable;
|
||||
args.append("-fno-stack-protector") catch unreachable;
|
||||
},
|
||||
}
|
||||
|
||||
for (self.include_dirs.toSliceConst()) |dir| {
|
||||
%%args.append("-I");
|
||||
%%args.append(self.builder.pathFromRoot(dir));
|
||||
args.append("-I") catch unreachable;
|
||||
args.append(self.builder.pathFromRoot(dir)) catch unreachable;
|
||||
}
|
||||
|
||||
for (self.cflags.toSliceConst()) |cflag| {
|
||||
%%args.append(cflag);
|
||||
args.append(cflag) catch unreachable;
|
||||
}
|
||||
|
||||
if (self.disable_libc) {
|
||||
%%args.append("-nostdlib");
|
||||
args.append("-nostdlib") catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1408,18 +1408,18 @@ pub const LibExeObjStep = struct {
|
||||
var cc_args = ArrayList([]const u8).init(builder.allocator);
|
||||
defer cc_args.deinit();
|
||||
|
||||
%%cc_args.append(cc);
|
||||
cc_args.append(cc) catch unreachable;
|
||||
|
||||
const is_darwin = self.target.isDarwin();
|
||||
|
||||
switch (self.kind) {
|
||||
Kind.Obj => {
|
||||
%%cc_args.append("-c");
|
||||
%%cc_args.append(builder.pathFromRoot(self.object_src));
|
||||
cc_args.append("-c") catch unreachable;
|
||||
cc_args.append(builder.pathFromRoot(self.object_src)) catch unreachable;
|
||||
|
||||
const output_path = builder.pathFromRoot(self.getOutputPath());
|
||||
%%cc_args.append("-o");
|
||||
%%cc_args.append(output_path);
|
||||
cc_args.append("-o") catch unreachable;
|
||||
cc_args.append(output_path) catch unreachable;
|
||||
|
||||
self.appendCompileFlags(&cc_args);
|
||||
|
||||
@@ -1427,113 +1427,113 @@ pub const LibExeObjStep = struct {
|
||||
},
|
||||
Kind.Lib => {
|
||||
for (self.source_files.toSliceConst()) |source_file| {
|
||||
%%cc_args.resize(0);
|
||||
%%cc_args.append(cc);
|
||||
cc_args.resize(0) catch unreachable;
|
||||
cc_args.append(cc) catch unreachable;
|
||||
|
||||
if (!self.static) {
|
||||
%%cc_args.append("-fPIC");
|
||||
cc_args.append("-fPIC") catch unreachable;
|
||||
}
|
||||
|
||||
const abs_source_file = builder.pathFromRoot(source_file);
|
||||
%%cc_args.append("-c");
|
||||
%%cc_args.append(abs_source_file);
|
||||
cc_args.append("-c") catch unreachable;
|
||||
cc_args.append(abs_source_file) catch unreachable;
|
||||
|
||||
const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, source_file);
|
||||
const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable;
|
||||
const cache_o_dir = os.path.dirname(cache_o_src);
|
||||
try builder.makePath(cache_o_dir);
|
||||
const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
|
||||
%%cc_args.append("-o");
|
||||
%%cc_args.append(builder.pathFromRoot(cache_o_file));
|
||||
cc_args.append("-o") catch unreachable;
|
||||
cc_args.append(builder.pathFromRoot(cache_o_file)) catch unreachable;
|
||||
|
||||
self.appendCompileFlags(&cc_args);
|
||||
|
||||
try builder.spawnChild(cc_args.toSliceConst());
|
||||
|
||||
%%self.object_files.append(cache_o_file);
|
||||
self.object_files.append(cache_o_file) catch unreachable;
|
||||
}
|
||||
|
||||
if (self.static) {
|
||||
// ar
|
||||
%%cc_args.resize(0);
|
||||
%%cc_args.append("ar");
|
||||
cc_args.resize(0) catch unreachable;
|
||||
cc_args.append("ar") catch unreachable;
|
||||
|
||||
%%cc_args.append("qc");
|
||||
cc_args.append("qc") catch unreachable;
|
||||
|
||||
const output_path = builder.pathFromRoot(self.getOutputPath());
|
||||
%%cc_args.append(output_path);
|
||||
cc_args.append(output_path) catch unreachable;
|
||||
|
||||
for (self.object_files.toSliceConst()) |object_file| {
|
||||
%%cc_args.append(builder.pathFromRoot(object_file));
|
||||
cc_args.append(builder.pathFromRoot(object_file)) catch unreachable;
|
||||
}
|
||||
|
||||
try builder.spawnChild(cc_args.toSliceConst());
|
||||
|
||||
// ranlib
|
||||
%%cc_args.resize(0);
|
||||
%%cc_args.append("ranlib");
|
||||
%%cc_args.append(output_path);
|
||||
cc_args.resize(0) catch unreachable;
|
||||
cc_args.append("ranlib") catch unreachable;
|
||||
cc_args.append(output_path) catch unreachable;
|
||||
|
||||
try builder.spawnChild(cc_args.toSliceConst());
|
||||
} else {
|
||||
%%cc_args.resize(0);
|
||||
%%cc_args.append(cc);
|
||||
cc_args.resize(0) catch unreachable;
|
||||
cc_args.append(cc) catch unreachable;
|
||||
|
||||
if (is_darwin) {
|
||||
%%cc_args.append("-dynamiclib");
|
||||
cc_args.append("-dynamiclib") catch unreachable;
|
||||
|
||||
%%cc_args.append("-Wl,-headerpad_max_install_names");
|
||||
cc_args.append("-Wl,-headerpad_max_install_names") catch unreachable;
|
||||
|
||||
%%cc_args.append("-compatibility_version");
|
||||
%%cc_args.append(builder.fmt("{}.0.0", self.version.major));
|
||||
cc_args.append("-compatibility_version") catch unreachable;
|
||||
cc_args.append(builder.fmt("{}.0.0", self.version.major)) catch unreachable;
|
||||
|
||||
%%cc_args.append("-current_version");
|
||||
%%cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch));
|
||||
cc_args.append("-current_version") catch unreachable;
|
||||
cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch)) catch unreachable;
|
||||
|
||||
const install_name = builder.pathFromRoot(%%os.path.join(builder.allocator, builder.cache_root, self.major_only_filename));
|
||||
%%cc_args.append("-install_name");
|
||||
%%cc_args.append(install_name);
|
||||
const install_name = builder.pathFromRoot(os.path.join(builder.allocator, builder.cache_root, self.major_only_filename) catch unreachable);
|
||||
cc_args.append("-install_name") catch unreachable;
|
||||
cc_args.append(install_name) catch unreachable;
|
||||
} else {
|
||||
%%cc_args.append("-fPIC");
|
||||
%%cc_args.append("-shared");
|
||||
cc_args.append("-fPIC") catch unreachable;
|
||||
cc_args.append("-shared") catch unreachable;
|
||||
|
||||
const soname_arg = builder.fmt("-Wl,-soname,lib{}.so.{d}", self.name, self.version.major);
|
||||
defer builder.allocator.free(soname_arg);
|
||||
%%cc_args.append(soname_arg);
|
||||
cc_args.append(soname_arg) catch unreachable;
|
||||
}
|
||||
|
||||
const output_path = builder.pathFromRoot(self.getOutputPath());
|
||||
%%cc_args.append("-o");
|
||||
%%cc_args.append(output_path);
|
||||
cc_args.append("-o") catch unreachable;
|
||||
cc_args.append(output_path) catch unreachable;
|
||||
|
||||
for (self.object_files.toSliceConst()) |object_file| {
|
||||
%%cc_args.append(builder.pathFromRoot(object_file));
|
||||
cc_args.append(builder.pathFromRoot(object_file)) catch unreachable;
|
||||
}
|
||||
|
||||
if (!is_darwin) {
|
||||
const rpath_arg = builder.fmt("-Wl,-rpath,{}",
|
||||
%%os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root)));
|
||||
os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root)) catch unreachable);
|
||||
defer builder.allocator.free(rpath_arg);
|
||||
%%cc_args.append(rpath_arg);
|
||||
cc_args.append(rpath_arg) catch unreachable;
|
||||
|
||||
%%cc_args.append("-rdynamic");
|
||||
cc_args.append("-rdynamic") catch unreachable;
|
||||
}
|
||||
|
||||
for (self.full_path_libs.toSliceConst()) |full_path_lib| {
|
||||
%%cc_args.append(builder.pathFromRoot(full_path_lib));
|
||||
cc_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable;
|
||||
}
|
||||
|
||||
{
|
||||
var it = self.link_libs.iterator();
|
||||
while (it.next()) |entry| {
|
||||
%%cc_args.append(builder.fmt("-l{}", entry.key));
|
||||
cc_args.append(builder.fmt("-l{}", entry.key)) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_darwin and !self.static) {
|
||||
var it = self.frameworks.iterator();
|
||||
while (it.next()) |entry| {
|
||||
%%cc_args.append("-framework");
|
||||
%%cc_args.append(entry.key);
|
||||
cc_args.append("-framework") catch unreachable;
|
||||
cc_args.append(entry.key) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1547,75 +1547,75 @@ pub const LibExeObjStep = struct {
|
||||
},
|
||||
Kind.Exe => {
|
||||
for (self.source_files.toSliceConst()) |source_file| {
|
||||
%%cc_args.resize(0);
|
||||
%%cc_args.append(cc);
|
||||
cc_args.resize(0) catch unreachable;
|
||||
cc_args.append(cc) catch unreachable;
|
||||
|
||||
const abs_source_file = builder.pathFromRoot(source_file);
|
||||
%%cc_args.append("-c");
|
||||
%%cc_args.append(abs_source_file);
|
||||
cc_args.append("-c") catch unreachable;
|
||||
cc_args.append(abs_source_file) catch unreachable;
|
||||
|
||||
const cache_o_src = %%os.path.join(builder.allocator, builder.cache_root, source_file);
|
||||
const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable;
|
||||
const cache_o_dir = os.path.dirname(cache_o_src);
|
||||
try builder.makePath(cache_o_dir);
|
||||
const cache_o_file = builder.fmt("{}{}", cache_o_src, self.target.oFileExt());
|
||||
%%cc_args.append("-o");
|
||||
%%cc_args.append(builder.pathFromRoot(cache_o_file));
|
||||
cc_args.append("-o") catch unreachable;
|
||||
cc_args.append(builder.pathFromRoot(cache_o_file)) catch unreachable;
|
||||
|
||||
for (self.cflags.toSliceConst()) |cflag| {
|
||||
%%cc_args.append(cflag);
|
||||
cc_args.append(cflag) catch unreachable;
|
||||
}
|
||||
|
||||
for (self.include_dirs.toSliceConst()) |dir| {
|
||||
%%cc_args.append("-I");
|
||||
%%cc_args.append(builder.pathFromRoot(dir));
|
||||
cc_args.append("-I") catch unreachable;
|
||||
cc_args.append(builder.pathFromRoot(dir)) catch unreachable;
|
||||
}
|
||||
|
||||
try builder.spawnChild(cc_args.toSliceConst());
|
||||
|
||||
%%self.object_files.append(cache_o_file);
|
||||
self.object_files.append(cache_o_file) catch unreachable;
|
||||
}
|
||||
|
||||
%%cc_args.resize(0);
|
||||
%%cc_args.append(cc);
|
||||
cc_args.resize(0) catch unreachable;
|
||||
cc_args.append(cc) catch unreachable;
|
||||
|
||||
for (self.object_files.toSliceConst()) |object_file| {
|
||||
%%cc_args.append(builder.pathFromRoot(object_file));
|
||||
cc_args.append(builder.pathFromRoot(object_file)) catch unreachable;
|
||||
}
|
||||
|
||||
const output_path = builder.pathFromRoot(self.getOutputPath());
|
||||
%%cc_args.append("-o");
|
||||
%%cc_args.append(output_path);
|
||||
cc_args.append("-o") catch unreachable;
|
||||
cc_args.append(output_path) catch unreachable;
|
||||
|
||||
const rpath_arg = builder.fmt("-Wl,-rpath,{}",
|
||||
%%os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root)));
|
||||
os.path.real(builder.allocator, builder.pathFromRoot(builder.cache_root)) catch unreachable);
|
||||
defer builder.allocator.free(rpath_arg);
|
||||
%%cc_args.append(rpath_arg);
|
||||
cc_args.append(rpath_arg) catch unreachable;
|
||||
|
||||
%%cc_args.append("-rdynamic");
|
||||
cc_args.append("-rdynamic") catch unreachable;
|
||||
|
||||
{
|
||||
var it = self.link_libs.iterator();
|
||||
while (it.next()) |entry| {
|
||||
%%cc_args.append(builder.fmt("-l{}", entry.key));
|
||||
cc_args.append(builder.fmt("-l{}", entry.key)) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_darwin) {
|
||||
if (self.need_flat_namespace_hack) {
|
||||
%%cc_args.append("-Wl,-flat_namespace");
|
||||
cc_args.append("-Wl,-flat_namespace") catch unreachable;
|
||||
}
|
||||
%%cc_args.append("-Wl,-search_paths_first");
|
||||
cc_args.append("-Wl,-search_paths_first") catch unreachable;
|
||||
}
|
||||
|
||||
for (self.full_path_libs.toSliceConst()) |full_path_lib| {
|
||||
%%cc_args.append(builder.pathFromRoot(full_path_lib));
|
||||
cc_args.append(builder.pathFromRoot(full_path_lib)) catch unreachable;
|
||||
}
|
||||
|
||||
if (is_darwin) {
|
||||
var it = self.frameworks.iterator();
|
||||
while (it.next()) |entry| {
|
||||
%%cc_args.append("-framework");
|
||||
%%cc_args.append(entry.key);
|
||||
cc_args.append("-framework") catch unreachable;
|
||||
cc_args.append(entry.key) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1662,7 +1662,7 @@ pub const TestStep = struct {
|
||||
}
|
||||
|
||||
pub fn linkSystemLibrary(self: &TestStep, name: []const u8) {
|
||||
%%self.link_libs.put(name);
|
||||
self.link_libs.put(name) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setNamePrefix(self: &TestStep, text: []const u8) {
|
||||
@@ -1696,78 +1696,78 @@ pub const TestStep = struct {
|
||||
var zig_args = ArrayList([]const u8).init(builder.allocator);
|
||||
defer zig_args.deinit();
|
||||
|
||||
%%zig_args.append(builder.zig_exe);
|
||||
try zig_args.append(builder.zig_exe);
|
||||
|
||||
%%zig_args.append("test");
|
||||
%%zig_args.append(builder.pathFromRoot(self.root_src));
|
||||
try zig_args.append("test");
|
||||
try zig_args.append(builder.pathFromRoot(self.root_src));
|
||||
|
||||
if (self.verbose) {
|
||||
%%zig_args.append("--verbose");
|
||||
try zig_args.append("--verbose");
|
||||
}
|
||||
|
||||
switch (self.build_mode) {
|
||||
builtin.Mode.Debug => {},
|
||||
builtin.Mode.ReleaseSafe => %%zig_args.append("--release-safe"),
|
||||
builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"),
|
||||
builtin.Mode.ReleaseSafe => try zig_args.append("--release-safe"),
|
||||
builtin.Mode.ReleaseFast => try zig_args.append("--release-fast"),
|
||||
}
|
||||
|
||||
switch (self.target) {
|
||||
Target.Native => {},
|
||||
Target.Cross => |cross_target| {
|
||||
%%zig_args.append("--target-arch");
|
||||
%%zig_args.append(@tagName(cross_target.arch));
|
||||
try zig_args.append("--target-arch");
|
||||
try zig_args.append(@tagName(cross_target.arch));
|
||||
|
||||
%%zig_args.append("--target-os");
|
||||
%%zig_args.append(@tagName(cross_target.os));
|
||||
try zig_args.append("--target-os");
|
||||
try zig_args.append(@tagName(cross_target.os));
|
||||
|
||||
%%zig_args.append("--target-environ");
|
||||
%%zig_args.append(@tagName(cross_target.environ));
|
||||
try zig_args.append("--target-environ");
|
||||
try zig_args.append(@tagName(cross_target.environ));
|
||||
},
|
||||
}
|
||||
|
||||
if (self.filter) |filter| {
|
||||
%%zig_args.append("--test-filter");
|
||||
%%zig_args.append(filter);
|
||||
try zig_args.append("--test-filter");
|
||||
try zig_args.append(filter);
|
||||
}
|
||||
|
||||
if (self.name_prefix.len != 0) {
|
||||
%%zig_args.append("--test-name-prefix");
|
||||
%%zig_args.append(self.name_prefix);
|
||||
try zig_args.append("--test-name-prefix");
|
||||
try zig_args.append(self.name_prefix);
|
||||
}
|
||||
|
||||
{
|
||||
var it = self.link_libs.iterator();
|
||||
while (true) {
|
||||
const entry = it.next() ?? break;
|
||||
%%zig_args.append("--library");
|
||||
%%zig_args.append(entry.key);
|
||||
try zig_args.append("--library");
|
||||
try zig_args.append(entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
if (self.exec_cmd_args) |exec_cmd_args| {
|
||||
for (exec_cmd_args) |cmd_arg| {
|
||||
if (cmd_arg) |arg| {
|
||||
%%zig_args.append("--test-cmd");
|
||||
%%zig_args.append(arg);
|
||||
try zig_args.append("--test-cmd");
|
||||
try zig_args.append(arg);
|
||||
} else {
|
||||
%%zig_args.append("--test-cmd-bin");
|
||||
try zig_args.append("--test-cmd-bin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (builder.include_paths.toSliceConst()) |include_path| {
|
||||
%%zig_args.append("-isystem");
|
||||
%%zig_args.append(builder.pathFromRoot(include_path));
|
||||
try zig_args.append("-isystem");
|
||||
try zig_args.append(builder.pathFromRoot(include_path));
|
||||
}
|
||||
|
||||
for (builder.rpaths.toSliceConst()) |rpath| {
|
||||
%%zig_args.append("-rpath");
|
||||
%%zig_args.append(rpath);
|
||||
try zig_args.append("-rpath");
|
||||
try zig_args.append(rpath);
|
||||
}
|
||||
|
||||
for (builder.lib_paths.toSliceConst()) |lib_path| {
|
||||
%%zig_args.append("--library-path");
|
||||
%%zig_args.append(lib_path);
|
||||
try zig_args.append("--library-path");
|
||||
try zig_args.append(lib_path);
|
||||
}
|
||||
|
||||
try builder.spawnChild(zig_args.toSliceConst());
|
||||
@@ -1785,11 +1785,11 @@ pub const CommandStep = struct {
|
||||
pub fn create(builder: &Builder, cwd: ?[]const u8, env_map: &const BufMap,
|
||||
argv: []const []const u8) -> &CommandStep
|
||||
{
|
||||
const self = %%builder.allocator.create(CommandStep);
|
||||
const self = builder.allocator.create(CommandStep) catch unreachable;
|
||||
*self = CommandStep {
|
||||
.builder = builder,
|
||||
.step = Step.init(argv[0], builder.allocator, make),
|
||||
.argv = %%builder.allocator.alloc([]u8, argv.len),
|
||||
.argv = builder.allocator.alloc([]u8, argv.len) catch unreachable,
|
||||
.cwd = cwd,
|
||||
.env_map = env_map,
|
||||
};
|
||||
@@ -1815,7 +1815,7 @@ const InstallArtifactStep = struct {
|
||||
const Self = this;
|
||||
|
||||
pub fn create(builder: &Builder, artifact: &LibExeObjStep) -> &Self {
|
||||
const self = %%builder.allocator.create(Self);
|
||||
const self = builder.allocator.create(Self) catch unreachable;
|
||||
const dest_dir = switch (artifact.kind) {
|
||||
LibExeObjStep.Kind.Obj => unreachable,
|
||||
LibExeObjStep.Kind.Exe => builder.exe_dir,
|
||||
@@ -1825,15 +1825,15 @@ const InstallArtifactStep = struct {
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
|
||||
.artifact = artifact,
|
||||
.dest_file = %%os.path.join(builder.allocator, dest_dir, artifact.out_filename),
|
||||
.dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable,
|
||||
};
|
||||
self.step.dependOn(&artifact.step);
|
||||
builder.pushInstalledFile(self.dest_file);
|
||||
if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
|
||||
builder.pushInstalledFile(%%os.path.join(builder.allocator, builder.lib_dir,
|
||||
artifact.major_only_filename));
|
||||
builder.pushInstalledFile(%%os.path.join(builder.allocator, builder.lib_dir,
|
||||
artifact.name_only_filename));
|
||||
builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir,
|
||||
artifact.major_only_filename) catch unreachable);
|
||||
builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir,
|
||||
artifact.name_only_filename) catch unreachable);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -1978,7 +1978,7 @@ pub const Step = struct {
|
||||
}
|
||||
|
||||
pub fn dependOn(self: &Step, other: &Step) {
|
||||
%%self.dependencies.append(other);
|
||||
self.dependencies.append(other) catch unreachable;
|
||||
}
|
||||
|
||||
fn makeNoOp(self: &Step) -> %void {}
|
||||
@@ -1990,13 +1990,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj
|
||||
const out_dir = os.path.dirname(output_path);
|
||||
const out_basename = os.path.basename(output_path);
|
||||
// sym link for libfoo.so.1 to libfoo.so.1.2.3
|
||||
const major_only_path = %%os.path.join(allocator, out_dir, filename_major_only);
|
||||
const major_only_path = os.path.join(allocator, out_dir, filename_major_only) catch unreachable;
|
||||
os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
|
||||
warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
|
||||
return err;
|
||||
};
|
||||
// sym link for libfoo.so to libfoo.so.1
|
||||
const name_only_path = %%os.path.join(allocator, out_dir, filename_name_only);
|
||||
const name_only_path = os.path.join(allocator, out_dir, filename_name_only) catch unreachable;
|
||||
os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
|
||||
warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
|
||||
return err;
|
||||
|
||||
+24
-24
@@ -123,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
|
||||
},
|
||||
State.IntegerWidth => switch (c) {
|
||||
'}' => {
|
||||
width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
|
||||
width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
|
||||
try formatInt(args[next_arg], radix, uppercase, width, context, output);
|
||||
next_arg += 1;
|
||||
state = State.Start;
|
||||
@@ -147,7 +147,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
|
||||
},
|
||||
State.FloatWidth => switch (c) {
|
||||
'}' => {
|
||||
width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
|
||||
width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
|
||||
try formatFloatDecimal(args[next_arg], width, context, output);
|
||||
next_arg += 1;
|
||||
state = State.Start;
|
||||
@@ -158,7 +158,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
|
||||
},
|
||||
State.BufWidth => switch (c) {
|
||||
'}' => {
|
||||
width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
|
||||
width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
|
||||
try formatBuf(args[next_arg], width, context, output);
|
||||
next_arg += 1;
|
||||
state = State.Start;
|
||||
@@ -410,7 +410,7 @@ pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width:
|
||||
.out_buf = out_buf,
|
||||
.index = 0,
|
||||
};
|
||||
%%formatInt(value, base, uppercase, width, &context, formatIntCallback);
|
||||
formatInt(value, base, uppercase, width, &context, formatIntCallback) catch unreachable;
|
||||
return context.index;
|
||||
}
|
||||
const FormatIntBuf = struct {
|
||||
@@ -437,12 +437,12 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T {
|
||||
}
|
||||
|
||||
test "fmt.parseInt" {
|
||||
assert(%%parseInt(i32, "-10", 10) == -10);
|
||||
assert(%%parseInt(i32, "+10", 10) == 10);
|
||||
assert((parseInt(i32, "-10", 10) catch unreachable) == -10);
|
||||
assert((parseInt(i32, "+10", 10) catch unreachable) == 10);
|
||||
assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidChar);
|
||||
assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidChar);
|
||||
assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidChar);
|
||||
assert(%%parseInt(u8, "255", 10) == 255);
|
||||
assert((parseInt(u8, "255", 10) catch unreachable) == 255);
|
||||
assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 {
|
||||
pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {
|
||||
var size: usize = 0;
|
||||
// Cannot fail because `countSize` cannot fail.
|
||||
%%format(&size, countSize, fmt, args);
|
||||
format(&size, countSize, fmt, args) catch unreachable;
|
||||
const buf = try allocator.alloc(u8, size);
|
||||
return bufPrint(buf, fmt, args);
|
||||
}
|
||||
@@ -542,7 +542,7 @@ test "parse u64 digit too big" {
|
||||
|
||||
test "parse unsigned comptime" {
|
||||
comptime {
|
||||
assert(%%parseUnsigned(usize, "2", 10) == 2);
|
||||
assert((try parseUnsigned(usize, "2", 10)) == 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,31 +550,31 @@ test "fmt.format" {
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: ?i32 = 1234;
|
||||
const result = %%bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
assert(mem.eql(u8, result, "nullable: 1234\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: ?i32 = null;
|
||||
const result = %%bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
assert(mem.eql(u8, result, "nullable: null\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: %i32 = 1234;
|
||||
const result = %%bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
assert(mem.eql(u8, result, "error union: 1234\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: %i32 = error.InvalidChar;
|
||||
const result = %%bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: u3 = 0b101;
|
||||
const result = %%bufPrint(buf1[0..], "u3: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "u3: {}\n", value);
|
||||
assert(mem.eql(u8, result, "u3: 5\n"));
|
||||
}
|
||||
|
||||
@@ -584,46 +584,46 @@ test "fmt.format" {
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 12.34;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 1.23400001e1\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f64 = -12.34e10;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", value);
|
||||
assert(mem.eql(u8, result, "f64: -1.234e11\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
|
||||
assert(mem.eql(u8, result, "f64: NaN\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);
|
||||
assert(mem.eql(u8, result, "f64: Infinity\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);
|
||||
assert(mem.eql(u8, result, "f64: -Infinity\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 1.1234;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.1}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.1}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 1.1\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 1234.567;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.2}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.2}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 1234.56\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = -11.1234;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.4}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.4}\n", value);
|
||||
// -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
|
||||
// -11.12339... is truncated to -11.1233
|
||||
assert(mem.eql(u8, result, "f32: -11.1233\n"));
|
||||
@@ -631,13 +631,13 @@ test "fmt.format" {
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 91.12345;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 91.12345\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f64 = 91.12345678901235;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {.10}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f64: {.10}\n", value);
|
||||
assert(mem.eql(u8, result, "f64: 91.1234567890\n"));
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -236,14 +236,14 @@ test "basicHashMapTest" {
|
||||
var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
|
||||
defer map.deinit();
|
||||
|
||||
assert(%%map.put(1, 11) == null);
|
||||
assert(%%map.put(2, 22) == null);
|
||||
assert(%%map.put(3, 33) == null);
|
||||
assert(%%map.put(4, 44) == null);
|
||||
assert(%%map.put(5, 55) == null);
|
||||
assert((map.put(1, 11) catch unreachable) == null);
|
||||
assert((map.put(2, 22) catch unreachable) == null);
|
||||
assert((map.put(3, 33) catch unreachable) == null);
|
||||
assert((map.put(4, 44) catch unreachable) == null);
|
||||
assert((map.put(5, 55) catch unreachable) == null);
|
||||
|
||||
assert(??%%map.put(5, 66) == 55);
|
||||
assert(??%%map.put(5, 55) == 66);
|
||||
assert(??(map.put(5, 66) catch unreachable) == 55);
|
||||
assert(??(map.put(5, 55) catch unreachable) == 66);
|
||||
|
||||
assert((??map.get(2)).value == 22);
|
||||
_ = map.remove(2);
|
||||
|
||||
+3
-3
@@ -145,14 +145,14 @@ test "c_allocator" {
|
||||
|
||||
test "IncrementingAllocator" {
|
||||
const total_bytes = 100 * 1024 * 1024;
|
||||
var inc_allocator = %%IncrementingAllocator.init(total_bytes);
|
||||
var inc_allocator = try IncrementingAllocator.init(total_bytes);
|
||||
defer inc_allocator.deinit();
|
||||
|
||||
const allocator = &inc_allocator.allocator;
|
||||
const slice = %%allocator.alloc(&i32, 100);
|
||||
const slice = try allocator.alloc(&i32, 100);
|
||||
|
||||
for (slice) |*item, i| {
|
||||
*item = %%allocator.create(i32);
|
||||
*item = try allocator.create(i32);
|
||||
**item = i32(i);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -18,34 +18,34 @@ test "write a file, read it, then delete it" {
|
||||
rng.fillBytes(data[0..]);
|
||||
const tmp_file_name = "temp_test_file.txt";
|
||||
{
|
||||
var file = %%io.File.openWrite(tmp_file_name, allocator);
|
||||
var file = try io.File.openWrite(tmp_file_name, allocator);
|
||||
defer file.close();
|
||||
|
||||
var file_out_stream = io.FileOutStream.init(&file);
|
||||
var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream);
|
||||
const st = &buf_stream.stream;
|
||||
%%st.print("begin");
|
||||
%%st.write(data[0..]);
|
||||
%%st.print("end");
|
||||
%%buf_stream.flush();
|
||||
try st.print("begin");
|
||||
try st.write(data[0..]);
|
||||
try st.print("end");
|
||||
try buf_stream.flush();
|
||||
}
|
||||
{
|
||||
var file = %%io.File.openRead(tmp_file_name, allocator);
|
||||
var file = try io.File.openRead(tmp_file_name, allocator);
|
||||
defer file.close();
|
||||
|
||||
const file_size = %%file.getEndPos();
|
||||
const file_size = try file.getEndPos();
|
||||
const expected_file_size = "begin".len + data.len + "end".len;
|
||||
assert(file_size == expected_file_size);
|
||||
|
||||
var file_in_stream = io.FileInStream.init(&file);
|
||||
var buf_stream = io.BufferedInStream.init(&file_in_stream.stream);
|
||||
const st = &buf_stream.stream;
|
||||
const contents = %%st.readAllAlloc(allocator, 2 * 1024);
|
||||
const contents = try st.readAllAlloc(allocator, 2 * 1024);
|
||||
defer allocator.free(contents);
|
||||
|
||||
assert(mem.eql(u8, contents[0.."begin".len], "begin"));
|
||||
assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data));
|
||||
assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
|
||||
}
|
||||
%%os.deleteFile(allocator, tmp_file_name);
|
||||
try os.deleteFile(allocator, tmp_file_name);
|
||||
}
|
||||
|
||||
+5
-5
@@ -199,11 +199,11 @@ test "basic linked list test" {
|
||||
const allocator = debug.global_allocator;
|
||||
var list = LinkedList(u32).init();
|
||||
|
||||
var one = %%list.createNode(1, allocator);
|
||||
var two = %%list.createNode(2, allocator);
|
||||
var three = %%list.createNode(3, allocator);
|
||||
var four = %%list.createNode(4, allocator);
|
||||
var five = %%list.createNode(5, allocator);
|
||||
var one = list.createNode(1, allocator) catch unreachable;
|
||||
var two = list.createNode(2, allocator) catch unreachable;
|
||||
var three = list.createNode(3, allocator) catch unreachable;
|
||||
var four = list.createNode(4, allocator) catch unreachable;
|
||||
var five = list.createNode(5, allocator) catch unreachable;
|
||||
defer {
|
||||
list.destroyNode(one, allocator);
|
||||
list.destroyNode(two, allocator);
|
||||
|
||||
+30
-30
@@ -277,10 +277,10 @@ test "math overflow functions" {
|
||||
}
|
||||
|
||||
fn testOverflow() {
|
||||
assert(%%mul(i32, 3, 4) == 12);
|
||||
assert(%%add(i32, 3, 4) == 7);
|
||||
assert(%%sub(i32, 3, 4) == -1);
|
||||
assert(%%shlExact(i32, 0b11, 4) == 0b110000);
|
||||
assert((mul(i32, 3, 4) catch unreachable) == 12);
|
||||
assert((add(i32, 3, 4) catch unreachable) == 7);
|
||||
assert((sub(i32, 3, 4) catch unreachable) == -1);
|
||||
assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
|
||||
}
|
||||
|
||||
|
||||
@@ -302,8 +302,8 @@ test "math.absInt" {
|
||||
comptime testAbsInt();
|
||||
}
|
||||
fn testAbsInt() {
|
||||
assert(%%absInt(i32(-10)) == 10);
|
||||
assert(%%absInt(i32(10)) == 10);
|
||||
assert((absInt(i32(-10)) catch unreachable) == 10);
|
||||
assert((absInt(i32(10)) catch unreachable) == 10);
|
||||
}
|
||||
|
||||
pub const absFloat = @import("fabs.zig").fabs;
|
||||
@@ -329,13 +329,13 @@ test "math.divTrunc" {
|
||||
comptime testDivTrunc();
|
||||
}
|
||||
fn testDivTrunc() {
|
||||
assert(%%divTrunc(i32, 5, 3) == 1);
|
||||
assert(%%divTrunc(i32, -5, 3) == -1);
|
||||
assert((divTrunc(i32, 5, 3) catch unreachable) == 1);
|
||||
assert((divTrunc(i32, -5, 3) catch unreachable) == -1);
|
||||
if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
|
||||
assert(%%divTrunc(f32, 5.0, 3.0) == 1.0);
|
||||
assert(%%divTrunc(f32, -5.0, 3.0) == -1.0);
|
||||
assert((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
|
||||
assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
|
||||
}
|
||||
|
||||
error DivisionByZero;
|
||||
@@ -359,13 +359,13 @@ test "math.divFloor" {
|
||||
comptime testDivFloor();
|
||||
}
|
||||
fn testDivFloor() {
|
||||
assert(%%divFloor(i32, 5, 3) == 1);
|
||||
assert(%%divFloor(i32, -5, 3) == -2);
|
||||
assert((divFloor(i32, 5, 3) catch unreachable) == 1);
|
||||
assert((divFloor(i32, -5, 3) catch unreachable) == -2);
|
||||
if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
|
||||
assert(%%divFloor(f32, 5.0, 3.0) == 1.0);
|
||||
assert(%%divFloor(f32, -5.0, 3.0) == -2.0);
|
||||
assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
|
||||
assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
|
||||
}
|
||||
|
||||
error DivisionByZero;
|
||||
@@ -393,14 +393,14 @@ test "math.divExact" {
|
||||
comptime testDivExact();
|
||||
}
|
||||
fn testDivExact() {
|
||||
assert(%%divExact(i32, 10, 5) == 2);
|
||||
assert(%%divExact(i32, -10, 5) == -2);
|
||||
assert((divExact(i32, 10, 5) catch unreachable) == 2);
|
||||
assert((divExact(i32, -10, 5) catch unreachable) == -2);
|
||||
if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
|
||||
|
||||
assert(%%divExact(f32, 10.0, 5.0) == 2.0);
|
||||
assert(%%divExact(f32, -10.0, 5.0) == -2.0);
|
||||
assert((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
|
||||
assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
|
||||
if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
|
||||
}
|
||||
|
||||
@@ -420,13 +420,13 @@ test "math.mod" {
|
||||
comptime testMod();
|
||||
}
|
||||
fn testMod() {
|
||||
assert(%%mod(i32, -5, 3) == 1);
|
||||
assert(%%mod(i32, 5, 3) == 2);
|
||||
assert((mod(i32, -5, 3) catch unreachable) == 1);
|
||||
assert((mod(i32, 5, 3) catch unreachable) == 2);
|
||||
if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
|
||||
assert(%%mod(f32, -5, 3) == 1);
|
||||
assert(%%mod(f32, 5, 3) == 2);
|
||||
assert((mod(f32, -5, 3) catch unreachable) == 1);
|
||||
assert((mod(f32, 5, 3) catch unreachable) == 2);
|
||||
if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
}
|
||||
@@ -447,13 +447,13 @@ test "math.rem" {
|
||||
comptime testRem();
|
||||
}
|
||||
fn testRem() {
|
||||
assert(%%rem(i32, -5, 3) == -2);
|
||||
assert(%%rem(i32, 5, 3) == 2);
|
||||
assert((rem(i32, -5, 3) catch unreachable) == -2);
|
||||
assert((rem(i32, 5, 3) catch unreachable) == 2);
|
||||
if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
|
||||
assert(%%rem(f32, -5, 3) == -2);
|
||||
assert(%%rem(f32, 5, 3) == 2);
|
||||
assert((rem(f32, -5, 3) catch unreachable) == -2);
|
||||
assert((rem(f32, 5, 3) catch unreachable) == 2);
|
||||
if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
}
|
||||
@@ -497,11 +497,11 @@ pub fn negateCast(x: var) -> %@IntType(true, @typeOf(x).bit_count) {
|
||||
}
|
||||
|
||||
test "math.negateCast" {
|
||||
assert(%%negateCast(u32(999)) == -999);
|
||||
assert(@typeOf(%%negateCast(u32(999))) == i32);
|
||||
assert((negateCast(u32(999)) catch unreachable) == -999);
|
||||
assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
|
||||
|
||||
assert(%%negateCast(u32(-@minValue(i32))) == @minValue(i32));
|
||||
assert(@typeOf(%%negateCast(u32(-@minValue(i32)))) == i32);
|
||||
assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32));
|
||||
assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32);
|
||||
|
||||
if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
}
|
||||
|
||||
+3
-3
@@ -93,7 +93,7 @@ pub const Allocator = struct {
|
||||
// n <= old_mem.len and the multiplication didn't overflow for that operation.
|
||||
const byte_count = @sizeOf(T) * n;
|
||||
|
||||
const byte_slice = %%self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment);
|
||||
const byte_slice = self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment) catch unreachable;
|
||||
return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
|
||||
}
|
||||
|
||||
@@ -446,8 +446,8 @@ pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 {
|
||||
}
|
||||
|
||||
test "mem.join" {
|
||||
assert(eql(u8, %%join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c"));
|
||||
assert(eql(u8, %%join(debug.global_allocator, ',', "a"), "a"));
|
||||
assert(eql(u8, try join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c"));
|
||||
assert(eql(u8, try join(debug.global_allocator, ',', "a"), "a"));
|
||||
}
|
||||
|
||||
test "testStringEquality" {
|
||||
|
||||
+2
-87
@@ -3,6 +3,8 @@ const linux = std.os.linux;
|
||||
const assert = std.debug.assert;
|
||||
const endian = std.endian;
|
||||
|
||||
// TODO don't trust this file, it bit rotted. start over
|
||||
|
||||
error SigInterrupt;
|
||||
error Io;
|
||||
error TimedOut;
|
||||
@@ -67,24 +69,9 @@ const Address = struct {
|
||||
pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
|
||||
if (hostname.len == 0) {
|
||||
|
||||
//
|
||||
// if (family != AF_INET6)
|
||||
// buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } };
|
||||
// if (family != AF_INET)
|
||||
// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
|
||||
//
|
||||
unreachable; // TODO
|
||||
}
|
||||
|
||||
// TODO
|
||||
//switch (parseIpLiteral(hostname)) {
|
||||
// Ok => |addr| {
|
||||
// out_addrs[0] = addr;
|
||||
// return out_addrs[0..1];
|
||||
// },
|
||||
// else => {},
|
||||
//};
|
||||
|
||||
unreachable; // TODO
|
||||
}
|
||||
|
||||
@@ -142,23 +129,6 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection {
|
||||
error InvalidIpLiteral;
|
||||
|
||||
pub fn parseIpLiteral(buf: []const u8) -> %Address {
|
||||
// TODO
|
||||
//switch (parseIp4(buf)) {
|
||||
// Ok => |ip4| {
|
||||
// var result: Address = undefined;
|
||||
// @memcpy(&result.addr[0], (&u8)(&ip4), @sizeOf(u32));
|
||||
// result.family = linux.AF_INET;
|
||||
// result.scope_id = 0;
|
||||
// return result;
|
||||
// },
|
||||
// else => {},
|
||||
//}
|
||||
//switch (parseIp6(buf)) {
|
||||
// Ok => |addr| {
|
||||
// return addr;
|
||||
// },
|
||||
// else => {},
|
||||
//}
|
||||
|
||||
return error.InvalidIpLiteral;
|
||||
}
|
||||
@@ -249,21 +219,6 @@ fn parseIp6(buf: []const u8) -> %Address {
|
||||
return error.Incomplete;
|
||||
}
|
||||
|
||||
//
|
||||
// if (p) {
|
||||
// if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
|
||||
// else z = p-1;
|
||||
// if (*z) {
|
||||
// if (!IN6_IS_ADDR_LINKLOCAL(&a6) and
|
||||
// !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
|
||||
// return EAI_NONAME;
|
||||
// scopeid = if_nametoindex(p);
|
||||
// if (!scopeid) return EAI_NONAME;
|
||||
// }
|
||||
// if (scopeid > UINT_MAX) return EAI_NONAME;
|
||||
// }
|
||||
//
|
||||
|
||||
if (scope_id) {
|
||||
return result;
|
||||
}
|
||||
@@ -316,43 +271,3 @@ fn parseIp4(buf: []const u8) -> %u32 {
|
||||
|
||||
return error.Incomplete;
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
//fn testParseIp4() {
|
||||
// @setFnTest(this);
|
||||
//
|
||||
// assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));
|
||||
// switch (parseIp4("256.0.0.1")) { Overflow => {}, else => unreachable, }
|
||||
// switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => unreachable, }
|
||||
// switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => unreachable, }
|
||||
// switch (parseIp4("127.0.0.")) { Incomplete => {}, else => unreachable, }
|
||||
// switch (parseIp4("100..0.1")) { InvalidChar => {}, else => unreachable, }
|
||||
//}
|
||||
//
|
||||
//fn testParseIp6() {
|
||||
// @setFnTest(this);
|
||||
//
|
||||
// {
|
||||
// const addr = %%parseIp6("FF01:0:0:0:0:0:0:FB");
|
||||
// assert(addr.addr[0] == 0xff);
|
||||
// assert(addr.addr[1] == 0x01);
|
||||
// assert(addr.addr[2] == 0x00);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fn testLookupSimpleIp() {
|
||||
// @setFnTest(this);
|
||||
//
|
||||
// {
|
||||
// var addrs_buf: [5]Address = undefined;
|
||||
// const addrs = %%lookup("192.168.1.1", addrs_buf);
|
||||
// assert(addrs.len == 1);
|
||||
// const addr = addrs[0];
|
||||
// assert(addr.family == linux.AF_INET);
|
||||
// assert(addr.addr[0] == 192);
|
||||
// assert(addr.addr[1] == 168);
|
||||
// assert(addr.addr[2] == 1);
|
||||
// assert(addr.addr[3] == 1);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -191,7 +191,7 @@ pub const ChildProcess = struct {
|
||||
pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8,
|
||||
env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult
|
||||
{
|
||||
const child = %%ChildProcess.init(argv, allocator);
|
||||
const child = try ChildProcess.init(argv, allocator);
|
||||
defer child.deinit();
|
||||
|
||||
child.stdin_behavior = ChildProcess.StdIo.Ignore;
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
|
||||
|
||||
test "os.getRandomBytes" {
|
||||
var buf: [50]u8 = undefined;
|
||||
%%getRandomBytes(buf[0..]);
|
||||
try getRandomBytes(buf[0..]);
|
||||
}
|
||||
|
||||
/// Raises a signal in the current kernel thread, ending its execution.
|
||||
@@ -1489,7 +1489,7 @@ test "windows arg parsing" {
|
||||
fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) {
|
||||
var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
|
||||
for (expected_args) |expected_arg| {
|
||||
const arg = %%??it.next(debug.global_allocator);
|
||||
const arg = ??it.next(debug.global_allocator) catch unreachable;
|
||||
assert(mem.eql(u8, arg, expected_arg));
|
||||
}
|
||||
assert(it.next(debug.global_allocator) == null);
|
||||
|
||||
+19
-19
@@ -49,23 +49,23 @@ pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 {
|
||||
}
|
||||
|
||||
test "os.path.join" {
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator,
|
||||
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"));
|
||||
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"),
|
||||
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"));
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
|
||||
}
|
||||
|
||||
test "os.path.resolve" {
|
||||
const cwd = %%os.getCwd(debug.global_allocator);
|
||||
const cwd = try os.getCwd(debug.global_allocator);
|
||||
if (is_windows) {
|
||||
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
|
||||
cwd[0] = asciiUpper(cwd[0]);
|
||||
@@ -598,11 +598,11 @@ test "os.path.resolve" {
|
||||
|
||||
test "os.path.resolveWindows" {
|
||||
if (is_windows) {
|
||||
const cwd = %%os.getCwd(debug.global_allocator);
|
||||
const cwd = try os.getCwd(debug.global_allocator);
|
||||
const parsed_cwd = windowsParsePath(cwd);
|
||||
{
|
||||
const result = testResolveWindows([][]const u8{"/usr/local", "lib\\zig\\std\\array_list.zig"});
|
||||
const expected = %%join(debug.global_allocator,
|
||||
const expected = try join(debug.global_allocator,
|
||||
parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
|
||||
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
|
||||
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
|
||||
@@ -611,7 +611,7 @@ test "os.path.resolveWindows" {
|
||||
}
|
||||
{
|
||||
const result = testResolveWindows([][]const u8{"usr/local", "lib\\zig"});
|
||||
const expected = %%join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
|
||||
const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
|
||||
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
|
||||
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
|
||||
}
|
||||
@@ -649,11 +649,11 @@ test "os.path.resolvePosix" {
|
||||
}
|
||||
|
||||
fn testResolveWindows(paths: []const []const u8) -> []u8 {
|
||||
return %%resolveWindows(debug.global_allocator, paths);
|
||||
return resolveWindows(debug.global_allocator, paths) catch unreachable;
|
||||
}
|
||||
|
||||
fn testResolvePosix(paths: []const []const u8) -> []u8 {
|
||||
return %%resolvePosix(debug.global_allocator, paths);
|
||||
return resolvePosix(debug.global_allocator, paths) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn dirname(path: []const u8) -> []const u8 {
|
||||
@@ -1057,12 +1057,12 @@ test "os.path.relative" {
|
||||
}
|
||||
|
||||
fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) {
|
||||
const result = %%relativePosix(debug.global_allocator, from, to);
|
||||
const result = relativePosix(debug.global_allocator, from, to) catch unreachable;
|
||||
assert(mem.eql(u8, result, expected_output));
|
||||
}
|
||||
|
||||
fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) {
|
||||
const result = %%relativeWindows(debug.global_allocator, from, to);
|
||||
const result = relativeWindows(debug.global_allocator, from, to) catch unreachable;
|
||||
assert(mem.eql(u8, result, expected_output));
|
||||
}
|
||||
|
||||
@@ -1172,7 +1172,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
|
||||
defer os.close(fd);
|
||||
|
||||
var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;
|
||||
const proc_path = %%fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd);
|
||||
const proc_path = fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd) catch unreachable;
|
||||
|
||||
return os.readLink(allocator, proc_path);
|
||||
},
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ pub const Rand = struct {
|
||||
return T(r.range(uint, uint(start), uint(end)));
|
||||
} else if (start < 0 and end < 0) {
|
||||
// Can't overflow because the range is over signed ints
|
||||
return %%math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1);
|
||||
return math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1) catch unreachable;
|
||||
} else if (start < 0 and end >= 0) {
|
||||
const end_uint = uint(end);
|
||||
const total_range = math.absCast(start) + end_uint;
|
||||
@@ -85,7 +85,7 @@ pub const Rand = struct {
|
||||
break :x start;
|
||||
} else x: {
|
||||
// Can't overflow because the range is over signed ints
|
||||
break :x %%math.negateCast(value - end_uint);
|
||||
break :x math.negateCast(value - end_uint) catch unreachable;
|
||||
};
|
||||
return result;
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -1115,7 +1115,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined;
|
||||
fn fuzzTest(rng: &std.rand.Rand) {
|
||||
const array_size = rng.range(usize, 0, 1000);
|
||||
var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
|
||||
var array = %%fixed_allocator.allocator.alloc(IdAndValue, array_size);
|
||||
var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;
|
||||
// populate with random data
|
||||
for (array) |*item, index| {
|
||||
item.id = index;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn main() -> %void {
|
||||
var arg_it = os.args();
|
||||
|
||||
// TODO use a more general purpose allocator here
|
||||
var inc_allocator = %%std.heap.IncrementingAllocator.init(40 * 1024 * 1024);
|
||||
var inc_allocator = std.heap.IncrementingAllocator.init(40 * 1024 * 1024) catch unreachable;
|
||||
defer inc_allocator.deinit();
|
||||
|
||||
const allocator = &inc_allocator.allocator;
|
||||
@@ -107,7 +107,7 @@ pub fn main() -> %void {
|
||||
return usageAndErr(&builder, false, try stderr_stream);
|
||||
}
|
||||
} else {
|
||||
%%targets.append(arg);
|
||||
targets.append(arg) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,10 @@ pub fn main() -> %void {
|
||||
for (test_fn_list) |test_fn, i| {
|
||||
warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
|
||||
|
||||
test_fn.func();
|
||||
test_fn.func() catch |err| {
|
||||
warn("{}\n", err);
|
||||
return err;
|
||||
};
|
||||
|
||||
warn("OK\n");
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ error Utf8EncodesSurrogateHalf;
|
||||
error Utf8CodepointTooLarge;
|
||||
|
||||
/// Decodes the UTF-8 codepoint encoded in the given slice of bytes.
|
||||
/// bytes.len must be equal to %%utf8ByteSequenceLength(bytes[0]).
|
||||
/// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable.
|
||||
/// If you already know the length at comptime, you can call one of
|
||||
/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
|
||||
pub fn utf8Decode(bytes: []const u8) -> %u32 {
|
||||
@@ -158,7 +158,7 @@ fn testError(bytes: []const u8, expected_err: error) {
|
||||
}
|
||||
|
||||
fn testValid(bytes: []const u8, expected_codepoint: u32) {
|
||||
std.debug.assert(%%testDecode(bytes) == expected_codepoint);
|
||||
std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint);
|
||||
}
|
||||
|
||||
fn testDecode(bytes: []const u8) -> %u32 {
|
||||
|
||||
+12
-12
@@ -85,14 +85,14 @@ const A = struct {
|
||||
fn castToMaybeTypeError(z: i32) {
|
||||
const x = i32(1);
|
||||
const y: %?i32 = x;
|
||||
assert(??%%y == 1);
|
||||
assert(??(try y) == 1);
|
||||
|
||||
const f = z;
|
||||
const g: %?i32 = f;
|
||||
|
||||
const a = A{ .a = z };
|
||||
const b: %?A = a;
|
||||
assert((??%%b).a == 1);
|
||||
assert((??(b catch unreachable)).a == 1);
|
||||
}
|
||||
|
||||
test "implicitly cast from int to %?T" {
|
||||
@@ -108,7 +108,7 @@ fn implicitIntLitToMaybe() {
|
||||
test "return null from fn() -> %?&T" {
|
||||
const a = returnNullFromMaybeTypeErrorRef();
|
||||
const b = returnNullLitFromMaybeTypeErrorRef();
|
||||
assert(%%a == null and %%b == null);
|
||||
assert((try a) == null and (try b) == null);
|
||||
}
|
||||
fn returnNullFromMaybeTypeErrorRef() -> %?&A {
|
||||
const a: ?&A = null;
|
||||
@@ -167,7 +167,7 @@ test "implicitly cast from [0]T to %[]T" {
|
||||
}
|
||||
|
||||
fn testCastZeroArrayToErrSliceMut() {
|
||||
assert((%%gimmeErrOrSlice()).len == 0);
|
||||
assert((gimmeErrOrSlice() catch unreachable).len == 0);
|
||||
}
|
||||
|
||||
fn gimmeErrOrSlice() -> %[]u8 {
|
||||
@@ -178,14 +178,14 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" {
|
||||
{
|
||||
var data = "hi";
|
||||
const slice = data[0..];
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
}
|
||||
comptime {
|
||||
var data = "hi";
|
||||
const slice = data[0..];
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
}
|
||||
}
|
||||
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
|
||||
@@ -231,11 +231,11 @@ fn foo(args: ...) {
|
||||
|
||||
test "peer type resolution: error and [N]T" {
|
||||
// TODO: implicit %T to %U where T can implicitly cast to U
|
||||
//assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK"));
|
||||
//comptime assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK"));
|
||||
//assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
|
||||
//comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
|
||||
|
||||
assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK"));
|
||||
comptime assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK"));
|
||||
assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
|
||||
comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
|
||||
}
|
||||
|
||||
error BadValue;
|
||||
|
||||
@@ -21,7 +21,7 @@ fn foo(args: [][]const u8) {
|
||||
}
|
||||
|
||||
fn bar(argc: usize) {
|
||||
const args = %%debug.global_allocator.alloc([]const u8, argc);
|
||||
const args = debug.global_allocator.alloc([]const u8, argc) catch unreachable;
|
||||
for (args) |_, i| {
|
||||
const ptr = argv[i];
|
||||
args[i] = ptr[0..strlen(ptr)];
|
||||
|
||||
@@ -14,7 +14,7 @@ fn runSomeErrorDefers(x: bool) -> %bool {
|
||||
}
|
||||
|
||||
test "mixing normal and error defers" {
|
||||
assert(%%runSomeErrorDefers(true));
|
||||
assert(runSomeErrorDefers(true) catch unreachable);
|
||||
assert(result[0] == 'c');
|
||||
assert(result[1] == 'a');
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ test "enum with members" {
|
||||
const b = ET { .UINT = 42 };
|
||||
var buf: [20]u8 = undefined;
|
||||
|
||||
assert(%%a.print(buf[0..]) == 3);
|
||||
assert((a.print(buf[0..]) catch unreachable) == 3);
|
||||
assert(mem.eql(u8, buf[0..3], "-42"));
|
||||
|
||||
assert(%%b.print(buf[0..]) == 2);
|
||||
assert((b.print(buf[0..]) catch unreachable) == 2);
|
||||
assert(mem.eql(u8, buf[0..2], "42"));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn baz() -> %i32 {
|
||||
}
|
||||
|
||||
test "error wrapping" {
|
||||
assert(%%baz() == 15);
|
||||
assert((baz() catch unreachable) == 15);
|
||||
}
|
||||
|
||||
error ItBroke;
|
||||
@@ -65,14 +65,14 @@ fn errBinaryOperatorG(x: bool) -> %isize {
|
||||
|
||||
|
||||
test "unwrap simple value from error" {
|
||||
const i = %%unwrapSimpleValueFromErrorDo();
|
||||
const i = unwrapSimpleValueFromErrorDo() catch unreachable;
|
||||
assert(i == 13);
|
||||
}
|
||||
fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }
|
||||
|
||||
|
||||
test "error return in assignment" {
|
||||
%%doErrReturnInAssignment();
|
||||
doErrReturnInAssignment() catch unreachable;
|
||||
}
|
||||
|
||||
fn doErrReturnInAssignment() -> %void {
|
||||
|
||||
@@ -16,6 +16,6 @@ fn getErrInt() -> %i32 { return 0; }
|
||||
error ItBroke;
|
||||
|
||||
test "ir block deps" {
|
||||
assert(%%foo(1) == 0);
|
||||
assert(%%foo(2) == 0);
|
||||
assert((foo(1) catch unreachable) == 0);
|
||||
assert((foo(2) catch unreachable) == 0);
|
||||
}
|
||||
|
||||
+2
-2
@@ -258,7 +258,7 @@ test "explicit cast maybe pointers" {
|
||||
}
|
||||
|
||||
test "generic malloc free" {
|
||||
const a = %%memAlloc(u8, 10);
|
||||
const a = memAlloc(u8, 10) catch unreachable;
|
||||
memFree(u8, a);
|
||||
}
|
||||
const some_mem : [100]u8 = undefined;
|
||||
@@ -417,7 +417,7 @@ test "cast slice to u8 slice" {
|
||||
}
|
||||
|
||||
test "pointer to void return type" {
|
||||
%%testPointerToVoidReturnType();
|
||||
testPointerToVoidReturnType() catch unreachable;
|
||||
}
|
||||
fn testPointerToVoidReturnType() -> %void {
|
||||
const a = testPointerToVoidReturnType2();
|
||||
|
||||
@@ -22,7 +22,7 @@ fn doThing(form_id: u64) -> %FormValue {
|
||||
}
|
||||
|
||||
test "switch prong returns error enum" {
|
||||
switch (%%doThing(17)) {
|
||||
switch (doThing(17) catch unreachable) {
|
||||
FormValue.Address => |payload| { assert(payload == 1); },
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ fn foo(id: u64) -> %FormValue {
|
||||
}
|
||||
|
||||
test "switch prong implicit cast" {
|
||||
const result = switch (%%foo(2)) {
|
||||
const result = switch (foo(2) catch unreachable) {
|
||||
FormValue.One => false,
|
||||
FormValue.Two => |x| x,
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ test "unions embedded in aggregate types" {
|
||||
Value.Array => |arr| assert(arr[4] == 3),
|
||||
else => unreachable,
|
||||
}
|
||||
switch((%%err).val1) {
|
||||
switch((err catch unreachable).val1) {
|
||||
Value.Int => |x| assert(x == 1234),
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ fn runContinueAndBreakTest() {
|
||||
}
|
||||
|
||||
test "return with implicit cast from while loop" {
|
||||
%%returnWithImplicitCastFromWhileLoopTest();
|
||||
returnWithImplicitCastFromWhileLoopTest() catch unreachable;
|
||||
}
|
||||
fn returnWithImplicitCastFromWhileLoopTest() -> %void {
|
||||
while (true) {
|
||||
|
||||
+44
-44
@@ -17,8 +17,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\
|
||||
\\pub fn main() -> %void {
|
||||
\\ privateFunction();
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK 2\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK 2\n") catch unreachable;
|
||||
\\}
|
||||
\\
|
||||
\\fn privateFunction() {
|
||||
@@ -32,8 +32,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\// purposefully conflicting function with main.zig
|
||||
\\// but it's private so it should be OK
|
||||
\\fn privateFunction() {
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK 1\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK 1\n") catch unreachable;
|
||||
\\}
|
||||
\\
|
||||
\\pub fn printText() {
|
||||
@@ -58,8 +58,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
tc.addSourceFile("foo.zig",
|
||||
\\use @import("std").io;
|
||||
\\pub fn foo_function() {
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\}
|
||||
);
|
||||
|
||||
@@ -69,8 +69,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\
|
||||
\\pub fn bar_function() {
|
||||
\\ if (foo_function()) {
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\ }
|
||||
\\}
|
||||
);
|
||||
@@ -101,8 +101,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\pub const a_text = "OK\n";
|
||||
\\
|
||||
\\pub fn ok() {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print(b_text);
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print(b_text) catch unreachable;
|
||||
\\}
|
||||
);
|
||||
|
||||
@@ -119,8 +119,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\const io = @import("std").io;
|
||||
\\
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a'));
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
|
||||
\\}
|
||||
, "Hello, world!\n0012 012 a\n");
|
||||
|
||||
@@ -272,8 +272,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\ var x_local : i32 = print_ok(x);
|
||||
\\}
|
||||
\\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\ return 0;
|
||||
\\}
|
||||
\\const foo : i32 = 0;
|
||||
@@ -354,26 +354,26 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\pub fn main() -> %void {
|
||||
\\ const bar = Bar {.field2 = 13,};
|
||||
\\ const foo = Foo {.field1 = bar,};
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ if (!foo.method()) {
|
||||
\\ %%stdout.print("BAD\n");
|
||||
\\ stdout.print("BAD\n") catch unreachable;
|
||||
\\ }
|
||||
\\ if (!bar.method()) {
|
||||
\\ %%stdout.print("BAD\n");
|
||||
\\ stdout.print("BAD\n") catch unreachable;
|
||||
\\ }
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\}
|
||||
, "OK\n");
|
||||
|
||||
cases.add("defer with only fallthrough",
|
||||
\\const io = @import("std").io;
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ defer %%stdout.print("defer2\n");
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ defer stdout.print("defer2\n") catch unreachable;
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
, "before\nafter\ndefer3\ndefer2\ndefer1\n");
|
||||
|
||||
@@ -381,14 +381,14 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\const io = @import("std").io;
|
||||
\\const os = @import("std").os;
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ defer %%stdout.print("defer2\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ defer stdout.print("defer2\n") catch unreachable;
|
||||
\\ var args_it = @import("std").os.args();
|
||||
\\ if (args_it.skip() and !args_it.skip()) return;
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
, "before\ndefer2\ndefer1\n");
|
||||
|
||||
@@ -398,13 +398,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\ do_test() catch return;
|
||||
\\}
|
||||
\\fn do_test() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ %defer %%stdout.print("deferErr\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ %defer stdout.print("deferErr\n") catch unreachable;
|
||||
\\ try its_gonna_fail();
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
\\error IToldYouItWouldFail;
|
||||
\\fn its_gonna_fail() -> %void {
|
||||
@@ -418,13 +418,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\ do_test() catch return;
|
||||
\\}
|
||||
\\fn do_test() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ %defer %%stdout.print("deferErr\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ %defer stdout.print("deferErr\n") catch unreachable;
|
||||
\\ try its_gonna_pass();
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
\\fn its_gonna_pass() -> %void { }
|
||||
, "before\nafter\ndefer3\ndefer1\n");
|
||||
@@ -435,8 +435,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\const io = @import("std").io;
|
||||
\\
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print(foo_txt);
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print(foo_txt) catch unreachable;
|
||||
\\}
|
||||
, "1234\nabcd\n");
|
||||
|
||||
|
||||
@@ -1423,10 +1423,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
|
||||
|
||||
cases.add("ignored assert-err-ok return value",
|
||||
\\export fn foo() {
|
||||
\\ %%bar();
|
||||
\\ bar() catch unreachable;
|
||||
\\}
|
||||
\\fn bar() -> %i32 { return 0; }
|
||||
, ".tmp_source.zig:2:5: error: expression value is ignored");
|
||||
, ".tmp_source.zig:2:11: error: expression value is ignored");
|
||||
|
||||
cases.add("ignored statement value",
|
||||
\\export fn foo() {
|
||||
|
||||
@@ -3,5 +3,5 @@ pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }
|
||||
fn bar() -> %void {}
|
||||
|
||||
export fn foo() {
|
||||
%%bar();
|
||||
bar() catch unreachable;
|
||||
}
|
||||
|
||||
+69
-69
@@ -54,7 +54,7 @@ error TestFailed;
|
||||
const max_stdout_size = 1 * 1024 * 1024; // 1 MB
|
||||
|
||||
pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompareOutputContext);
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
*cases = CompareOutputContext {
|
||||
.b = b,
|
||||
.step = b.step("test-compare-output", "Run the compare output tests"),
|
||||
@@ -68,7 +68,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
|
||||
}
|
||||
|
||||
pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompareOutputContext);
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
*cases = CompareOutputContext {
|
||||
.b = b,
|
||||
.step = b.step("test-debug-safety", "Run the debug safety tests"),
|
||||
@@ -82,7 +82,7 @@ pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &buil
|
||||
}
|
||||
|
||||
pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompileErrorContext);
|
||||
const cases = b.allocator.create(CompileErrorContext) catch unreachable;
|
||||
*cases = CompileErrorContext {
|
||||
.b = b,
|
||||
.step = b.step("test-compile-errors", "Run the compile error tests"),
|
||||
@@ -96,7 +96,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
|
||||
}
|
||||
|
||||
pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(BuildExamplesContext);
|
||||
const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
|
||||
*cases = BuildExamplesContext {
|
||||
.b = b,
|
||||
.step = b.step("test-build-examples", "Build the examples"),
|
||||
@@ -110,7 +110,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
|
||||
}
|
||||
|
||||
pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompareOutputContext);
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
*cases = CompareOutputContext {
|
||||
.b = b,
|
||||
.step = b.step("test-asm-link", "Run the assemble and link tests"),
|
||||
@@ -124,7 +124,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &
|
||||
}
|
||||
|
||||
pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(TranslateCContext);
|
||||
const cases = b.allocator.create(TranslateCContext) catch unreachable;
|
||||
*cases = TranslateCContext {
|
||||
.b = b,
|
||||
.step = b.step("test-translate-c", "Run the C header file parsing tests"),
|
||||
@@ -197,10 +197,10 @@ pub const CompareOutputContext = struct {
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
||||
%%self.sources.append(SourceFile {
|
||||
self.sources.append(SourceFile {
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) {
|
||||
@@ -222,7 +222,7 @@ pub const CompareOutputContext = struct {
|
||||
cli_args: []const []const u8) -> &RunCompareOutputStep
|
||||
{
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(RunCompareOutputStep);
|
||||
const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
|
||||
*ptr = RunCompareOutputStep {
|
||||
.context = context,
|
||||
.exe_path = exe_path,
|
||||
@@ -244,14 +244,14 @@ pub const CompareOutputContext = struct {
|
||||
var args = ArrayList([]const u8).init(b.allocator);
|
||||
defer args.deinit();
|
||||
|
||||
%%args.append(full_exe_path);
|
||||
args.append(full_exe_path) catch unreachable;
|
||||
for (self.cli_args) |arg| {
|
||||
%%args.append(arg);
|
||||
args.append(arg) catch unreachable;
|
||||
}
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
||||
const child = %%os.ChildProcess.init(args.toSliceConst(), b.allocator);
|
||||
const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.stdin_behavior = StdIo.Ignore;
|
||||
@@ -267,8 +267,8 @@ pub const CompareOutputContext = struct {
|
||||
var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
|
||||
var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
|
||||
|
||||
%%stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size);
|
||||
%%stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size);
|
||||
stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
@@ -313,7 +313,7 @@ pub const CompareOutputContext = struct {
|
||||
name: []const u8) -> &DebugSafetyRunStep
|
||||
{
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(DebugSafetyRunStep);
|
||||
const ptr = allocator.create(DebugSafetyRunStep) catch unreachable;
|
||||
*ptr = DebugSafetyRunStep {
|
||||
.context = context,
|
||||
.exe_path = exe_path,
|
||||
@@ -333,7 +333,7 @@ pub const CompareOutputContext = struct {
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
||||
const child = %%os.ChildProcess.init([][]u8{full_exe_path}, b.allocator);
|
||||
const child = os.ChildProcess.init([][]u8{full_exe_path}, b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.env_map = &b.env_map;
|
||||
@@ -416,11 +416,11 @@ pub const CompareOutputContext = struct {
|
||||
pub fn addCase(self: &CompareOutputContext, case: &const TestCase) {
|
||||
const b = self.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename);
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
|
||||
|
||||
switch (case.special) {
|
||||
Special.Asm => {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
@@ -430,7 +430,7 @@ pub const CompareOutputContext = struct {
|
||||
exe.addAssemblyFile(root_src);
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
exe.step.dependOn(&write_src.step);
|
||||
}
|
||||
@@ -443,8 +443,8 @@ pub const CompareOutputContext = struct {
|
||||
},
|
||||
Special.None => {
|
||||
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})",
|
||||
"compare-output", case.name, @tagName(mode));
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})",
|
||||
"compare-output", case.name, @tagName(mode)) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
continue;
|
||||
@@ -457,7 +457,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
exe.step.dependOn(&write_src.step);
|
||||
}
|
||||
@@ -470,7 +470,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
},
|
||||
Special.DebugSafety => {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "safety {}", case.name);
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
@@ -482,7 +482,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
exe.step.dependOn(&write_src.step);
|
||||
}
|
||||
@@ -515,14 +515,14 @@ pub const CompileErrorContext = struct {
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
||||
%%self.sources.append(SourceFile {
|
||||
self.sources.append(SourceFile {
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedError(self: &TestCase, text: []const u8) {
|
||||
%%self.expected_errors.append(text);
|
||||
self.expected_errors.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -538,7 +538,7 @@ pub const CompileErrorContext = struct {
|
||||
case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep
|
||||
{
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(CompileCmpOutputStep);
|
||||
const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
|
||||
*ptr = CompileCmpOutputStep {
|
||||
.step = build.Step.init("CompileCmpOutput", allocator, make),
|
||||
.context = context,
|
||||
@@ -555,25 +555,25 @@ pub const CompileErrorContext = struct {
|
||||
const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
||||
const obj_path = %%os.path.join(b.allocator, b.cache_root, "test.o");
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
|
||||
const obj_path = os.path.join(b.allocator, b.cache_root, "test.o") catch unreachable;
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
%%zig_args.append(b.zig_exe);
|
||||
zig_args.append(b.zig_exe) catch unreachable;
|
||||
|
||||
%%zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj");
|
||||
%%zig_args.append(b.pathFromRoot(root_src));
|
||||
zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
||||
|
||||
%%zig_args.append("--name");
|
||||
%%zig_args.append("test");
|
||||
zig_args.append("--name") catch unreachable;
|
||||
zig_args.append("test") catch unreachable;
|
||||
|
||||
%%zig_args.append("--output");
|
||||
%%zig_args.append(b.pathFromRoot(obj_path));
|
||||
zig_args.append("--output") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(obj_path)) catch unreachable;
|
||||
|
||||
switch (self.build_mode) {
|
||||
Mode.Debug => {},
|
||||
Mode.ReleaseSafe => %%zig_args.append("--release-safe"),
|
||||
Mode.ReleaseFast => %%zig_args.append("--release-fast"),
|
||||
Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
|
||||
Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
|
||||
}
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
@@ -582,7 +582,7 @@ pub const CompileErrorContext = struct {
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
}
|
||||
|
||||
const child = %%os.ChildProcess.init(zig_args.toSliceConst(), b.allocator);
|
||||
const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.env_map = &b.env_map;
|
||||
@@ -598,8 +598,8 @@ pub const CompileErrorContext = struct {
|
||||
var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
|
||||
var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
|
||||
|
||||
%%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size);
|
||||
%%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size);
|
||||
stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
|
||||
@@ -660,7 +660,7 @@ pub const CompileErrorContext = struct {
|
||||
pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8,
|
||||
expected_lines: ...) -> &TestCase
|
||||
{
|
||||
const tc = %%self.b.allocator.create(TestCase);
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
*tc = TestCase {
|
||||
.name = name,
|
||||
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
||||
@@ -697,8 +697,8 @@ pub const CompileErrorContext = struct {
|
||||
const b = self.b;
|
||||
|
||||
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})",
|
||||
case.name, @tagName(mode));
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {} ({})",
|
||||
case.name, @tagName(mode)) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
continue;
|
||||
@@ -708,7 +708,7 @@ pub const CompileErrorContext = struct {
|
||||
self.step.dependOn(&compile_and_cmp_errors.step);
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
compile_and_cmp_errors.step.dependOn(&write_src.step);
|
||||
}
|
||||
@@ -740,17 +740,17 @@ pub const BuildExamplesContext = struct {
|
||||
}
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
const rel_zig_exe = %%os.path.relative(b.allocator, b.build_root, b.zig_exe);
|
||||
%%zig_args.append(rel_zig_exe);
|
||||
%%zig_args.append("build");
|
||||
const rel_zig_exe = os.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable;
|
||||
zig_args.append(rel_zig_exe) catch unreachable;
|
||||
zig_args.append("build") catch unreachable;
|
||||
|
||||
%%zig_args.append("--build-file");
|
||||
%%zig_args.append(b.pathFromRoot(build_file));
|
||||
zig_args.append("--build-file") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
|
||||
|
||||
%%zig_args.append("test");
|
||||
zig_args.append("test") catch unreachable;
|
||||
|
||||
if (b.verbose) {
|
||||
%%zig_args.append("--verbose");
|
||||
zig_args.append("--verbose") catch unreachable;
|
||||
}
|
||||
|
||||
const run_cmd = b.addCommand(null, b.env_map, zig_args.toSliceConst());
|
||||
@@ -765,8 +765,8 @@ pub const BuildExamplesContext = struct {
|
||||
const b = self.b;
|
||||
|
||||
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})",
|
||||
root_src, @tagName(mode));
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})",
|
||||
root_src, @tagName(mode)) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
continue;
|
||||
@@ -804,14 +804,14 @@ pub const TranslateCContext = struct {
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
||||
%%self.sources.append(SourceFile {
|
||||
self.sources.append(SourceFile {
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedLine(self: &TestCase, text: []const u8) {
|
||||
%%self.expected_lines.append(text);
|
||||
self.expected_lines.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -824,7 +824,7 @@ pub const TranslateCContext = struct {
|
||||
|
||||
pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(TranslateCCmpOutputStep);
|
||||
const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
|
||||
*ptr = TranslateCCmpOutputStep {
|
||||
.step = build.Step.init("ParseCCmpOutput", allocator, make),
|
||||
.context = context,
|
||||
@@ -840,13 +840,13 @@ pub const TranslateCContext = struct {
|
||||
const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
%%zig_args.append(b.zig_exe);
|
||||
zig_args.append(b.zig_exe) catch unreachable;
|
||||
|
||||
%%zig_args.append("translate-c");
|
||||
%%zig_args.append(b.pathFromRoot(root_src));
|
||||
zig_args.append("translate-c") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
||||
@@ -854,7 +854,7 @@ pub const TranslateCContext = struct {
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
}
|
||||
|
||||
const child = %%os.ChildProcess.init(zig_args.toSliceConst(), b.allocator);
|
||||
const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.env_map = &b.env_map;
|
||||
@@ -870,8 +870,8 @@ pub const TranslateCContext = struct {
|
||||
var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
|
||||
var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
|
||||
|
||||
%%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size);
|
||||
%%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size);
|
||||
stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
|
||||
@@ -933,7 +933,7 @@ pub const TranslateCContext = struct {
|
||||
pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
|
||||
source: []const u8, expected_lines: ...) -> &TestCase
|
||||
{
|
||||
const tc = %%self.b.allocator.create(TestCase);
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
*tc = TestCase {
|
||||
.name = name,
|
||||
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
||||
@@ -966,7 +966,7 @@ pub const TranslateCContext = struct {
|
||||
pub fn addCase(self: &TranslateCContext, case: &const TestCase) {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "translate-c {}", case.name);
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
@@ -976,7 +976,7 @@ pub const TranslateCContext = struct {
|
||||
self.step.dependOn(&translate_c_and_cmp.step);
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
translate_c_and_cmp.step.dependOn(&write_src.step);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user