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:
Bryan Bennett 2024-08-12 12:13:53 -04:00
parent 3f5f7a602d
commit 5c01142933
No known key found for this signature in database
GPG key ID: EE149E4215408DE9
11 changed files with 184 additions and 232 deletions

View file

@ -1,14 +1,6 @@
(executable
(name flake_env)
(public_name flake_env)
(libraries
core
core_unix
core_unix.filename_unix
core_unix.sys_unix
ppx_yojson_conv
re
sha
lib)
(libraries lib ppx_yojson_conv re sha)
(preprocess
(pps ppx_yojson_conv ppx_jane)))
(pps ppx_yojson_conv)))

View file

@ -1,64 +1,62 @@
open Core;
module Unix = Core_unix;
open Lib;
let main = () => {
let argv = Sys.get_argv();
switch (Util.get_args(argv)) {
| Ok((layout_directory, flake_specifier, other_args)) =>
switch (preflight(layout_directory)) {
| Ok () =>
switch (Lib.Watches.get()) {
| Ok(watches) =>
let paths = Array.map(~f=watch => watch.path, watches);
let hash =
switch (Util.hash_files(paths)) {
| Ok(hsh) => hsh
| Error(msg) =>
Printf.eprintf("%s\n", msg);
exit(1);
};
Lib.Watches.(
switch (Util.get_args(Sys.argv)) {
| Ok((layout_directory, flake_specifier, other_args)) =>
switch (preflight(layout_directory)) {
| Ok () =>
switch (Lib.Watches.get()) {
| Ok(watches) =>
let paths = Array.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";
let profile = layout_directory ++ "/flake-profile-" ++ hash;
let profile_rc = profile ++ ".rc";
switch (Sys_unix.is_file(profile_rc), Sys_unix.is_file(profile)) {
| (`Yes, `Yes) =>
let profile_rc_mtime = Unix.stat(profile_rc).st_mtime;
let all_older =
Array.map(~f=watch => watch.modtime, watches)
|> Array.for_all(~f=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,
);
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 =
Array.map(watch => watch.modtime, watches)
|> Array.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)
};
| _ =>
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(e) =>
Printf.eprintf("%s\n", e);
| Error () =>
Printf.eprintf(
"%s <layout_directory> <flake specifier> <...args>\n",
Sys.argv[0],
);
exit(1);
}
| Error () =>
Printf.eprintf(
"%s <layout_directory> <flake specifier> <...args>\n",
argv[0],
);
exit(1);
};
);
};
let () = main();