123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(*
* Copyright (c) 2014 Leo White <leo@lpw25.net>
*
* 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.
*)openStdLabelsopenOr_errormoduleOdoc_compile=CompilemoduleCompile=structtypet={unit_name:string;digest:Digest.t}letnamet=t.unit_nameletdigestt=t.digestletcomparet1t2=matchString.compare(namet1)(namet2)with|0->Digest.compare(digestt1)(digestt2)|n->nendmoduleCompile_set=Set.Make(Compile)letadd_depacc=function|_,None->acc(* drop module aliases *)|unit_name,Somedigest->Compile_set.add{Compile.unit_name;digest}accletfor_compile_step_cmtaccfile=letcmt_infos=Cmt_format.read_cmt(Fs.File.to_stringfile)inList.fold_left~f:add_dep~init:acccmt_infos.Cmt_format.cmt_importsletfor_compile_step_cmi_or_cmtiaccfile=letcmi_infos=Cmi_format.read_cmi(Fs.File.to_stringfile)inList.fold_left~f:add_dep~init:acccmi_infos.Cmi_format.cmi_crcsletfor_compile_stepfiles=letset=List.fold_left~f:(funaccfile->ifFs.File.has_ext"cmt"filethenfor_compile_step_cmtaccfileelsefor_compile_step_cmi_or_cmtiaccfile)~init:Compile_set.emptyfilesinCompile_set.fold(funab->a::b)set[]moduleHash_set:sigtypetvalcreate:unit->tvaladd:t->Odoc_model.Root.t->unitvalelements:t->Odoc_model.Root.tlistend=structtypet=unitOdoc_model.Root.Hash_table.tletaddtelt=ifOdoc_model.Root.Hash_table.memteltthen()elseOdoc_model.Root.Hash_table.addtelt()letcreate()=Odoc_model.Root.Hash_table.create42letelementst=Odoc_model.Root.Hash_table.fold(funs()acc->s::acc)t[]endletdeps_of_imports~depsimports=List.iterimports~f:(funimport->matchimportwith|Odoc_model.Lang.Compilation_unit.Import.Unresolved_->()|Odoc_model.Lang.Compilation_unit.Import.Resolved(root,_)->Hash_set.adddepsroot);Ok()letdeps_of_odoc_file~depsinput=Odoc_file.loadinput>>=fununit->matchunit.contentwith|Page_content_|Source_tree_content_->Ok()(* XXX something should certainly be done here *)|Impl_contentimpl->deps_of_imports~depsimpl.Odoc_model.Lang.Implementation.imports|Unit_contentunit->deps_of_imports~depsunit.Odoc_model.Lang.Compilation_unit.importsletfor_rendering_steppkg_dir=letdeps=Hash_set.create()inletadd_deps()file=deps_of_odoc_file~depsfileinFs.Directory.fold_files_rec_result~ext:".odoc"add_deps()pkg_dir>>=fun()->Ok(Hash_set.elementsdeps)