Bladeren bron

add --path-link option

Jonathan Marler 4 jaren geleden
bovenliggende
commit
5f8c011e6d
2 gewijzigde bestanden met toevoegingen van 31 en 1 verwijderingen
  1. 19 0
      test
  2. 12 1
      zigup.zig

+ 19 - 0
test

@@ -0,0 +1,19 @@
+#!/usr/bin/env sh
+set -ex
+
+rm -rf scratch
+mkdir scratch
+mkdir scratch/install scratch/bin
+
+zigup="./zig-cache/bin/zigup --install-dir scratch/install --path-link scratch/bin/zig"
+
+$zigup $opt || true
+$zigup default
+$zigup fetch-index
+$zigup 0.5.0
+$zigup fetch 0.5.0
+$zigup latest
+$zigup list
+$zigup default 0.5.0
+#$zigup default latest
+$zigup latest

+ 12 - 1
zigup.zig

@@ -7,7 +7,8 @@ const Allocator = mem.Allocator;
 
 const ziget = @import("ziget");
 
-var globalOptionalInstallDir : ?[]const u8 = undefined;
+var globalOptionalInstallDir : ?[]const u8 = null;
+var globalOptionalPathLink : ?[]const u8 = null;
 
 fn find_zigs(allocator: *Allocator) !?[][]u8 {
     const ziglist = std.ArrayList([]u8).init(allocator);
@@ -101,6 +102,8 @@ fn getAndCreateInstallDir(allocator: *Allocator) ![]const u8 {
 }
 
 fn makeZigPathLinkString(allocator: *Allocator) ![]const u8 {
+    if (globalOptionalPathLink) |path| return path;
+
     // for now we're just going to hardcode the path to $HOME/bin/zig
     const home = std.os.getenv("HOME") orelse {
         std.debug.warn("Error: cannot find install directory, $HOME environment variable is not set\n", .{});
@@ -133,6 +136,9 @@ fn help() void {
         \\
         \\Common Options:
         \\  --install-dir DIR             override the default install location
+        \\  --path-link PATH              path to the `zig` symlink that points to the default compiler
+        \\                                this will typically be a file path within a PATH directory so
+        \\                                that the user can just run `zig`
     ) catch unreachable;
 }
 
@@ -174,6 +180,11 @@ pub fn main2() !u8 {
                 if (!std.fs.path.isAbsolute(globalOptionalInstallDir.?)) {
                     globalOptionalInstallDir = try toAbsolute(allocator, globalOptionalInstallDir.?);
                 }
+            } else if (std.mem.eql(u8, "--path-link", arg)) {
+                globalOptionalPathLink = try getCmdOpt(args, &i);
+                if (!std.fs.path.isAbsolute(globalOptionalPathLink.?)) {
+                    globalOptionalPathLink = try toAbsolute(allocator, globalOptionalPathLink.?);
+                }
             } else {
                 args[newlen] = args[i];
                 newlen += 1;