mirror of
https://git.sr.ht/~bryan_bennett/flake_env
synced 2025-12-17 07:01: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
71
lib/lib.re
71
lib/lib.re
|
|
@ -1,33 +1,34 @@
|
|||
open Core;
|
||||
module Unix = Core_unix;
|
||||
|
||||
module Util = Flake_env__util;
|
||||
module Watches = Flake_env__watches;
|
||||
module Versions = Flake_env__versions;
|
||||
|
||||
let read_file = f_path =>
|
||||
In_channel.with_open_bin(f_path, In_channel.input_all);
|
||||
let write_file = (f_path, content) =>
|
||||
Out_channel.with_open_bin(f_path, c =>
|
||||
Out_channel.output_string(c, content)
|
||||
);
|
||||
|
||||
let print_cur_cache = profile_rc => {
|
||||
In_channel.read_all(profile_rc) |> Printf.printf("%s");
|
||||
read_file(profile_rc) |> Printf.printf("%s");
|
||||
};
|
||||
|
||||
let clean_old_gcroots = layout_dir => {
|
||||
Util.rmrf(layout_dir ++ "/flake-inputs/");
|
||||
Util.rmrf(layout_dir);
|
||||
Unix.mkdir_p(layout_dir ++ "/flake-inputs/");
|
||||
FileUtil.rm([layout_dir], ~recurse=true);
|
||||
FileUtil.mkdir(~parent=true, layout_dir ++ "/flake-inputs/");
|
||||
};
|
||||
|
||||
let add_gcroot = (store_path, symlink) => {
|
||||
switch (Util.nix(["build", "--out-link", symlink, store_path])) {
|
||||
| (Ok (), _) => Ok()
|
||||
| (err, _) => err
|
||||
| (WEXITED(0), _) => Ok()
|
||||
| (_, _) => Error("Failed to run `nix build`!")
|
||||
};
|
||||
};
|
||||
|
||||
let freshen_cache = (layout_dir, hash, flake_specifier, other_args) => {
|
||||
clean_old_gcroots(layout_dir);
|
||||
let () = clean_old_gcroots(layout_dir);
|
||||
let tmp_profile =
|
||||
layout_dir
|
||||
++ "flake-tmp-profile."
|
||||
++ Core.Pid.to_string(Core_unix.getpid());
|
||||
layout_dir ++ "flake-tmp-profile." ++ string_of_int(Unix.getpid());
|
||||
|
||||
let pde_args = [
|
||||
"print-dev-env",
|
||||
|
|
@ -42,54 +43,40 @@ let freshen_cache = (layout_dir, hash, flake_specifier, other_args) => {
|
|||
let profile_rc = profile ++ ".rc";
|
||||
|
||||
switch (exit_code) {
|
||||
| Ok () =>
|
||||
Out_channel.with_file(
|
||||
~f=f => Out_channel.output_string(f, stdout_content),
|
||||
profile_rc,
|
||||
);
|
||||
| WEXITED(0) =>
|
||||
write_file(profile_rc, stdout_content);
|
||||
|
||||
switch (add_gcroot(tmp_profile, profile)) {
|
||||
| Ok () =>
|
||||
Sys_unix.remove(tmp_profile);
|
||||
let () = FileUtil.rm([tmp_profile]);
|
||||
let flake_input_cache_path = layout_dir ++ "/flake-inputs/";
|
||||
let flake_inputs = Watches.get_input_paths();
|
||||
flake_inputs
|
||||
|> List.iter(~f=inpt => {
|
||||
|> List.iter(inpt => {
|
||||
switch (
|
||||
add_gcroot("/nix/store/" ++ inpt, flake_input_cache_path ++ inpt)
|
||||
) {
|
||||
| Ok () => ()
|
||||
| err =>
|
||||
Printf.eprintf(
|
||||
"Failed creating flake-input gcroot: %s\n",
|
||||
Core_unix.Exit_or_signal.to_string_hum(err),
|
||||
)
|
||||
| Error(err) =>
|
||||
Printf.eprintf("Failed creating flake-input gcroot: %s\n", err)
|
||||
}
|
||||
});
|
||||
print_cur_cache(profile_rc);
|
||||
| err =>
|
||||
Printf.eprintf(
|
||||
"Failed creating gcroot: %s\n",
|
||||
Core_unix.Exit_or_signal.to_string_hum(err),
|
||||
);
|
||||
| Error(err) =>
|
||||
Printf.eprintf("Failed creating gcroot: %s\n", err);
|
||||
exit(1);
|
||||
};
|
||||
| err =>
|
||||
Printf.eprintf(
|
||||
"Failed evaluating flake: %s\n",
|
||||
Core_unix.Exit_or_signal.to_string_hum(err),
|
||||
);
|
||||
| _ =>
|
||||
Printf.eprintf("Failed evaluating flake\n");
|
||||
exit(1);
|
||||
};
|
||||
};
|
||||
|
||||
let preflight = layout_directory => {
|
||||
switch (
|
||||
Versions.preflight_versions(),
|
||||
Sys_unix.is_directory(layout_directory),
|
||||
) {
|
||||
| (Ok(_), `Yes) => Ok()
|
||||
| (Ok(_), _) =>
|
||||
Unix.mkdir_p(layout_directory);
|
||||
switch (Versions.preflight_versions(), Util.is_directory(layout_directory)) {
|
||||
| (Ok(_), true) => Ok()
|
||||
| (Ok(_), false) =>
|
||||
FileUtil.mkdir(~parent=true, layout_directory);
|
||||
Ok();
|
||||
| (err, _) => err
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue