Compare commits

..

4 commits

Author SHA1 Message Date
Bryan Bennett
7b4fd3de8f
Reduce dune version to work with Nix 23.11 2024-01-26 07:28:59 -05:00
Bryan Bennett
a8d2d777a9
nixpkgs-fmt default.nix 2024-01-17 08:26:23 -05:00
Bryan Bennett
6c66f0271d
Ignore result symlink 2024-01-17 08:23:08 -05:00
Bryan Bennett
536791abfb
Add pre-commit-hooks.nix integration 2024-01-17 08:22:39 -05:00
7 changed files with 26 additions and 64 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
_build/ _build/
_coverage/ _coverage/
result result
/.pre-commit-config.yaml

1
.pre-commit-config.yaml Symbolic link
View file

@ -0,0 +1 @@
/nix/store/y3cj5g3rd064bxpi3r2i1k2nzhk9qrdw-pre-commit-config.json

View file

@ -12,14 +12,7 @@ let main = () => {
switch (Lib.Watches.get()) { switch (Lib.Watches.get()) {
| Ok(watches) => | Ok(watches) =>
let paths = Array.map(~f=watch => watch.path, watches); let paths = Array.map(~f=watch => watch.path, watches);
let hash = let hash = Util.hash_files(paths);
switch (Util.hash_files(paths)) {
| Ok(hsh) => hsh
| Error(msg) =>
Printf.eprintf("%s\n", e);
exit(1);
};
let profile = layout_directory ++ "/flake-profile-" ++ hash; let profile = layout_directory ++ "/flake-profile-" ++ hash;
let profile_rc = profile ++ ".rc"; let profile_rc = profile ++ ".rc";

View file

@ -41,7 +41,7 @@ use_flake_env() {
local ld=$(direnv_layout_dir) local ld=$(direnv_layout_dir)
export direnv export direnv
eval "$(@flake_env@ "${1:-"."}" "$ld")" eval "$(@flake_env@ "$ld" "$@")"
export -n direnv export -n direnv

View file

@ -10,7 +10,7 @@ doc: "https://git.sr.ht/~bryan_bennett/flake_env"
bug-reports: "https://todo.sr.ht/~bryan_bennett/flake_env" bug-reports: "https://todo.sr.ht/~bryan_bennett/flake_env"
depends: [ depends: [
"ocaml" "ocaml"
"dune" {>= "3.11"} "dune" {>= "3.12"}
"odoc" {with-doc} "odoc" {with-doc}
] ]
build: [ build: [

View file

@ -17,39 +17,23 @@ let nix = args =>
); );
let hash_files = filenames => { let hash_files = filenames => {
/*** Hash all entries in [filenames] /*** Hash all entries in [filenames], returning a hex-encoded string of the hash of their contents */
Returns Some(hex-string) or None if no filenames are found.
*/
let ctx = Sha1.init(); let ctx = Sha1.init();
let files_to_hash = let () =
filenames filenames
|> Array.filter(~f=f => |> Array.filter(~f=f =>
switch (Sys_unix.file_exists(f)) { switch (Sys_unix.file_exists(f)) {
| `Yes => true | `Yes => true
| _ => | _ => false
// let fullpth = Filename_unix.realpath(f);
Printf.eprintf(
"Cannot find file %s (cwd: %s)\n",
f,
Core_unix.getcwd(),
);
false;
} }
); )
|> Array.iter(~f=f => {
switch (files_to_hash |> Array.length) { f
| 0 => Error("No files found to hash") |> In_channel.create
| _ => |> In_channel.input_all
let () = |> Sha1.update_string(ctx)
files_to_hash });
|> Array.iter(~f=f => { Sha1.finalize(ctx) |> Sha1.to_hex;
f
|> In_channel.create
|> In_channel.input_all
|> Sha1.update_string(ctx)
});
Ok(Sha1.finalize(ctx) |> Sha1.to_hex);
};
}; };
let rec rmrf = path => { let rec rmrf = path => {

View file

@ -16,22 +16,7 @@ let _syst_to_bool =
let check_exit_or_signal = let check_exit_or_signal =
Alcotest.(check(Alcotest.pair(testable_exit_or_signal, string))); Alcotest.(check(Alcotest.pair(testable_exit_or_signal, string)));
let testable_result_string = let check_string = Alcotest.(check(string));
Alcotest.testable(
(pp_fmt, elem) => {
switch (elem) {
| Ok(s) => Fmt.pf(pp_fmt, "Ok(%s)", s)
| Error(s) => Fmt.pf(pp_fmt, "Error(%s)", s)
}
},
(a, b) =>
switch (a, b) {
| (Ok(a), Ok(b)) => String.compare(a, b) == 0
| (Error(a), Error(b)) => String.compare(a, b) == 0
| _ => false
},
);
let check_result_string = Alcotest.(check(testable_result_string));
let check_bool = Alcotest.(check(bool)); let check_bool = Alcotest.(check(bool));
let check_get_args = let check_get_args =
Alcotest.( Alcotest.(
@ -62,26 +47,26 @@ let test_run_process_stdout = () =>
); );
let test_hash_one = () => { let test_hash_one = () => {
check_result_string( check_string(
"Hash matches", "Hash matches",
Ok("32b4ac64be805d730745f6bac45a5d95174ebd10"), hash_files([|"../LICENSE"|]),
hash_files([|"spit_version.sh"|]), "b43cf2e824eb66ba0e8f939c08072a8e307b5e5f",
); );
}; };
let test_hash_multiple = () => { let test_hash_multiple = () => {
check_result_string( check_string(
"Hash matches", "Hash matches",
Ok("e4c880fc6ab9a1b88e6be18e53fc4cec9f463d1a"), hash_files([|"../LICENSE", "../LICENSE"|]),
hash_files([|"spit_version.sh", "spit_version.sh"|]), "08304d8baeed02722f81252952b00f6ac011ce0c",
); );
}; };
let test_hash_filters_nonexistent = () => { let test_hash_filters_nonexistent = () => {
check_result_string( check_string(
"Hash matches", "Hash matches",
Ok("32b4ac64be805d730745f6bac45a5d95174ebd10"), hash_files([|"../LICENSE", "FOOBARBAZ"|]),
hash_files([|"spit_version.sh", "FOOBARBAZ"|]), "b43cf2e824eb66ba0e8f939c08072a8e307b5e5f",
); );
}; };