mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-05-31 21:35:57 +03:00
build system: remove unneeded args from configurer
not needed: * zig exe path * zig lib dir * build root * local cache root * global cache root
This commit is contained in:
@@ -189,7 +189,10 @@ pub fn make(
|
||||
|
||||
man.hash.add(conf_run.flags.test_runner_mode);
|
||||
if (conf_run.flags.test_runner_mode) {
|
||||
try argv_list.ensureUnusedCapacity(gpa, 2);
|
||||
const cache_dir_string = try convertPathArg(run_index, maker, .{ .root_dir = cache_root });
|
||||
|
||||
try argv_list.ensureUnusedCapacity(gpa, 3);
|
||||
argv_list.appendAssumeCapacity(try allocPrint(arena, "--cache-dir={s}", .{cache_dir_string}));
|
||||
argv_list.appendAssumeCapacity(try allocPrint(arena, "--seed=0x{x}", .{graph.random_seed}));
|
||||
argv_list.appendAssumeCapacity("--listen=-");
|
||||
}
|
||||
|
||||
@@ -39,44 +39,10 @@ pub fn main(init: process.Init.Minimal) !void {
|
||||
|
||||
const args = try init.args.toSlice(arena);
|
||||
|
||||
// Skip own executable name.
|
||||
var arg_idx: usize = 1;
|
||||
|
||||
const zig_exe = expectArgOrFatal(args, &arg_idx, "--zig");
|
||||
const zig_lib_dir = expectArgOrFatal(args, &arg_idx, "--zig-lib-dir");
|
||||
const build_root = expectArgOrFatal(args, &arg_idx, "--build-root");
|
||||
const local_cache_root = expectArgOrFatal(args, &arg_idx, "--local-cache");
|
||||
const global_cache_root = expectArgOrFatal(args, &arg_idx, "--global-cache");
|
||||
|
||||
const cwd: Io.Dir = .cwd();
|
||||
|
||||
const zig_lib_directory: std.Build.Cache.Directory = .{
|
||||
.path = zig_lib_dir,
|
||||
.handle = try cwd.openDir(io, zig_lib_dir, .{}),
|
||||
};
|
||||
|
||||
const build_root_directory: std.Build.Cache.Directory = .{
|
||||
.path = build_root,
|
||||
.handle = try cwd.openDir(io, build_root, .{}),
|
||||
};
|
||||
|
||||
const local_cache_directory: std.Build.Cache.Directory = .{
|
||||
.path = local_cache_root,
|
||||
.handle = try cwd.createDirPathOpen(io, local_cache_root, .{}),
|
||||
};
|
||||
|
||||
const global_cache_directory: std.Build.Cache.Directory = .{
|
||||
.path = global_cache_root,
|
||||
.handle = try cwd.createDirPathOpen(io, global_cache_root, .{}),
|
||||
};
|
||||
|
||||
var graph: std.Build.Graph = .{
|
||||
.io = io,
|
||||
.arena = arena,
|
||||
.zig_exe = zig_exe,
|
||||
.environ_map = try init.environ.createMap(arena),
|
||||
.global_cache_root = global_cache_directory,
|
||||
.zig_lib_directory = zig_lib_directory,
|
||||
// TODO get this from parent process instead
|
||||
.host = .{
|
||||
.query = .{},
|
||||
@@ -96,12 +62,7 @@ pub fn main(init: process.Init.Minimal) !void {
|
||||
assert(try graph.wip_configuration.addString("") == .empty);
|
||||
assert(try graph.wip_configuration.addString("root") == .root);
|
||||
|
||||
const builder = try std.Build.create(
|
||||
&graph,
|
||||
build_root_directory,
|
||||
local_cache_directory,
|
||||
dependencies.root_deps,
|
||||
);
|
||||
const builder = try std.Build.create(&graph, dependencies.root_deps);
|
||||
|
||||
var error_style: ErrorStyle = .verbose;
|
||||
var multiline_errors: MultilineErrors = .indent;
|
||||
@@ -119,7 +80,9 @@ pub fn main(init: process.Init.Minimal) !void {
|
||||
}
|
||||
}
|
||||
|
||||
while (nextArg(args, &arg_idx)) |arg| {
|
||||
var arg_i: usize = 1; // Skip own executable name.
|
||||
|
||||
while (nextArg(args, &arg_i)) |arg| {
|
||||
if (mem.cutPrefix(u8, arg, "-D")) |option_contents| {
|
||||
if (option_contents.len == 0)
|
||||
fatalWithHint("expected option name after '-D'", .{});
|
||||
@@ -145,7 +108,7 @@ pub fn main(init: process.Init.Minimal) !void {
|
||||
});
|
||||
};
|
||||
} else if (mem.eql(u8, arg, "--color")) {
|
||||
const next_arg = nextArg(args, &arg_idx) orelse
|
||||
const next_arg = nextArg(args, &arg_i) orelse
|
||||
fatalWithHint("expected [auto|on|off] after {q}", .{arg});
|
||||
color = std.meta.stringToEnum(Color, next_arg) orelse {
|
||||
fatalWithHint("expected [auto|on|off] after {q}, found {q}", .{
|
||||
@@ -153,13 +116,13 @@ pub fn main(init: process.Init.Minimal) !void {
|
||||
});
|
||||
};
|
||||
} else if (mem.eql(u8, arg, "--error-style")) {
|
||||
const next_arg = nextArg(args, &arg_idx) orelse
|
||||
const next_arg = nextArg(args, &arg_i) orelse
|
||||
fatalWithHint("expected style after {q}", .{arg});
|
||||
error_style = std.meta.stringToEnum(ErrorStyle, next_arg) orelse {
|
||||
fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg });
|
||||
};
|
||||
} else if (mem.eql(u8, arg, "--multiline-errors")) {
|
||||
const next_arg = nextArg(args, &arg_idx) orelse
|
||||
const next_arg = nextArg(args, &arg_i) orelse
|
||||
fatalWithHint("expected style after {q}", .{arg});
|
||||
multiline_errors = std.meta.stringToEnum(MultilineErrors, next_arg) orelse {
|
||||
fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg });
|
||||
@@ -169,8 +132,6 @@ pub fn main(init: process.Init.Minimal) !void {
|
||||
// but it is handled by the parent process. The build runner
|
||||
// only sees this flag.
|
||||
graph.system_package_mode = true;
|
||||
} else if (mem.eql(u8, arg, "--have-run-args")) {
|
||||
graph.have_run_args = true;
|
||||
} else {
|
||||
fatalWithHint("unrecognized argument: {q}", .{arg});
|
||||
}
|
||||
@@ -1112,19 +1073,6 @@ fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {
|
||||
return args[idx.*];
|
||||
}
|
||||
|
||||
fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 {
|
||||
return nextArg(args, idx) orelse {
|
||||
fatalWithHint("expected argument after: {s}", .{args[idx.* - 1]});
|
||||
};
|
||||
}
|
||||
|
||||
fn expectArgOrFatal(args: []const [:0]const u8, index_ptr: *usize, first: []const u8) []const u8 {
|
||||
const next_arg = nextArg(args, index_ptr) orelse fatal("missing {q} argument", .{first});
|
||||
if (!mem.eql(u8, first, next_arg)) fatal("expected {q} instead of {q}", .{ first, next_arg });
|
||||
const arg = nextArg(args, index_ptr) orelse fatal("expected argument after {q}", .{first});
|
||||
return arg;
|
||||
}
|
||||
|
||||
const ErrorStyle = enum {
|
||||
verbose,
|
||||
minimal,
|
||||
|
||||
+7
-27
@@ -36,9 +36,6 @@ invalid_user_input: bool,
|
||||
default_step: *Step,
|
||||
top_level_steps: std.StringArrayHashMapUnmanaged(*Step.TopLevel),
|
||||
install_prefix: []const u8,
|
||||
/// Path to the directory containing build.zig.
|
||||
build_root: Cache.Directory,
|
||||
cache_root: Cache.Directory,
|
||||
debug_log_scopes: []const []const u8 = &.{},
|
||||
/// Number of stack frames captured when a `StackTrace` is recorded for debug purposes,
|
||||
/// in particular at `Step` creation.
|
||||
@@ -83,10 +80,7 @@ pub const Graph = struct {
|
||||
arena: Allocator,
|
||||
system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,
|
||||
system_package_mode: bool = false,
|
||||
zig_exe: []const u8,
|
||||
environ_map: process.Environ.Map,
|
||||
global_cache_root: Cache.Directory,
|
||||
zig_lib_directory: Cache.Directory,
|
||||
needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty,
|
||||
/// Information about the native target. Computed before build() is invoked.
|
||||
host: ResolvedTarget,
|
||||
@@ -97,10 +91,6 @@ pub const Graph = struct {
|
||||
/// respects the '--color' flag.
|
||||
stderr_mode: ?Io.Terminal.Mode = null,
|
||||
release_mode: ReleaseMode = .off,
|
||||
/// Whether the user passed in "--" arguments. They can be added to a child
|
||||
/// process via `Step.Run` API but cannot be observed in the configure
|
||||
/// phase.
|
||||
have_run_args: bool = false,
|
||||
|
||||
/// Indexes correspond to `Configuration.GeneratedFileIndex`.
|
||||
generated_files: std.ArrayList(*Step),
|
||||
@@ -230,8 +220,6 @@ const TypeId = enum {
|
||||
|
||||
pub fn create(
|
||||
graph: *Graph,
|
||||
build_root: Cache.Directory,
|
||||
cache_root: Cache.Directory,
|
||||
available_deps: AvailableDeps,
|
||||
) error{OutOfMemory}!*Build {
|
||||
const arena = graph.arena;
|
||||
@@ -239,8 +227,6 @@ pub fn create(
|
||||
const b = try arena.create(Build);
|
||||
b.* = .{
|
||||
.graph = graph,
|
||||
.build_root = build_root,
|
||||
.cache_root = cache_root,
|
||||
.invalid_user_input = false,
|
||||
.allocator = arena,
|
||||
.user_input_options = UserInputOptionsMap.init(arena),
|
||||
@@ -280,7 +266,6 @@ pub fn create(
|
||||
fn createChild(
|
||||
parent: *Build,
|
||||
dep_name: []const u8,
|
||||
build_root: Cache.Directory,
|
||||
pkg_hash: []const u8,
|
||||
pkg_deps: AvailableDeps,
|
||||
user_input_options: UserInputOptionsMap,
|
||||
@@ -312,8 +297,6 @@ fn createChild(
|
||||
.invalid_user_input = false,
|
||||
.default_step = undefined,
|
||||
.top_level_steps = .{},
|
||||
.build_root = build_root,
|
||||
.cache_root = parent.cache_root,
|
||||
.debug_log_scopes = parent.debug_log_scopes,
|
||||
.enable_darling = parent.enable_darling,
|
||||
.enable_qemu = parent.enable_qemu,
|
||||
@@ -2036,15 +2019,12 @@ fn dependencyInner(
|
||||
|
||||
const build_root: std.Build.Cache.Directory = .{
|
||||
.path = build_root_string,
|
||||
.handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err| {
|
||||
std.debug.print("unable to open '{s}': {s}\n", .{
|
||||
build_root_string, @errorName(err),
|
||||
});
|
||||
process.exit(1);
|
||||
},
|
||||
.handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err|
|
||||
process.fatal("unable to open {s}: {t}", .{ build_root_string, err }),
|
||||
};
|
||||
|
||||
const sub_builder = b.createChild(name, build_root, pkg_hash, pkg_deps, user_input_options) catch @panic("unhandled error");
|
||||
const sub_builder = b.createChild(name, build_root, pkg_hash, pkg_deps, user_input_options) catch
|
||||
@panic("unhandled error");
|
||||
if (build_zig) |bz| {
|
||||
sub_builder.runBuild(bz) catch @panic("unhandled error");
|
||||
|
||||
@@ -2330,9 +2310,9 @@ pub const InstallDir = union(enum) {
|
||||
}
|
||||
};
|
||||
|
||||
/// Creates a path leading to a directory inside "tmp" subdirectory of
|
||||
/// `cache_root` which is created on demand and cleaned up by the build runner
|
||||
/// upon success.
|
||||
/// Creates a path leading to a directory inside "tmp" subdirectory of local
|
||||
/// cache which is created on demand and cleaned up by the build runner upon
|
||||
/// success.
|
||||
pub fn tmpPath(b: *Build) LazyPath {
|
||||
const wf = b.addTempFiles();
|
||||
return wf.getDirectory();
|
||||
|
||||
@@ -215,9 +215,7 @@ pub fn setName(run: *Run, name: []const u8) void {
|
||||
|
||||
pub fn enableTestRunnerMode(run: *Run) void {
|
||||
if (run.test_runner_mode) return;
|
||||
const b = run.step.owner;
|
||||
run.stdio = .zig_test;
|
||||
run.addPrefixedDirectoryArg("--cache-dir=", .{ .cwd_relative = b.cache_root.path orelse "." });
|
||||
run.test_runner_mode = true;
|
||||
}
|
||||
|
||||
|
||||
+16
-40
@@ -4976,43 +4976,27 @@ fn cmdBuild(
|
||||
try configure_argv.ensureUnusedCapacity(arena, 16);
|
||||
try make_argv.ensureUnusedCapacity(arena, 16);
|
||||
|
||||
_ = configure_argv.addOneAssumeCapacity();
|
||||
_ = make_argv.addOneAssumeCapacity();
|
||||
_ = configure_argv.addOneAssumeCapacity(); // configurer executable
|
||||
_ = make_argv.addOneAssumeCapacity(); // maker executable
|
||||
|
||||
configure_argv.appendAssumeCapacity("--zig");
|
||||
configure_argv.appendAssumeCapacity(self_exe_path);
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };
|
||||
|
||||
make_argv.appendAssumeCapacity("--zig");
|
||||
make_argv.appendAssumeCapacity(self_exe_path);
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined };
|
||||
const argv_index_zig_lib_dir = make_argv.items.len - 1;
|
||||
|
||||
configure_argv.appendAssumeCapacity("--zig-lib-dir");
|
||||
make_argv.appendAssumeCapacity("--zig-lib-dir");
|
||||
const argv_index_zig_lib_dir = configure_argv.items.len;
|
||||
_ = configure_argv.addOneAssumeCapacity();
|
||||
_ = make_argv.addOneAssumeCapacity();
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--build-root", undefined };
|
||||
const argv_index_build_file = make_argv.items.len - 1;
|
||||
|
||||
configure_argv.appendAssumeCapacity("--build-root");
|
||||
make_argv.appendAssumeCapacity("--build-root");
|
||||
const argv_index_build_file = configure_argv.items.len;
|
||||
_ = configure_argv.addOneAssumeCapacity();
|
||||
_ = make_argv.addOneAssumeCapacity();
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--local-cache", undefined };
|
||||
const argv_index_cache_dir = make_argv.items.len - 1;
|
||||
|
||||
configure_argv.appendAssumeCapacity("--local-cache");
|
||||
make_argv.appendAssumeCapacity("--local-cache");
|
||||
const argv_index_cache_dir = configure_argv.items.len;
|
||||
_ = configure_argv.addOneAssumeCapacity();
|
||||
_ = make_argv.addOneAssumeCapacity();
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--global-cache", undefined };
|
||||
const argv_index_global_cache_dir = make_argv.items.len - 1;
|
||||
|
||||
configure_argv.appendAssumeCapacity("--global-cache");
|
||||
make_argv.appendAssumeCapacity("--global-cache");
|
||||
const argv_index_global_cache_dir = configure_argv.items.len;
|
||||
_ = configure_argv.addOneAssumeCapacity();
|
||||
_ = make_argv.addOneAssumeCapacity();
|
||||
|
||||
make_argv.appendSliceAssumeCapacity(&.{ "--configuration", undefined });
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--configuration", undefined };
|
||||
const argv_index_configuration_file = make_argv.items.len - 1;
|
||||
|
||||
make_argv.appendSliceAssumeCapacity(&.{ "--seed", default_seed });
|
||||
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--seed", default_seed };
|
||||
const argv_index_seed = make_argv.items.len - 1;
|
||||
|
||||
var color: Color = .auto;
|
||||
@@ -5147,13 +5131,10 @@ fn cmdBuild(
|
||||
try configure_argv.appendSlice(arena, &.{ arg, args[i] });
|
||||
continue;
|
||||
} else if (mem.cutPrefix(u8, arg, "-j")) |str| {
|
||||
const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| {
|
||||
fatal("unable to parse jobs count '{s}': {s}", .{
|
||||
str, @errorName(err),
|
||||
});
|
||||
};
|
||||
const num = std.fmt.parseUnsigned(u32, str, 10) catch |err|
|
||||
fatal("unable to parse jobs count {s}: {t}", .{ str, err });
|
||||
if (num < 1) {
|
||||
fatal("number of jobs must be at least 1\n", .{});
|
||||
fatal("number of jobs must be at least 1", .{});
|
||||
}
|
||||
n_jobs = num;
|
||||
} else if (mem.eql(u8, arg, "--seed")) {
|
||||
@@ -5287,11 +5268,6 @@ fn cmdBuild(
|
||||
} });
|
||||
defer _ = make_runner_task.cancel(io) catch {};
|
||||
|
||||
configure_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
|
||||
configure_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;
|
||||
configure_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path;
|
||||
configure_argv.items[argv_index_cache_dir] = dirs.local_cache.path orelse cwd_path;
|
||||
|
||||
make_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
|
||||
make_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;
|
||||
make_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path;
|
||||
|
||||
Reference in New Issue
Block a user