authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-21 18:04:23-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-21 18:04:23-04:00
log77c2ac3fcd27b114b0068d3b64b3d884aa71e4ef
tree380d6bc5c3d2f352dc5fbe95246c7c623e8f2b42
parentf429f4dcabec2324b76b900f5785204897ea7685
signaturelock-open Commit is signed but in an unrecognized format.

zig build: support DESTDIR environment variable

closes #2929

1 files changed, 12 insertions(+), 10 deletions(-)

std/build.zig+12-10
...@@ -41,9 +41,10 @@ pub const Builder = struct {...@@ -41,9 +41,10 @@ pub const Builder = struct {
41 env_map: *BufMap,41 env_map: *BufMap,
42 top_level_steps: ArrayList(*TopLevelStep),42 top_level_steps: ArrayList(*TopLevelStep),
43 install_prefix: ?[]const u8,43 install_prefix: ?[]const u8,
44 search_prefixes: ArrayList([]const u8),44 dest_dir: ?[]const u8,
45 lib_dir: ?[]const u8,45 lib_dir: ?[]const u8,
46 exe_dir: ?[]const u8,46 exe_dir: ?[]const u8,
47 search_prefixes: ArrayList([]const u8),
47 installed_files: ArrayList(InstalledFile),48 installed_files: ArrayList(InstalledFile),
48 build_root: []const u8,49 build_root: []const u8,
49 cache_root: []const u8,50 cache_root: []const u8,
...@@ -125,10 +126,11 @@ pub const Builder = struct {...@@ -125,10 +126,11 @@ pub const Builder = struct {
125 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),126 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
126 .default_step = undefined,127 .default_step = undefined,
127 .env_map = env_map,128 .env_map = env_map,
128 .install_prefix = null,
129 .search_prefixes = ArrayList([]const u8).init(allocator),129 .search_prefixes = ArrayList([]const u8).init(allocator),
130 .install_prefix = null,
130 .lib_dir = null,131 .lib_dir = null,
131 .exe_dir = null,132 .exe_dir = null,
133 .dest_dir = env_map.get("DESTDIR"),
132 .installed_files = ArrayList(InstalledFile).init(allocator),134 .installed_files = ArrayList(InstalledFile).init(allocator),
133 .install_tls = TopLevelStep{135 .install_tls = TopLevelStep{
134 .step = Step.initNoOp("install", allocator),136 .step = Step.initNoOp("install", allocator),
...@@ -164,14 +166,14 @@ pub const Builder = struct {...@@ -164,14 +166,14 @@ pub const Builder = struct {
164 }166 }
165167
166 fn resolveInstallPrefix(self: *Builder) void {168 fn resolveInstallPrefix(self: *Builder) void {
167 const prefix = if (self.install_prefix) |prefix| prefix else blk: {169 const dest_dir = self.dest_dir orelse blk: {
168 const prefix = self.cache_root;170 const dest_dir = self.install_prefix orelse self.cache_root;
169 self.install_prefix = prefix;171 self.dest_dir = dest_dir;
170 break :blk prefix;172 break :blk dest_dir;
171 };173 };
172174 self.dest_dir = dest_dir;
173 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "lib" }) catch unreachable;175 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "lib" }) catch unreachable;
174 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "bin" }) catch unreachable;176 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ dest_dir, "bin" }) catch unreachable;
175 }177 }
176178
177 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {179 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
...@@ -884,7 +886,7 @@ pub const Builder = struct {...@@ -884,7 +886,7 @@ pub const Builder = struct {
884886
885 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {887 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
886 const base_dir = switch (dir) {888 const base_dir = switch (dir) {
887 .Prefix => self.install_prefix.?,889 .Prefix => self.dest_dir.?,
888 .Bin => self.exe_dir.?,890 .Bin => self.exe_dir.?,
889 .Lib => self.lib_dir.?,891 .Lib => self.lib_dir.?,
890 };892 };