12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182(*
* 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_errormoduleCompile=structtypet={unit_name:string;digest:Digest.t}letnamet=t.unit_nameletdigestt=t.digestendletadd_depacc=function|_,None->acc(* drop module aliases *)|unit_name,Somedigest->{Compile.unit_name;digest}::accletfor_compile_step_cmtfile=letcmt_infos=Cmt_format.read_cmt(Fs.File.to_stringfile)inList.fold_left~f:add_dep~init:[]cmt_infos.Cmt_format.cmt_importsletfor_compile_step_cmi_or_cmtifile=letcmi_infos=Cmi_format.read_cmi(Fs.File.to_stringfile)inList.fold_left~f:add_dep~init:[]cmi_infos.Cmi_format.cmi_crcsletfor_compile_stepfile=matchFs.File.has_ext"cmt"filewith|true->for_compile_step_cmtfile|false->for_compile_step_cmi_or_cmtifilemoduleHash_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_->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)