diff --git a/bin-saphe/saphe.ml b/bin-saphe/saphe.ml index ef5b71826..01c8e280f 100644 --- a/bin-saphe/saphe.ml +++ b/bin-saphe/saphe.ml @@ -15,8 +15,15 @@ let update fpath_in = SapheMain.update ~fpath_in -let solve fpath_in = - SapheMain.solve ~fpath_in +let solve + fpath_in + show_full_path + verbosity += + SapheMain.solve + ~fpath_in + ~show_full_path + ~verbosity let build @@ -188,7 +195,11 @@ let command_update : unit Cmdliner.Cmd.t = let command_solve : unit Cmdliner.Cmd.t = let open Cmdliner in Cmd.v (Cmd.info "solve") - Term.(const solve $ arg_in) + Term.(const solve + $ arg_in + $ flag_full_path + $ flag_verbosity + ) let command_build : unit Cmdliner.Cmd.t = diff --git a/src-common/commonUtil.ml b/src-common/commonUtil.ml index 915bc8210..2838c2af6 100644 --- a/src-common/commonUtil.ml +++ b/src-common/commonUtil.ml @@ -1,4 +1,7 @@ +open MyUtil + + let is_middle_char (char : char) : bool = Char.equal char '-' || Core.Char.is_alpha char || Core.Char.is_digit char @@ -38,3 +41,24 @@ let parse_long_identifier (s : string) : (string list * string) option = return (modnms, varnm) else None + + +type path_display_setting = + | FullPath + | RelativeToCwd of abs_path + + +let display_path (setting : path_display_setting) (abspath : abs_path) = + match setting with + | FullPath -> AbsPath.to_string abspath + | RelativeToCwd(abspath_cwd) -> AbsPath.make_relative ~from:abspath_cwd abspath + + +let is_verbose = function + | Verbosity.Verbose -> true + | _ -> false + + +let is_not_quiet = function + | Verbosity.Quiet -> false + | _ -> true diff --git a/src-common/commonUtil.mli b/src-common/commonUtil.mli index 68379aa72..784a0e1c8 100644 --- a/src-common/commonUtil.mli +++ b/src-common/commonUtil.mli @@ -1,4 +1,6 @@ +open MyUtil + val is_uppercased_identifier : string -> bool val is_lowercased_identifier : string -> bool @@ -6,3 +8,13 @@ val is_lowercased_identifier : string -> bool val parse_long_command : prefix:string -> string -> (string list * string) option val parse_long_identifier : string -> (string list * string) option + +type path_display_setting = + | FullPath + | RelativeToCwd of abs_path + +val display_path : path_display_setting -> abs_path -> string + +val is_verbose : Verbosity.t -> bool + +val is_not_quiet : Verbosity.t -> bool diff --git a/src-saphe/logging.ml b/src-saphe/logging.ml index d742af530..e44500960 100644 --- a/src-saphe/logging.ml +++ b/src-saphe/logging.ml @@ -1,9 +1,20 @@ open MyUtil +open CommonUtil open PackageSystemBase -let show_package_dependency_before_solving (dependencies_with_flags : (dependency_flag * package_dependency) list) = +type config = { + path_display_setting : path_display_setting; + verbosity : Verbosity.t; +} + + +let show_path (config : config) = + display_path config.path_display_setting + + +let show_package_dependency_before_solving (config : config) (dependencies_with_flags : (dependency_flag * package_dependency) list) = Printf.printf " package dependencies to solve:\n"; dependencies_with_flags |> List.iter (fun (flag, dep) -> let PackageDependency{ used_as; spec } = dep in @@ -16,62 +27,84 @@ let show_package_dependency_before_solving (dependencies_with_flags : (dependenc | SourceDependency -> "" | TestOnlyDependency -> ", test_only" in - Printf.printf " - %s (%s%s) used as %s\n" package_name s_restr s_test_only used_as + Printf.printf " - %s (%s%s) used as %s\n" + package_name + s_restr + s_test_only + used_as | LocalFixedDependency{ absolute_path } -> - Printf.printf " - '%s' used as %s\n" (AbsPath.to_string absolute_path) used_as + Printf.printf " - '%s' used as %s\n" + (show_path config absolute_path) + used_as ) -let show_package_dependency_solutions (solutions : package_solution list) = +let show_package_dependency_solutions (config : config) (solutions : package_solution list) = Printf.printf " package dependency solutions:\n"; solutions |> List.iter (fun solution -> match solution.lock with | Lock.Registered(RegisteredLock.{ registered_package_id; locked_version; _ }) -> let RegisteredPackageId.{ package_name; _ } = registered_package_id in - Printf.printf " - %s %s\n" package_name (SemanticVersion.to_string locked_version) + Printf.printf " - %s %s\n" + package_name + (SemanticVersion.to_string locked_version) | Lock.LocalFixed{ absolute_path } -> - Printf.printf " - %s\n" (AbsPath.to_string absolute_path) + Printf.printf " - %s\n" + (show_path config absolute_path) ) -let end_lock_config_output (abspath_lock_config : abs_path) = - Printf.printf " lock config written on '%s'.\n" (AbsPath.to_string abspath_lock_config) +let end_lock_config_output (config : config) (abspath_lock_config : abs_path) = + Printf.printf " lock config written on '%s'.\n" + (show_path config abspath_lock_config) -let end_envelope_config_output (abspath_envelope_config : abs_path) = - Printf.printf " envelope config written on '%s'.\n" (AbsPath.to_string abspath_envelope_config) +let end_envelope_config_output (config : config) (abspath_envelope_config : abs_path) = + Printf.printf " envelope config written on '%s'.\n" + (show_path config abspath_envelope_config) -let end_deps_config_output (abspath_deps_config : abs_path) = - Printf.printf " deps config written on '%s'.\n" (AbsPath.to_string abspath_deps_config) +let end_deps_config_output (config : config) (abspath_deps_config : abs_path) = + if is_verbose config.verbosity then begin + Printf.printf " deps config written on '%s'.\n" + (show_path config abspath_deps_config) + end let lock_already_installed (lock_name : lock_name) (absdir : abs_path) = - Printf.printf " '%s': already installed at '%s'\n" lock_name (AbsPath.to_string absdir) + Printf.printf " '%s': already installed at '%s'\n" + lock_name + (AbsPath.to_string absdir) let lock_cache_exists (lock_name : lock_name) (abspath_tarball : abs_path) = - Printf.printf " cache for '%s' exists at '%s'\n" lock_name (AbsPath.to_string abspath_tarball) + Printf.printf " cache for '%s' exists at '%s'\n" + lock_name + (AbsPath.to_string abspath_tarball) let store_root_config_updated ~(created : bool) (abspath_store_root_config : abs_path) = let verb = if created then "created" else "updated" in - Printf.printf " %s the store root config '%s'\n" verb (AbsPath.to_string abspath_store_root_config) + Printf.printf " %s the store root config '%s'\n" + verb + (AbsPath.to_string abspath_store_root_config) let package_registry_updated ~(created : bool) (absdir_registry_repo : abs_path) = let verb = if created then "fetched" else "updated" in - Printf.printf " %s the package registry '%s'\n" verb (AbsPath.to_string absdir_registry_repo) + Printf.printf " %s the package registry '%s'\n" + verb + (AbsPath.to_string absdir_registry_repo) -let initialize_file (abspath_doc : abs_path) = - Printf.printf " created '%s'\n" (AbsPath.to_string abspath_doc) +let initialize_file (config : config) (abspath_doc : abs_path) = + Printf.printf " created '%s'\n" (show_path config abspath_doc) -let initialize_package_config (abspath_package_config : abs_path) = - Printf.printf " created a package config '%s'\n" (AbsPath.to_string abspath_package_config) +let initialize_package_config (config : config) (abspath_package_config : abs_path) = + Printf.printf " created a package config '%s'\n" (show_path config abspath_package_config) let downloading_lock (lock_name : lock_name) (absdir : abs_path) = diff --git a/src-saphe/logging.mli b/src-saphe/logging.mli index 5c2c585ff..fe1be4cce 100644 --- a/src-saphe/logging.mli +++ b/src-saphe/logging.mli @@ -1,16 +1,22 @@ open MyUtil +open CommonUtil open PackageSystemBase -val show_package_dependency_before_solving : (dependency_flag * package_dependency) list -> unit +type config = { + path_display_setting : path_display_setting; + verbosity : Verbosity.t; +} -val show_package_dependency_solutions : package_solution list -> unit +val show_package_dependency_before_solving : config -> (dependency_flag * package_dependency) list -> unit -val end_lock_config_output : abs_path -> unit +val show_package_dependency_solutions : config -> package_solution list -> unit -val end_envelope_config_output : abs_path -> unit +val end_lock_config_output : config -> abs_path -> unit -val end_deps_config_output : abs_path -> unit +val end_envelope_config_output : config -> abs_path -> unit + +val end_deps_config_output : config -> abs_path -> unit val lock_already_installed : lock_name -> abs_path -> unit @@ -20,9 +26,9 @@ val store_root_config_updated : created:bool -> abs_path -> unit val package_registry_updated : created:bool -> abs_path -> unit -val initialize_file : abs_path -> unit +val initialize_file : config -> abs_path -> unit -val initialize_package_config : abs_path -> unit +val initialize_package_config : config -> abs_path -> unit val downloading_lock : lock_name -> abs_path -> unit diff --git a/src-saphe/sapheMain.ml b/src-saphe/sapheMain.ml index 4dfe976c0..510588b67 100644 --- a/src-saphe/sapheMain.ml +++ b/src-saphe/sapheMain.ml @@ -1,5 +1,6 @@ open MyUtil +open CommonUtil open EnvelopeSystemBase open PackageSystemBase open ConfigError @@ -10,6 +11,16 @@ let version = (SemanticVersion.to_string Constant.current_ecosystem_version) +let make_display_config ~(show_full_path : bool) ~(verbosity : Verbosity.t) ~current_dir:(absdir_current : abs_path) = + let path_display_setting = + if show_full_path then + FullPath + else + RelativeToCwd(absdir_current) + in + Logging.{ path_display_setting; verbosity } + + type solve_input = | PackageSolveInput of { root : abs_path; (* The absolute path of a directory used as the package root *) @@ -158,23 +169,23 @@ type package_init_input = } -let write_package_config (abspath_package_config : abs_path) ~(data : string) = +let write_package_config (display_config : Logging.config) (abspath_package_config : abs_path) ~(data : string) = let open ResultMonad in let* () = AbsPathIo.write_file abspath_package_config data |> Result.map_error (fun message -> FailedToWriteFile{ path = abspath_package_config; message }) in - Logging.initialize_package_config abspath_package_config; + Logging.initialize_package_config display_config abspath_package_config; return () -let write_initial_file (abspath : abs_path) ~(data : string) = +let write_initial_file (display_config : Logging.config) (abspath : abs_path) ~(data : string) = let open ResultMonad in let* () = AbsPathIo.write_file abspath data |> Result.map_error (fun message -> FailedToWriteFile{ path = abspath; message }) in - Logging.initialize_file abspath; + Logging.initialize_file display_config abspath; return () @@ -190,8 +201,15 @@ let init_document ~(fpath_in : string) = let res = let open ResultMonad in - (* Constructs the input: *) let absdir_current = AbsPathIo.getcwd () in + let display_config = + make_display_config + ~show_full_path:true (* TODO: make this changeable *) + ~verbosity:Verbosity.Verbose + ~current_dir:absdir_current + in + + (* Constructs the input: *) let abspath_doc = AbsPath.make_absolute_if_relative ~origin:absdir_current fpath_in in let abspath_package_config = Constant.document_package_config_path ~doc:abspath_doc in let absdir = AbsPath.dirname abspath_doc in @@ -202,14 +220,14 @@ let init_document ~(fpath_in : string) = match Filename.extension (AbsPath.to_string abspath_doc) with | ".saty" -> ShellCommand.mkdir_p absdir; - let* () = write_package_config abspath_package_config ~data:InitData.document_package_config_contents in - let* () = write_initial_file abspath_doc ~data:InitData.document_contents in + let* () = write_package_config display_config abspath_package_config ~data:InitData.document_package_config_contents in + let* () = write_initial_file display_config abspath_doc ~data:InitData.document_contents in return () | ".md" -> ShellCommand.mkdir_p absdir; - let* () = write_package_config abspath_package_config ~data:InitData.markdown_package_config_contents in - let* () = write_initial_file abspath_doc ~data:InitData.markdown_contents in + let* () = write_package_config display_config abspath_package_config ~data:InitData.markdown_package_config_contents in + let* () = write_initial_file display_config abspath_doc ~data:InitData.markdown_contents in return () | extension -> @@ -224,8 +242,15 @@ let init_library ~(fpath_in : string) = let res = let open ResultMonad in - (* Constructs the input: *) let absdir_current = AbsPathIo.getcwd () in + let display_config = + make_display_config + ~show_full_path:true (* TODO: make this changeable *) + ~verbosity:Verbosity.Verbose + ~current_dir:absdir_current + in + + (* Constructs the input: *) let absdir_package = AbsPath.make_absolute_if_relative ~origin:absdir_current fpath_in in let abspath_package_config = Constant.library_package_config_path ~dir:absdir_package in let abspath_source = AbsPath.append_to_directory absdir_package "src/calc.satyh" in @@ -238,9 +263,9 @@ let init_library ~(fpath_in : string) = ShellCommand.mkdir_p absdir_package; ShellCommand.mkdir_p (AbsPath.append_to_directory absdir_package "src"); ShellCommand.mkdir_p (AbsPath.append_to_directory absdir_package "test"); - let* () = write_package_config abspath_package_config ~data:InitData.library_package_config_contents in - let* () = write_initial_file abspath_source ~data:InitData.library_source_contents in - let* () = write_initial_file abspath_test ~data:InitData.library_test_contents in + let* () = write_package_config display_config abspath_package_config ~data:InitData.library_package_config_contents in + let* () = write_initial_file display_config abspath_source ~data:InitData.library_source_contents in + let* () = write_initial_file display_config abspath_test ~data:InitData.library_test_contents in return () in @@ -272,13 +297,19 @@ let make_solve_input ~current_dir:(absdir_current : abs_path) ~(fpath_in : strin } -let solve ~(fpath_in : string) = +let solve + ~(fpath_in : string) + ~(show_full_path : bool) + ~(verbosity : Verbosity.t) += let res = let open ResultMonad in + let absdir_current = AbsPathIo.getcwd () in + let display_config = make_display_config ~show_full_path ~verbosity ~current_dir:absdir_current in + (* Constructs the input: *) let solve_input = - let absdir_current = AbsPathIo.getcwd () in make_solve_input ~current_dir:absdir_current ~fpath_in in @@ -314,7 +345,7 @@ let solve ~(fpath_in : string) = CannotWriteEnvelopeConfig{ message; path = abspath_envelope_config } ) in - Logging.end_envelope_config_output abspath_envelope_config; + Logging.end_envelope_config_output display_config abspath_envelope_config; let dependencies_with_flags = List.append @@ -351,7 +382,7 @@ let solve ~(fpath_in : string) = return (language_version, dependencies_with_flags, abspath_lock_config, registry_remotes) in - Logging.show_package_dependency_before_solving dependencies_with_flags; + Logging.show_package_dependency_before_solving display_config dependencies_with_flags; (* Collects the local fixed packages used by the target: *) let* (local_fixed_package_map, registry_remotes_sub) = @@ -369,7 +400,7 @@ let solve ~(fpath_in : string) = EnvelopeConfig.write abspath_envelope_config { envelope_contents } |> Result.map_error (fun message -> FailedToWriteFile{ path = abspath_envelope_config; message }) in - Logging.end_envelope_config_output abspath_envelope_config; + Logging.end_envelope_config_output display_config abspath_envelope_config; return (local_fixed_dependencies |> LocalFixedPackageIdMap.add absdir_package deps) ) local_fixed_package_map (return LocalFixedPackageIdMap.empty) in @@ -456,7 +487,7 @@ let solve ~(fpath_in : string) = | Some(solutions) -> - Logging.show_package_dependency_solutions solutions; + Logging.show_package_dependency_solutions display_config solutions; let (lock_config, impl_specs) = convert_solutions_to_lock_config @@ -474,7 +505,7 @@ let solve ~(fpath_in : string) = ) () in let* () = LockConfig.write abspath_lock_config lock_config in - Logging.end_lock_config_output abspath_lock_config; + Logging.end_lock_config_output display_config abspath_lock_config; return () end in @@ -626,9 +657,11 @@ let build let res = let open ResultMonad in + let absdir_current = AbsPathIo.getcwd () in + let display_config = make_display_config ~show_full_path ~verbosity ~current_dir:absdir_current in + (* Constructs the input: *) let build_input = - let absdir_current = AbsPathIo.getcwd () in let abspath_in = AbsPath.make_absolute_if_relative ~origin:absdir_current fpath_in in if AbsPathIo.is_directory abspath_in then let options = @@ -717,7 +750,7 @@ let build let deps_config = make_deps_config ~store_root:absdir_store_root lock_config in ShellCommand.mkdir_p absdir_intermediate; let* () = DepsConfig.write abspath_deps_config deps_config in - Logging.end_deps_config_output abspath_deps_config; + Logging.end_deps_config_output display_config abspath_deps_config; (* Builds the package by invoking `satysfi`: *) let SatysfiCommand.{ exit_status; command = _ } = @@ -766,7 +799,7 @@ let build let deps_config = make_deps_config ~store_root:absdir_store_root lock_config in ShellCommand.mkdir_p absdir_intermediate; let* () = DepsConfig.write abspath_deps_config deps_config in - Logging.end_deps_config_output abspath_deps_config; + Logging.end_deps_config_output display_config abspath_deps_config; (* Builds the document by invoking `satysfi`: *) let SatysfiCommand.{ exit_status; command = _ } = @@ -804,8 +837,10 @@ let test let res = let open ResultMonad in + let absdir_current = AbsPathIo.getcwd () in + let display_config = make_display_config ~show_full_path ~verbosity ~current_dir:absdir_current in + let* test_input = - let absdir_current = AbsPathIo.getcwd () in let abspath_in = AbsPath.make_absolute_if_relative ~origin:absdir_current fpath_in in if AbsPathIo.is_directory abspath_in then let options = @@ -862,7 +897,7 @@ let test let deps_config = make_deps_config ~store_root:absdir_store_root lock_config in ShellCommand.mkdir_p absdir_intermediate; let* () = DepsConfig.write abspath_deps_config deps_config in - Logging.end_deps_config_output abspath_deps_config; + Logging.end_deps_config_output display_config abspath_deps_config; (* Builds the package by invoking `satysfi`: *) let SatysfiCommand.{ exit_status; command = _ } = diff --git a/src-saphe/sapheMain.mli b/src-saphe/sapheMain.mli index b5cc7df2f..bda032ca9 100644 --- a/src-saphe/sapheMain.mli +++ b/src-saphe/sapheMain.mli @@ -5,7 +5,11 @@ val init_document : fpath_in:string -> unit val init_library : fpath_in:string -> unit -val solve : fpath_in:string -> unit +val solve : + fpath_in:string -> + show_full_path:bool -> + verbosity:Verbosity.t -> + unit val update : fpath_in:string -> unit diff --git a/src/frontend/logging.ml b/src/frontend/logging.ml index 45c1f9491..18ee8a7d4 100644 --- a/src/frontend/logging.ml +++ b/src/frontend/logging.ml @@ -1,31 +1,16 @@ open MyUtil +open CommonUtil -type path_display_setting = - | FullPath - | RelativeToCwd of abs_path - type config = { path_display_setting : path_display_setting; verbosity : Verbosity.t; } -let show_path (config : config) (abspath : abs_path) = - match config.path_display_setting with - | FullPath -> AbsPath.to_string abspath - | RelativeToCwd(abspath_cwd) -> AbsPath.make_relative ~from:abspath_cwd abspath - - -let is_verbose = function - | Verbosity.Verbose -> true - | _ -> false - - -let is_not_quiet = function - | Verbosity.Quiet -> false - | _ -> true +let show_path (config : config) = + display_path config.path_display_setting let begin_to_typecheck_file (config : config) (abspath_in : abs_path) = diff --git a/src/frontend/logging.mli b/src/frontend/logging.mli index 411776f4f..eb86a4949 100644 --- a/src/frontend/logging.mli +++ b/src/frontend/logging.mli @@ -1,9 +1,6 @@ open MyUtil - -type path_display_setting = - | FullPath - | RelativeToCwd of abs_path +open CommonUtil type config = { path_display_setting : path_display_setting; diff --git a/src/frontend/main.ml b/src/frontend/main.ml index 9aab668dd..a3147779b 100644 --- a/src/frontend/main.ml +++ b/src/frontend/main.ml @@ -1,5 +1,6 @@ open MyUtil +open CommonUtil open EnvelopeSystemBase open ErrorReporting open Types @@ -154,9 +155,9 @@ let make_output_mode text_mode_formats_str_opt = let make_display_config ~(show_full_path : bool) ~(verbosity : Verbosity.t) ~current_dir:(absdir_current : abs_path) = let path_display_setting = if show_full_path then - Logging.FullPath + FullPath else - Logging.RelativeToCwd(absdir_current) + RelativeToCwd(absdir_current) in Logging.{ path_display_setting; verbosity }