12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(*
* 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_odoc_file~depsinput=Odoc_file.loadinput>>=fununit->matchunit.contentwith|Page_content_|Source_tree_content_->Ok()(* XXX something should certainly be done here *)|Unit_contentunit->List.iterunit.Odoc_model.Lang.Compilation_unit.imports~f:(funimport->matchimportwith|Odoc_model.Lang.Compilation_unit.Import.Unresolved_->()|Odoc_model.Lang.Compilation_unit.Import.Resolved(root,_)->Hash_set.adddepsroot);Ok()letfor_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)