Merge pull request #618 from rgrinberg/scope-encode

Move they '@' scope encoding to common module
This commit is contained in:
Rudi Grinberg 2018-03-15 19:09:56 +08:00 committed by GitHub
commit db55b4e880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -111,14 +111,7 @@ let gen_rules sctx components =
match components with
| [key] ->
let exe = ppx_exe sctx ~key in
let (key, lib_db) =
match String.rsplit2 key ~on:'@' with
| None ->
(key, SC.public_libs sctx)
| Some (key, scope) ->
(key, Scope.libs (SC.find_scope_by_name sctx
(Scope_info.Name.of_string scope)))
in
let (key, lib_db) = SC.Scope_key.of_string sctx key in
let names =
match key with
| "+none+" -> []
@ -183,8 +176,7 @@ let get_ppx_driver sctx ~scope pps =
let key =
match db with
| Installed | Public -> key
| Private scope_name ->
sprintf "%s@%s" key (Scope_info.Name.to_string scope_name)
| Private scope_name -> SC.Scope_key.to_string key scope_name
in
let sctx = SC.host sctx in
ppx_exe sctx ~key

View File

@ -370,6 +370,19 @@ module Pkg_version = struct
Build.vpath spec
end
module Scope_key = struct
let of_string sctx key =
match String.rsplit2 key ~on:'@' with
| None ->
(key, public_libs sctx)
| Some (key, scope) ->
( key
, Scope.libs (find_scope_by_name sctx (Scope_info.Name.of_string scope)))
let to_string key scope =
sprintf "%s@%s" key (Scope_info.Name.to_string scope)
end
let parse_bang var : bool * string =
let len = String.length var in
if len > 0 && var.[0] = '!' then

View File

@ -197,3 +197,9 @@ end
module Pkg_version : sig
val set : t -> Package.t -> (unit, string option) Build.t -> (unit, string option) Build.t
end
module Scope_key : sig
val of_string : t -> string -> string * Lib.DB.t
val to_string : string -> Scope_info.Name.t -> string
end