Skip to content

Commit

Permalink
handle language/ecosystem versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gfngfn committed Dec 27, 2023
1 parent 7017a97 commit 193416a
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 37 deletions.
5 changes: 1 addition & 4 deletions bin-saphe/configError.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type yaml_error =
| NotAnArray of YamlDecoder.context
| NotAnObject of YamlDecoder.context
| UnexpectedTag of YamlDecoder.context * string
| UnexpectedLanguage of string
| BreaksVersionRequirement of YamlDecoder.context * SemanticVersion.requirement
| NotASemanticVersion of YamlDecoder.context * string
| NotAVersionRequirement of YamlDecoder.context * string
| InvalidPackageName of YamlDecoder.context * string
Expand Down Expand Up @@ -64,9 +64,6 @@ type config_error =
depending : lock_name;
depended : lock_name;
}
(*
| CyclicLockDependency of (lock_name * untyped_package) cycle
*)
| CannotFindLibraryFile of lib_path * abs_path list
| CannotSolvePackageConstraints
(*
Expand Down
8 changes: 4 additions & 4 deletions bin-saphe/configUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ let requirement_decoder : SemanticVersion.requirement ConfigDecoder.t =
| Some(verreq) -> succeed verreq


let language_version_checker : unit ConfigDecoder.t =
let version_checker (version : SemanticVersion.t) : unit ConfigDecoder.t =
let open ConfigDecoder in
requirement_decoder >>= fun verreq ->
if Constant.current_language_version |> SemanticVersion.fulfill verreq then
requirement_decoder >>= fun requirement ->
if version |> SemanticVersion.fulfill requirement then
succeed ()
else
failure (fun _yctx -> UnexpectedLanguage(verreq |> SemanticVersion.requirement_to_string))
failure (fun yctx -> BreaksVersionRequirement(yctx, requirement))


let dependency_spec_decoder : package_dependency_spec ConfigDecoder.t =
Expand Down
5 changes: 2 additions & 3 deletions bin-saphe/constant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ open MyUtil
open PackageSystemBase


(* TODO: remove this *)
let current_language_version =
match SemanticVersion.parse "0.1.0" with
let current_ecosystem_version =
match SemanticVersion.parse "0.0.1" with
| Some(semver) -> semver
| None -> assert false

Expand Down
6 changes: 3 additions & 3 deletions bin-saphe/libraryRootConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let registry_spec_encoder (registry_hash_value, registry_remote) =

let config_decoder : t ConfigDecoder.t =
let open ConfigDecoder in
get "language" language_version_checker >>= fun () ->
get "ecosystem" (version_checker Constant.current_ecosystem_version) >>= fun () ->
get "registries" (list registry_spec_decoder) >>= fun registries ->
registries |> List.fold_left (fun res (registry_hash_value, registry_remote) ->
res >>= fun map ->
Expand All @@ -62,12 +62,12 @@ let config_decoder : t ConfigDecoder.t =


let config_encoder (library_root_config : t) : Yaml.value =
let language = SemanticVersion.(requirement_to_string (CompatibleWith(Constant.current_language_version))) in
let language = SemanticVersion.(requirement_to_string (CompatibleWith(Constant.current_ecosystem_version))) in
let registry_specs =
library_root_config.registries |> RegistryHashValueMap.bindings |> List.map registry_spec_encoder
in
`O[
("language", `String(language));
("ecosystem", `String(language));
("registries", `A(registry_specs));
]

Expand Down
4 changes: 2 additions & 2 deletions bin-saphe/lockConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let lock_encoder (lock : locked_package) : Yaml.value =

let lock_config_decoder : t ConfigDecoder.t =
let open ConfigDecoder in
get "language" language_version_checker >>= fun () ->
get "ecosystem" (version_checker Constant.current_ecosystem_version) >>= fun () ->
get_or_else "locks" (list lock_decoder) [] >>= fun locked_packages ->
succeed {
locked_packages;
Expand All @@ -81,7 +81,7 @@ let lock_config_decoder : t ConfigDecoder.t =

let lock_config_encoder (lock_config : t) : Yaml.value =
`O([
("language", `String("^0.1.0"));
("ecosystem", `String(SemanticVersion.(requirement_to_string (CompatibleWith(Constant.current_ecosystem_version)))));
("locks", `A(lock_config.locked_packages |> List.map lock_encoder));
])

Expand Down
27 changes: 20 additions & 7 deletions bin-saphe/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ let make_yaml_error_lines : yaml_error -> line list = function
| UnexpectedTag(yctx, tag) ->
[ NormalLine(Printf.sprintf "unexpected type tag '%s'%s" tag (show_yaml_context yctx)) ]

| UnexpectedLanguage(s_language_version) ->
[ NormalLine(Printf.sprintf "unexpected language version '%s'" s_language_version) ]
| BreaksVersionRequirement(yctx, requirement) ->
[ NormalLine(Printf.sprintf "breaks the requrement '%s'%s" (SemanticVersion.requirement_to_string requirement)(show_yaml_context yctx)) ]

| NotASemanticVersion(yctx, s) ->
[ NormalLine(Printf.sprintf "not a semantic version: '%s'%s" s (show_yaml_context yctx)) ]
Expand Down Expand Up @@ -511,13 +511,26 @@ let solve ~(fpath_in : string) =
(get_lib_path_string Constant.library_root_config_file))
in
let* library_root_config = LibraryRootConfig.load abspath_library_root_config in
let* (dependencies_with_flags, abspath_lock_config, registry_specs) =
let* (language_version, dependencies_with_flags, abspath_lock_config, registry_specs) =
match solve_input with
| PackageSolveInput{
root = absdir_package;
lock = abspath_lock_config;
} ->
let* PackageConfig.{ package_contents; registry_specs; _ } = PackageConfig.load absdir_package in
let*
PackageConfig.{
language_requirement;
package_contents;
registry_specs;
_
} = PackageConfig.load absdir_package
in
let language_version =
match language_requirement with
| SemanticVersion.CompatibleWith(semver) -> semver
(* Selects the minimum version according to the user's designation for the moment.
TODO: take dependencies into account when selecting a language version *)
in
begin
match package_contents with
| PackageConfig.Library{ dependencies; test_dependencies; _ } ->
Expand All @@ -526,10 +539,10 @@ let solve ~(fpath_in : string) =
(dependencies |> List.map (fun dep -> (SourceDependency, dep)))
(test_dependencies |> List.map (fun dep -> (TestOnlyDependency, dep)))
in
return (dependencies_with_flags, abspath_lock_config, registry_specs)
return (language_version, dependencies_with_flags, abspath_lock_config, registry_specs)

| PackageConfig.Font(_) ->
return ([], abspath_lock_config, registry_specs)
return (language_version, [], abspath_lock_config, registry_specs)
end

| DocumentSolveInput{
Expand Down Expand Up @@ -589,7 +602,7 @@ let solve ~(fpath_in : string) =
) registry_specs (return RegistryLocalNameMap.empty)
in

let package_context = { registries } in
let package_context = { registries; language_version } in
let solutions_opt = PackageConstraintSolver.solve package_context dependencies_with_flags in
begin
match solutions_opt with
Expand Down
14 changes: 8 additions & 6 deletions bin-saphe/packageConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ type package_contents =
}

type t = {
package_name : package_name;
package_authors : string list;
external_sources : (string * external_source) list;
package_contents : package_contents;
registry_specs : registry_remote RegistryLocalNameMap.t;
language_requirement : SemanticVersion.requirement;
package_name : package_name;
package_authors : string list;
external_sources : (string * external_source) list;
package_contents : package_contents;
registry_specs : registry_remote RegistryLocalNameMap.t;
}


Expand Down Expand Up @@ -250,7 +251,7 @@ let external_source_decoder : (string * external_source) ConfigDecoder.t =

let config_decoder : t ConfigDecoder.t =
let open ConfigDecoder in
get "language" language_version_checker >>= fun () ->
get "language" requirement_decoder >>= fun language_requirement ->
get "name" package_name_decoder >>= fun package_name ->
get "authors" (list string) >>= fun package_authors ->
get_or_else "registries" (list registry_spec_decoder) [] >>= fun registry_specs ->
Expand All @@ -264,6 +265,7 @@ let config_decoder : t ConfigDecoder.t =
succeed (map |> RegistryLocalNameMap.add registry_local_name registry_remote)
) (succeed RegistryLocalNameMap.empty) >>= fun registry_specs ->
succeed @@ {
language_requirement;
package_name;
package_authors;
external_sources;
Expand Down
11 changes: 6 additions & 5 deletions bin-saphe/packageConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ type package_contents =
}

type t = {
package_name : package_name;
package_authors : string list;
external_sources : (string * external_source) list;
package_contents : package_contents;
registry_specs : registry_remote RegistryLocalNameMap.t;
language_requirement : SemanticVersion.requirement;
package_name : package_name;
package_authors : string list;
external_sources : (string * external_source) list;
package_contents : package_contents;
registry_specs : registry_remote RegistryLocalNameMap.t;
}

val load : abs_path -> (t, config_error) result
3 changes: 1 addition & 2 deletions bin-saphe/packageConstraintSolver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ module SolverInput = struct
let impls =
impl_records |> List.filter_map (fun impl_record ->
let ImplRecord{ version; source; language_requirement; dependencies } = impl_record in
if Constant.current_language_version |> SemanticVersion.fulfill language_requirement then
(* TODO: change the condition above *)
if context.language_version |> SemanticVersion.fulfill language_requirement then
if String.equal (SemanticVersion.get_compatibility_unit version) compatibility then
let dependencies =
make_internal_dependency_from_registry registry_local_name context dependencies
Expand Down
3 changes: 2 additions & 1 deletion bin-saphe/packageSystemBase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ type registry_spec = {
}

type package_context = {
registries : registry_spec RegistryLocalNameMap.t;
language_version : SemanticVersion.t;
registries : registry_spec RegistryLocalNameMap.t;
}

type package_solution = {
Expand Down

0 comments on commit 193416a

Please sign in to comment.