mirror of
https://git.sr.ht/~bryan_bennett/flake_env
synced 2025-12-17 23:11:23 +01:00
Remove dependency on Janestreet Core
Core doubles the closure size and adds 8mb to the binary size for dubious benefit. This adds FileUtils to do the file interaction bits that aren't in the stdlib and removes Core in preference to the bundled Stdlib. Tests are passing, but I want to investigate the nix build before I commit to this approach
This commit is contained in:
parent
3f5f7a602d
commit
5c01142933
11 changed files with 184 additions and 232 deletions
|
|
@ -1,7 +1,5 @@
|
|||
open Core;
|
||||
open Yojson.Safe.Util;
|
||||
|
||||
module Unix = Core_unix;
|
||||
module StringSet = Set.Make(String);
|
||||
module Util = Flake_env__util;
|
||||
|
||||
|
|
@ -16,24 +14,30 @@ type watch = {
|
|||
type watches = array(watch);
|
||||
|
||||
let get = () => {
|
||||
let direnv_watch_str =
|
||||
Sys.getenv("DIRENV_WATCHES")
|
||||
|> Option.value_exn(~message="Environment missing DIRENV_WATCHES");
|
||||
let proc_info =
|
||||
Unix.create_process(
|
||||
~prog="direnv",
|
||||
~args=["show_dump", direnv_watch_str],
|
||||
);
|
||||
let sub_stdout = Unix.in_channel_of_descr(proc_info.stdout);
|
||||
let direnv_watch_str = Sys.getenv("DIRENV_WATCHES");
|
||||
|
||||
switch (Unix.waitpid(proc_info.pid)) {
|
||||
| Ok () => Ok(watches_of_yojson(Yojson.Safe.from_channel(sub_stdout)))
|
||||
let (read_p, write_p) = Unix.pipe();
|
||||
let pid =
|
||||
Unix.create_process(
|
||||
"direnv",
|
||||
[|"direnv", "show_dump", direnv_watch_str|],
|
||||
Unix.stdin,
|
||||
write_p,
|
||||
Unix.stderr,
|
||||
);
|
||||
let sub_stdout = Unix.in_channel_of_descr(read_p);
|
||||
|
||||
switch (Unix.waitpid([], pid)) {
|
||||
| (reported_pid, WEXITED(0)) when reported_pid == pid =>
|
||||
Ok(watches_of_yojson(Yojson.Safe.from_channel(sub_stdout)))
|
||||
| _ => Error("Failed to parse watches")
|
||||
};
|
||||
};
|
||||
|
||||
let get_path = doc =>
|
||||
String.drop_prefix(doc |> member("path") |> to_string, 11);
|
||||
let get_path = doc => {
|
||||
let pth = doc |> member("path") |> to_string;
|
||||
String.sub(pth, 11, String.length(pth) - 11);
|
||||
};
|
||||
|
||||
let rec get_paths_from_doc = (doc, paths) => {
|
||||
let p = get_path(doc);
|
||||
|
|
@ -42,16 +46,16 @@ let rec get_paths_from_doc = (doc, paths) => {
|
|||
doc
|
||||
|> member("inputs")
|
||||
|> to_assoc
|
||||
|> List.map(~f=((_k, v)) => get_paths_from_doc(v, paths)),
|
||||
|> List.map(((_k, v)) => get_paths_from_doc(v, paths)),
|
||||
);
|
||||
List.concat([[p], sub_paths]);
|
||||
};
|
||||
|
||||
let get_input_paths = () => {
|
||||
switch (Util.nix(["flake", "archive", "--json", "--no-write-lock-file"])) {
|
||||
| (Ok (), output) =>
|
||||
| (WEXITED(0), output) =>
|
||||
get_paths_from_doc(Yojson.Safe.from_string(output), [])
|
||||
| (Error(_), _) =>
|
||||
| _ =>
|
||||
Printf.eprintf(
|
||||
"Failed to parse output of `nix flake archive --json`. Ignorning flake inputs. \n",
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue