flake_env/bin/flake_env.re
2024-08-17 09:36:21 -04:00

62 lines
1.7 KiB
ReasonML

open Lib;
let main = () => {
Lib.Watches.(
switch (Util.get_args(Sys.argv)) {
| Ok((layout_directory, flake_specifier, other_args)) =>
switch (preflight(layout_directory)) {
| Ok () =>
switch (Lib.Watches.get_extant()) {
| Ok(watches) =>
let paths = List.map(watch => watch.path, watches);
let hash =
switch (Util.hash_files(paths)) {
| Ok(hsh) => hsh
| Error(msg) =>
Printf.eprintf("%s\n", msg);
exit(1);
};
let profile = layout_directory ++ "/flake-profile-" ++ hash;
let profile_rc = profile ++ ".rc";
switch (Lib.Util.is_file(profile_rc), Lib.Util.is_file(profile)) {
| (true, true) =>
let profile_rc_mtime = Unix.stat(profile_rc).st_mtime;
let all_older =
List.map(watch => watch.modtime, watches)
|> List.for_all(watch_mtime =>
watch_mtime <= int_of_float(profile_rc_mtime)
);
if (all_older) {
print_cur_cache(profile_rc);
} else {
freshen_cache(
layout_directory,
hash,
flake_specifier,
other_args,
);
};
| _ =>
freshen_cache(layout_directory, hash, flake_specifier, other_args)
};
| Error(e) =>
Printf.eprintf("%s\n", e);
exit(1);
}
| Error(e) =>
Printf.eprintf("%s\n", e);
exit(1);
}
| Error () =>
Printf.eprintf(
"%s <layout_directory> <flake specifier> <...args>\n",
Sys.argv[0],
);
exit(1);
}
);
};
let () = main();