use dune_site module to find inputs
this packages the inputs as part of the build and exposes the directory to find them via a generated module. this way, inputs are a resource of the library rather than an input. this means that `dune exec aoc` and `dune utop` will always find the file regardless of where they are invoked, which makes developing in emacs simpler :)
This commit is contained in:
1 parent
e1402bc17d
commit
89eb0c7a27
6 files changed
+24
-11
No files matched your search
+1
-1
@@ -24,7 +24,7 @@ let part2 lines =
|
||||
;;
|
||||
|
||||
let print () =
|
||||
let lines = Utils.lines_of_file "inputs/day1.tt" in
|
||||
let lines = Utils.lines_of_input 1 in
|
||||
Printf.(
|
||||
printf "Day 1.1: %d\n" @@ part1 lines;
|
||||
printf "Day 1.2: %d\n" @@ part2 lines)
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ let part2 lines =
|
||||
;;
|
||||
|
||||
let print () =
|
||||
let lines = Utils.lines_of_file "./inputs/day2.tt" in
|
||||
let lines = Utils.lines_of_input 2 in
|
||||
Printf.(
|
||||
printf "Day 2.1: %d\n" @@ part1 lines;
|
||||
printf "Day 2.2: %d\n" @@ part2 lines)
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
(library
|
||||
(name aoc)
|
||||
(libraries stdio re)
|
||||
(libraries stdio re dune-site)
|
||||
(preprocess (pps ppx_regexp)))
|
||||
|
||||
(install
|
||||
(section (site (aoc inputs)))
|
||||
(files (glob_files ../inputs/*)))
|
||||
|
||||
(generate_sites_module
|
||||
(module inputs)
|
||||
(sites aoc))
|
||||
+8
-8
@@ -1,9 +1,9 @@
|
||||
let lines_of_file filename = Stdio.In_channel.(with_file filename ~f:input_lines)
|
||||
|
||||
let rec print_int_list = function
|
||||
| [] -> ()
|
||||
| e :: l ->
|
||||
print_int e;
|
||||
print_string " ";
|
||||
print_int_list l
|
||||
let lines_of_input day =
|
||||
let base_path =
|
||||
match Inputs.Sites.inputs with
|
||||
| path :: _ -> path
|
||||
| _ -> failwith "cant find sites path"
|
||||
in
|
||||
let path = Printf.sprintf "%s/day%d.tt" base_path day in
|
||||
Stdio.In_channel.(with_file path ~f:input_lines)
|
||||
;;
|
||||
Reference in new issue
Block a user