Skip to content

Commit

Permalink
fix EnvelopeReader etc. about file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
gfngfn committed Jan 5, 2024
1 parent 35dfa4f commit 9cc30c5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 39 deletions.
12 changes: 8 additions & 4 deletions check-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ FAILED=0
for FILE in $(find lib-satysfi -name saphe.yaml); do
DIR="$(dirname "$FILE")"
echo " ==== $DIR ===="
./saphe solve "$DIR"
saphe solve "$DIR"
if [ $? -ne 0 ]; then
echo "! FAILED (not solved)"
FAILED=1
fi
if diff "$DIR/saphe.lock.yaml" "$DIR/saphe.lock.yaml.expected"; then
if diff "$DIR/satysfi-envelope.yaml" "$DIR/satysfi-envelope.yaml.expected"; then
echo "(TODO: build)"
#saphe build "$DIR"
echo "* OK: $DIR"
saphe build "$DIR"
if [ $? -ne 0 ]; then
echo "! FAILED (cannot build)"
FAILED=1
else
echo "* OK: $DIR"
fi
else
echo "! FAILED (envelope config mismatch): $DIR"
FAILED=1
Expand Down
30 changes: 17 additions & 13 deletions src-saphe/constant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ let lock_directory ~store_root:(absdir_store_root : abs_path) (lock : Lock.t) :
(lock_tarball_name package_name locked_version))


(* Should be in sync with SATySFi *)
let envelope_config_path ~dir:(absdir_library : abs_path) : abs_path =
append_to_abs_directory absdir_library "satysfi-envelope.yaml"


let lock_envelope_config ~(store_root : abs_path) (lock : Lock.t) : abs_path =
envelope_config_path ~dir:(lock_directory ~store_root lock)


let registry_root_directory_path ~store_root:(absdir_store_root : abs_path) (registry_hash_value : registry_hash_value) : abs_path =
make_abs_path (Filename.concat
(get_abs_path_string absdir_store_root)
Expand All @@ -41,43 +50,38 @@ let package_registry_config_file_name =
"saphe-registry.yaml"


let library_package_config_path (absdir_library : abs_path) : abs_path =
let library_package_config_path ~dir:(absdir_library : abs_path) : abs_path =
make_abs_path (Filename.concat (get_abs_path_string absdir_library) "saphe.yaml")


let document_package_config_path (abspath_doc : abs_path) : abs_path =
let document_package_config_path ~doc:(abspath_doc : abs_path) : abs_path =
let path_without_extension = Filename.remove_extension (get_abs_path_string abspath_doc) in
make_abs_path (Printf.sprintf "%s.saphe.yaml" path_without_extension)


let library_lock_config_path (absdir_library : abs_path) : abs_path =
let library_lock_config_path ~dir:(absdir_library : abs_path) : abs_path =
make_abs_path (Filename.concat (get_abs_path_string absdir_library) "saphe.lock.yaml")


let library_deps_config_path (absdir_library : abs_path) : abs_path =
let library_deps_config_path ~dir:(absdir_library : abs_path) : abs_path =
make_abs_path (Filename.concat (get_abs_path_string absdir_library) "satysfi-deps.yaml")


let document_lock_config_path (abspath_doc : abs_path) : abs_path =
let document_lock_config_path ~doc:(abspath_doc : abs_path) : abs_path =
let path_without_extension = Filename.remove_extension (get_abs_path_string abspath_doc) in
make_abs_path (Printf.sprintf "%s.saphe.lock.yaml" path_without_extension)


let document_deps_config_path (abspath_doc : abs_path) : abs_path =
let document_deps_config_path ~doc:(abspath_doc : abs_path) : abs_path =
let path_without_extension = Filename.remove_extension (get_abs_path_string abspath_doc) in
make_abs_path (Printf.sprintf "%s.satysfi-deps.yaml" path_without_extension)


let default_output_path (abspath_doc : abs_path) : abs_path =
let default_output_path ~doc:(abspath_doc : abs_path) : abs_path =
let path_without_extension = Filename.remove_extension (get_abs_path_string abspath_doc) in
make_abs_path (Printf.sprintf "%s.pdf" path_without_extension)


let dump_path (abspath_doc : abs_path) : abs_path =
let dump_path ~doc:(abspath_doc : abs_path) : abs_path =
let path_without_extension = Filename.remove_extension (get_abs_path_string abspath_doc) in
make_abs_path (Printf.sprintf "%s.satysfi-aux" path_without_extension)


(* Should be in sync with SATySFi *)
let envelope_config_path (absdir_library : abs_path) : abs_path =
make_abs_path (Filename.concat (get_abs_path_string absdir_library) "satysfi-envelope.yaml")
4 changes: 2 additions & 2 deletions src-saphe/lockFetcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let main ~(wget_command : string) ~(tar_command : string) ~(unzip_command : stri
(* Creates the directory if non-existent, or does nothing otherwise: *)
ShellCommand.mkdir_p absdir_lock;

let abspath_config = Constant.library_package_config_path absdir_lock in
let abspath_config = Constant.library_package_config_path ~dir:absdir_lock in
if Sys.file_exists (get_abs_path_string abspath_config) then begin
(* If the lock has already been fetched: *)
Logging.lock_already_installed lock_tarball_name absdir_lock;
Expand Down Expand Up @@ -117,7 +117,7 @@ let main ~(wget_command : string) ~(tar_command : string) ~(unzip_command : stri

(* Fetches external sources according to the package config: *)
let* PackageConfig.{ external_resources; _ } =
PackageConfig.load (Constant.library_package_config_path absdir_lock)
PackageConfig.load (Constant.library_package_config_path ~dir:absdir_lock)
in
let* () =
external_resources |> foldM (fun () (name, external_resource) ->
Expand Down
26 changes: 13 additions & 13 deletions src-saphe/sapheMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ let solve ~(fpath_in : string) =
let abspath_in = make_absolute_if_relative ~origin:absdir_current fpath_in in
if is_directory abspath_in then
(* If the input is a directory that forms a package: *)
let abspath_lock_config = Constant.library_lock_config_path abspath_in in
let abspath_envelope_config = Constant.envelope_config_path abspath_in in
let abspath_lock_config = Constant.library_lock_config_path ~dir:abspath_in in
let abspath_envelope_config = Constant.envelope_config_path ~dir:abspath_in in
PackageSolveInput{
root = abspath_in;
lock = abspath_lock_config;
envelope = abspath_envelope_config;
}
else
let abspath_package_config = Constant.document_package_config_path abspath_in in
let abspath_lock_config = Constant.document_lock_config_path abspath_in in
let abspath_package_config = Constant.document_package_config_path ~doc:abspath_in in
let abspath_lock_config = Constant.document_lock_config_path ~doc:abspath_in in
DocumentSolveInput{
doc = abspath_in;
config = abspath_package_config;
Expand All @@ -550,7 +550,7 @@ let solve ~(fpath_in : string) =
lock = abspath_lock_config;
envelope = abspath_envelope_config;
} ->
let abspath_package_config = Constant.library_package_config_path absdir_package in
let abspath_package_config = Constant.library_package_config_path ~dir:absdir_package in
let*
PackageConfig.{
language_requirement;
Expand Down Expand Up @@ -730,7 +730,7 @@ let make_envelope_spec ~(store_root : abs_path) (locked_package : LockConfig.loc
let envelope_dependencies = lock_dependencies |> List.map make_envelope_dependency in
{
envelope_name = lock_name;
envelope_path = get_abs_path_string (Constant.lock_directory ~store_root lock);
envelope_path = get_abs_path_string (Constant.lock_envelope_config ~store_root lock);
envelope_dependencies;
test_only_envelope = test_only_lock;
}
Expand Down Expand Up @@ -783,9 +783,9 @@ let build
let absdir_current = Sys.getcwd () in
let abspath_in = make_absolute_if_relative ~origin:absdir_current fpath_in in
if is_directory abspath_in then
let abspath_lock_config = Constant.library_lock_config_path abspath_in in
let abspath_deps_config = Constant.library_deps_config_path abspath_in in
let abspath_envelope_config = Constant.envelope_config_path abspath_in in
let abspath_lock_config = Constant.library_lock_config_path ~dir:abspath_in in
let abspath_deps_config = Constant.library_deps_config_path ~dir:abspath_in in
let abspath_envelope_config = Constant.envelope_config_path ~dir:abspath_in in
PackageBuildInput{
root = abspath_in;
lock = abspath_lock_config;
Expand All @@ -794,17 +794,17 @@ let build
options;
}
else
let abspath_lock_config = Constant.document_lock_config_path abspath_in in
let abspath_deps_config = Constant.document_deps_config_path abspath_in in
let abspath_lock_config = Constant.document_lock_config_path ~doc:abspath_in in
let abspath_deps_config = Constant.document_deps_config_path ~doc:abspath_in in
let abspath_out =
match fpath_out_opt with
| None ->
Constant.default_output_path abspath_in
Constant.default_output_path ~doc:abspath_in

| Some(fpath_out) ->
make_absolute_if_relative ~origin:absdir_current fpath_out
in
let abspath_dump = Constant.dump_path abspath_in in
let abspath_dump = Constant.dump_path ~doc:abspath_in in
DocumentBuildInput{
doc = abspath_in;
lock = abspath_lock_config;
Expand Down
12 changes: 8 additions & 4 deletions src/frontend/closedEnvelopeDependencyResolver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module EnvelopeDependencyGraph = DependencyGraph.Make(String)

type envelope_info = {
envelope_name : envelope_name;
envelope_directory : abs_path;
envelope_config : abs_path;
envelope_dependencies : envelope_dependency list;
}

Expand All @@ -31,15 +31,19 @@ let main (display_config : Logging.config) ~(use_test_only_envelope : bool) ~(ex
(* Skips test-only envelopes when using sources only: *)
return (graph, entryacc)
else
let absdir_envelope = make_abs_path envelope_path in
let abspath_envelope_config = make_abs_path envelope_path in
(*
match envelope_contents with
| RegisteredLock{ registry_hash_value; package_name; version = locked_version } ->
let libdir = Constant.lock_directory Lock.{ registry_hash_value; package_name; locked_version } in
make_abs_path (Filename.concat (get_abs_path_string absdir_lib_root) (get_lib_path_string libdir))
*)
let* envelope_with_config =
EnvelopeReader.main display_config ~use_test_files:use_test_only_envelope ~extensions absdir_envelope
EnvelopeReader.main
display_config
~use_test_files:use_test_only_envelope
~extensions
~envelope_config:abspath_envelope_config
in
let* (graph, vertex) =
graph |> EnvelopeDependencyGraph.add_vertex envelope_name envelope_with_config
Expand All @@ -48,7 +52,7 @@ let main (display_config : Logging.config) ~(use_test_only_envelope : bool) ~(ex
let envelope_info =
{
envelope_name;
envelope_directory = absdir_envelope;
envelope_config = abspath_envelope_config;
envelope_dependencies;
}
in
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/envelopeReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let make_path_list_absolute ~(origin : abs_path) (reldirs : string list) : abs_p
)


let main (display_config : Logging.config) ~(use_test_files : bool) ~(extensions : string list) (abspath_envelope_config : abs_path) : (EnvelopeConfig.t * untyped_envelope) ok =
let main (display_config : Logging.config) ~(use_test_files : bool) ~(extensions : string list) ~envelope_config:(abspath_envelope_config : abs_path) : (EnvelopeConfig.t * untyped_envelope) ok =
let open ResultMonad in
let* config = EnvelopeConfig.load abspath_envelope_config in
let absdir_envelope =
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/envelopeReader.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ val main :
Logging.config ->
use_test_files:bool ->
extensions:(string list) ->
abs_path ->
envelope_config:abs_path ->
(EnvelopeConfig.t * untyped_envelope, config_error) result
2 changes: 1 addition & 1 deletion src/frontend/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ let load_deps_config (abspath_deps_config : abs_path) : DepsConfig.t =


let load_envelope (display_config : Logging.config) ~(use_test_files : bool) ~(extensions : string list) (abspath_envelope_config : abs_path) =
match EnvelopeReader.main display_config ~use_test_files ~extensions abspath_envelope_config with
match EnvelopeReader.main display_config ~use_test_files ~extensions ~envelope_config:abspath_envelope_config with
| Ok(pair) -> pair
| Error(e) -> raise (ConfigError(e))

Expand Down

0 comments on commit 9cc30c5

Please sign in to comment.