feat(external): Switch between packages & programs automatically
This commit is contained in:
parent
f5e3183de1
commit
875628a097
2 changed files with 21 additions and 9 deletions
28
external/default.nix
vendored
28
external/default.nix
vendored
|
@ -3,7 +3,7 @@
|
||||||
{ pkgs, program, package }:
|
{ pkgs, program, package }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) foldl'fromJSON head readFile replaceStrings tail throw;
|
inherit (builtins) elemAt foldl' fromJSON head length readFile replaceStrings tail throw;
|
||||||
inherit (pkgs) lib runCommand go jq ripgrep;
|
inherit (pkgs) lib runCommand go jq ripgrep;
|
||||||
|
|
||||||
pathToName = p: replaceStrings ["/"] ["_"] (toString p);
|
pathToName = p: replaceStrings ["/"] ["_"] (toString p);
|
||||||
|
@ -36,14 +36,24 @@ let
|
||||||
if path == [] then { gopkg = value; }
|
if path == [] then { gopkg = value; }
|
||||||
else { "${head path}" = mkset (tail path) value; };
|
else { "${head path}" = mkset (tail path) value; };
|
||||||
|
|
||||||
toPackage = self: src: path: entry: package {
|
last = l: elemAt l ((length l) - 1);
|
||||||
name = pathToName entry.name entry.name;
|
|
||||||
path = lib.concatStringsSep "/" ([ path ] ++ entry.locator);
|
toPackage = self: src: path: entry:
|
||||||
srcs = map (f: src + ("/" + f)) entry.files;
|
let
|
||||||
deps = map (d: lib.attrByPath (d ++ [ "gopkg" ]) (
|
args = {
|
||||||
throw "missing local dependency '${lib.concatStringsSep "." d}' in '${path}'"
|
srcs = map (f: src + ("/" + f)) entry.files;
|
||||||
) self) entry.localDeps;
|
deps = map (d: lib.attrByPath (d ++ [ "gopkg" ]) (
|
||||||
};
|
throw "missing local dependency '${lib.concatStringsSep "." d}' in '${path}'"
|
||||||
|
) self) entry.localDeps;
|
||||||
|
};
|
||||||
|
libArgs = args // {
|
||||||
|
name = pathToName entry.name;
|
||||||
|
path = lib.concatStringsSep "/" ([ path ] ++ entry.locator);
|
||||||
|
};
|
||||||
|
binArgs = args // {
|
||||||
|
name = last ([ path ] ++ entry.locator);
|
||||||
|
};
|
||||||
|
in if entry.isCommand then (program binArgs) else (package libArgs);
|
||||||
|
|
||||||
in { src, path, deps ? [] }: let
|
in { src, path, deps ? [] }: let
|
||||||
name = pathToName path;
|
name = pathToName path;
|
||||||
|
|
2
external/main.go
vendored
2
external/main.go
vendored
|
@ -34,6 +34,7 @@ type pkg struct {
|
||||||
Files []string `json:"files"`
|
Files []string `json:"files"`
|
||||||
LocalDeps [][]string `json:"localDeps"`
|
LocalDeps [][]string `json:"localDeps"`
|
||||||
ForeignDeps []string `json:"foreignDeps"`
|
ForeignDeps []string `json:"foreignDeps"`
|
||||||
|
IsCommand bool `json:"isCommand"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// findGoDirs returns a filepath.WalkFunc that identifies all
|
// findGoDirs returns a filepath.WalkFunc that identifies all
|
||||||
|
@ -116,6 +117,7 @@ func analysePackage(root, source, importpath string, stdlib map[string]bool) (pk
|
||||||
Files: files,
|
Files: files,
|
||||||
LocalDeps: local,
|
LocalDeps: local,
|
||||||
ForeignDeps: foreign,
|
ForeignDeps: foreign,
|
||||||
|
IsCommand: p.IsCommand(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue