Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file DebianFormats.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458(******************************************************************************)(* ocaml-debian-formats: parse Debian files. *)(* *)(* Copyright (C) 2010-2017, Sylvain Le Gall *)(* *)(* This library is free software; you can redistribute it and/or modify it *)(* under the terms of the GNU Lesser General Public License as published by *)(* the Free Software Foundation; either version 2.1 of the License, or (at *)(* your option) any later version, with the OCaml static compilation *)(* exception. *)(* *)(* This library is distributed in the hope that it will be useful, but *)(* WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *)(* COPYING for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this library; if not, write to the Free Software Foundation, *)(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *)(******************************************************************************)openDF822openExtLibopenDFUtilstypename=stringtypeversion=stringtypevpkg=string*(string*string)optiontypeveqpkg=string*(string*string)optiontypearchitecture=stringtypemd5sum=Digest.ttypesha1=stringtypesha256=stringtypefile_size=int64typefilename=string(**/**)letdefaultdfltf1f2fld=tryf1f2fldwithNot_found->dflt(**/**)moduleVersion=structletnoepochver=trysnd(String.splitver":")withInvalid_string->verletupstreamver=tryfst(String.split(noepochver)"-")withInvalid_string->verletis_nativever=String.containsver'-'endmoduleRelease=structtypet={origin:string;label:string;suite:string;version:string;codename:string;date:string;architecture:string;component:string;description:string;md5sums:(md5sum*file_size*string)list;sha1:(sha1*file_size*string)list;sha256:(sha256*file_size*string)list;}letparsech=letparse_release_fieldspar=letparsefield=trysingle_linefield(List.assocfieldpar)withNot_found->""in{origin=parse"origin";label=parse"label";suite=parse"suite";version=parse"version";codename=parse"codename";date=parse"date";architecture=parse"architecture";component=parse"component";description=parse"description";md5sums=[];sha1=[];sha256=[];}inmatchparse_paragraph(start_from_channelch)with|None->raiseNot_found|Somepar->parse_release_fieldsparendmoduleSource=structtypet={name:name;version:version;binary:vpkglist;build_depends:(vpkg*(bool*architecture)list)listlist;build_depends_indep:(vpkg*(bool*architecture)list)listlist;build_conflicts:(vpkg*(bool*architecture)list)list;build_conflicts_indep:(vpkg*(bool*architecture)list)list;architecture:architecturelist;md5sums:(md5sum*file_size*filename)list;sha1:(sha1*file_size*filename)list;sha256:(sha256*file_size*filename)list;directory:filename;section:string;}letparse_name=parse_packageletparse_archs=List.filter((<>)"")(String.nsplits" ")letparse_versions=parse_versionsletparse_binarys=parse_vpkglistparse_constrsletparse_cnfs=parse_vpkgformulaparse_builddepssletparse_conjs=parse_vpkglistparse_builddepssletparse_cksumlst=List.fold_left(funaccline->matchList.filter((<>)"")(String.nsplitline" ")with|cksum::sz::tl->(cksum,Int64.of_stringsz,String.concat" "tl)::acc|_->acc)[](List.revlst)(* Relationships between source and binary packages
* http://www.debian.org/doc/debian-policy/ch-relationships.html
* Build-Depends, Build-Depends-Indep, Build-Conflicts, Build-Conflicts-Indep
*)letparse_sources_fieldspar=letparse_sffield=f(single_linefield(List.assocfieldpar))inletparse_mffield=f(String.concat" "(List.assocfieldpar))inletparse_lffield=f(List.assocfieldpar)inletexec()={name=parse_sparse_name"package";version=parse_sparse_version"version";architecture=parse_sparse_arch"architecture";binary=default[]parse_mparse_binary"binary";build_depends=default[]parse_mparse_cnf"build-depends";build_depends_indep=default[]parse_mparse_cnf"build-depends-indep";build_conflicts=default[]parse_mparse_conj"build-conflicts";build_conflicts_indep=default[]parse_mparse_conj"build-conflicts-indep";md5sums=default[]parse_lparse_cksum"files";sha1=default[]parse_lparse_cksum"checksums-sha1";sha256=default[]parse_lparse_cksum"checksums-sha256";directory=parse_s(funs->String.strips)"directory";section=parse_s(funs->String.strips)"section";}intrySome(exec())withNot_found->None(* this package doesn't either have version, arch or name *)(** parse a debian Sources file from channel *)letparsefch=letparse_packages=parse_822_iterparse_sources_fieldsinparse_packagesf(start_from_channelch)letfilenametft=lettest=matchftwith|`Dsc->funs->String.ends_withs".dsc"|`Tarball->funs->(not(String.ends_withs".debian.tar.gz"||String.ends_withs".debian.tar.bz2"))&&(String.ends_withs".tar.gz"||String.ends_withs".tar.bz2")|`Diff->funs->String.ends_withs".diff.gz"||String.ends_withs".debian.tar.gz"||String.ends_withs".debian.tar.bz2"|`Otherfn->(=)fninletmd5sum,sz,fn=List.find(fun(_,_,fn)->testfn)t.md5sumsinletfindaccffld=tryletdigest,_,_=List.find(fun(_,_,fn')->fn=fn')fldinfdigest::accwithNot_found->accinletdigests=[`MD5Summd5sum]inletdigests=finddigests(fund->`Sha1d)t.sha1inletdigests=finddigests(fund->`Sha256d)t.sha256in(fn,sz,digests)endmoduleBinary=structtypet={name:name;version:version;essential:bool;source:name*versionoption;depends:vpkglistlist;pre_depends:vpkglistlist;recommends:vpkglistlist;suggests:vpkglist;enhances:vpkglist;conflicts:vpkglist;breaks:vpkglist;replaces:vpkglist;provides:veqpkglist;extras:(string*string)list;}(** debian package format *)letparse_name=parse_packageletparse_vpkg=parse_constrletparse_veqpkg=parse_constrletparse_conjs=parse_vpkglistparse_vpkgsletparse_cnfs=parse_vpkgformulaparse_vpkgsletparse_provs=parse_veqpkglistparse_veqpkgsletparse_essential=function|"Yes"|"yes"->true|"No"|"no"->false(* this one usually is not there *)|_->assertfalse(* unreachable ?? *)letparse_packages_fieldsextraspar=letextras="status"::extrasinletparse_sffield=f(single_linefield(List.assocfieldpar))inletparse_mffield=f(String.concat" "(List.assocfieldpar))inletparse_eextras=List.filter_map(funprop->letprop=String.lowercasepropintrySome(prop,single_lineprop(List.assocproppar))withNot_found->None)extrasinletexec()={name=parse_sparse_name"package";version=parse_sparse_version"version";essential=defaultfalseparse_sparse_essential"essential";source=default("",None)parse_sparse_source"source";depends=default[]parse_mparse_cnf"depends";pre_depends=default[]parse_mparse_cnf"pre-depends";recommends=default[]parse_mparse_cnf"recommends";suggests=default[]parse_mparse_conj"suggests";enhances=default[]parse_mparse_conj"enhances";conflicts=default[]parse_mparse_conj"conflicts";breaks=default[]parse_mparse_conj"breaks";replaces=default[]parse_mparse_conj"replaces";provides=default[]parse_mparse_prov"provides";extras=parse_eextras;}in(* this package doesn't either have version or name *)trySome(exec())withNot_found->None(** parse a debian Packages file from the channel [ch] *)letparse?(extras=[])fch=letparse_packages=parse_822_iter(parse_packages_fieldsextras)inparse_packagesf(start_from_channelch)endmoduleControl=structtypesource_section={source:name;section:name;priority:name;maintainer:string;uploaders:stringlist;standards_version:version;build_depends:(vpkg*(bool*architecture)list)listlist;build_depends_indep:(vpkg*(bool*architecture)list)listlist;build_conflicts:(vpkg*(bool*architecture)list)list;build_conflicts_indep:(vpkg*(bool*architecture)list)list;}(** debian source section format *)typebinary_section={package:name;essential:bool;depends:vpkglistlist;pre_depends:vpkglistlist;recommends:vpkglistlist;suggests:vpkglist;enhances:vpkglist;conflicts:vpkglist;breaks:vpkglist;replaces:vpkglist;provides:veqpkglist;extras:(string*string)list;}(** debian binary sections format *)typet=source_section*binary_sectionlistletparse_name=parse_packageletparse_vpkg=parse_virtual_constrletparse_veqpkg=parse_virtual_constrletparse_conjs=parse_vpkglistparse_vpkgsletparse_essential=function|"Yes"|"yes"->true|"No"|"no"->false(* this one usually is not there *)|_->assertfalse(* unreachable ?? *)letparse_source_fieldspar=letparse_cnfs=parse_vpkgformulaparse_builddepssinletparse_conjs=parse_vpkglistparse_builddepssinletparse_sffield=tryf(single_linefield(List.assocfieldpar))withNot_found->failwith(Printf.sprintf"cannot find single line field %S"field)inletparse_mffield=f(String.concat" "(List.assocfieldpar))inletexec()={source=parse_sparse_name"source";section=parse_sparse_name"section";(* TODO: be more precise *)priority=parse_sparse_name"priority";(* TODO: more precise *)maintainer="";(* TODO *)uploaders=[];(* TODO *)standards_version=parse_sparse_version"standards-version";build_depends=default[]parse_mparse_cnf"build-depends";build_depends_indep=default[]parse_mparse_cnf"build-depends-indep";build_conflicts=default[]parse_mparse_conj"build-conflicts";build_conflicts_indep=default[]parse_mparse_conj"build-conflicts-indep";}inSome(exec())letparse_binary_fieldsextraspar=letextras="status"::extrasinletparse_sffield=f(single_linefield(List.assocfieldpar))inletparse_mffield=f(String.concat" "(List.assocfieldpar))inletparse_cnfs=parse_vpkgformulaparse_vpkgsinletparse_provs=parse_veqpkglistparse_veqpkgsinletparse_eextras=List.filter_map(funprop->letprop=String.lowercasepropintrySome(prop,single_lineprop(List.assocproppar))withNot_found->None)extrasinletexec()={package=parse_sparse_name"package";essential=defaultfalseparse_sparse_essential"essential";(* TODO: handle ${ ... } *)depends=(trydefault[]parse_mparse_cnf"depends"with_->[]);pre_depends=default[]parse_mparse_cnf"pre-depends";recommends=default[]parse_mparse_cnf"recommends";suggests=default[]parse_mparse_conj"suggests";enhances=default[]parse_mparse_conj"enhances";conflicts=default[]parse_mparse_conj"conflicts";breaks=default[]parse_mparse_conj"breaks";replaces=default[]parse_mparse_conj"replaces";(* TODO: handle ${ ... } *)provides=(trydefault[]parse_mparse_prov"provides"with_->[]);extras=parse_eextras;}in(* this package doesn't either have version or name *)trySome(exec())withNot_found->Noneletparsechn=letch=start_from_channelchninletsrc=matchparse_paragraphchwith|Somepar->(matchparse_source_fieldsparwith|Somesrc->src|None->failwith"Malformed source package")|None->failwith"No source package"inletbinaries=parse_822_iter(parse_binary_fields[])(funs->s)chin(src,binaries)letfilename=Filename.concat"debian""control"letdefault()=with_fnfilenameparseendmoduleChangelog=DFChangelogmoduleWatch=DFWatchmoduleURI=structtypeuri=stringtypemirror=uritypedist=stringtypesection=[`Main|`Contrib|`NonFree](**/**)letconcaturi1uri2=match(String.ends_withuri1"/",String.starts_withuri2"/")with|true,true->uri1^String.lchopuri2|false,true|true,false->uri1^uri2|false,false->uri1^"/"^uri2letrecconcat_lst=function|uri1::uri2::tl->concat_lst(concaturi1uri2::tl)|[uri]->uri|[]->""letstring_of_section=function|`Main->"main"|`Contrib->"contrib"|`NonFree->"non-free"(**/**)letsourcesmirrordistsection=concat_lst[mirror;"dists";dist;string_of_sectionsection;"source/Sources.bz2";]letpoolmirrorsrcfn=concat_lst[mirror;src.Source.directory;fn]end