123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(*
* Copyright (c) 2019 Nathan Rebours <nathan.p.rebours@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openResulttypet={base_name:string;sub_lib:stringoption}letcomparett'=letcompare_optcmpoo'=match(o,o')with|None,None->0|None,_->-1|_,None->1|Somex,Somex'->cmpxx'inlet {base_name;sub_lib}=tinlet{base_name=base_name';sub_lib=sub_lib'}=t'inmatchString.comparebase_namebase_name'with|0->compare_opt String.comparesub_libsub_lib'|c->cletequal tt'=comparett'=0letppfmt{base_name;sub_lib}=letcsts=Fmt.(conststrings)inFmt.string fmt"{ ";Fmt.(pair~sep:(cst"; ")string(option~none:(cst"None")string))fmt(base_name,sub_lib);Fmt.string fmt" }"letfrom_string s=letinvalid()=Error(Printf.sprintf"Invalid library name: %S"s)inmatchAstring.String.cuts~sep:"."swith|[""]|["";_]|[_;""]->invalid()|[base_name]->Ok{base_name;sub_lib=None}|base_name::sl->Ok{base_name;sub_lib =Some(String.concat"."sl)}|[]->(* String.cuts invariant *)assertfalsemoduleSet=structincludeSet.Make(structtypenonrec t=tletcompare=compareend)letto_package_sett=fold(funtacc->Astring.String.Set.addt.base_nameacc)tAstring.String.Set.emptyend