123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)typecompilation_mode=BuildVo|BuildVio|Vio2Vo|BuildVos|BuildVoktypet={compilation_mode:compilation_mode;compile_file:(string*bool)option(* bool is verbosity *);compilation_output_name:stringoption;vio_checking:bool;vio_tasks:(intlist*string)list;vio_files:stringlist;vio_files_j:int;echo:bool;glob_out:Dumpglob.glob_output;output_context:bool}letdefault={compilation_mode=BuildVo;compile_file=None;compilation_output_name=None;vio_checking=false;vio_tasks=[];vio_files=[];vio_files_j=0;echo=false;glob_out=Dumpglob.MultFiles;output_context=false}letdepropt=Feedback.msg_warningPp.(seq[str"Option ";stropt;str" is a noop and deprecated"])(* XXX Remove this duplication with Coqargs *)letfatal_errorexn=Topfmt.(in_phase~phase:ParsingCommandLineprint_err_exnexn);letexit_code=if(CErrors.is_anomalyexn)then129else1inexitexit_codeleterror_missing_args=prerr_endline("Error: extra argument expected after option "^s);prerr_endline"See -help for the syntax of supported options";exit1letarg_errormsg=CErrors.user_errmsgletis_dash_arguments=String.lengths>0&&s.[0]='-'letadd_compile?echocoptss=ifis_dash_argumentsthenarg_errorPp.(str"Unknown option "++strs);(* make the file name explicit; needed not to break up Coq loadpath stuff. *)letecho=Option.defaultcopts.echoechoinlets=letopenFilenameinifis_implicitsthenconcatcurrent_dir_nameselsesin{coptswithcompile_file=Some(s,echo)}letadd_compile?echocoptsv_file=matchcopts.compile_filewith|Some_->arg_errorPp.(str"More than one file to compile: "++strv_file)|None->add_compile?echocoptsv_fileletadd_vio_taskoptsf={optswithvio_tasks=f::opts.vio_tasks}letadd_vio_fileoptsf={optswithvio_files=f::opts.vio_files}letset_vio_checking_joptsoptj=try{optswithvio_files_j=int_of_stringj}withFailure_->prerr_endline("The first argument of "^opt^" must the number");prerr_endline"of concurrent workers to be used (a positive integer).";prerr_endline"Makefiles generated by coq_makefile should be called";prerr_endline"setting the J variable like in 'make vio2vo J=3'";exit1letset_compilation_modeoptsmode=matchopts.compilation_modewith|BuildVo->{optswithcompilation_mode=mode}|mode'whenmode<>mode'->prerr_endline"Options -vio and -vio2vo are exclusive";exit1|_->optsletget_task_lists=List.map(funs->tryint_of_stringswithFailure_->prerr_endline"Option -check-vio-tasks expects a comma-separated list";prerr_endline"of integers followed by a list of files";exit1)(Str.split(Str.regexp",")s)letis_not_dash_option=function|SomefwhenString.lengthf>0&&f.[0]<>'-'->true|_->falseletrecadd_vio_argspeeknextoval=ifis_not_dash_option(peek())thenletoval=add_vio_fileoval(next())inadd_vio_argspeeknextovalelseovalletwarn_deprecated_quick=CWarnings.create~name:"deprecated-quick"~category:Deprecation.Version.v8_11(fun()->Pp.strbrk"The -quick option is renamed -vio. Please consider using the -vos feature instead.")letparsearglist:t=letecho=reffalseinletargs=refarglistinletextras=ref[]inletrecparse(oval:t)=match!argswith|[]->(oval,List.rev!extras)|opt::rem->args:=rem;letnext()=match!argswith|x::rem->args:=rem;x|[]->error_missing_argoptinletpeek_next()=match!argswith|x::_->Somex|[]->Noneinletnoval:t=beginmatchoptwith(* Deprecated options *)|"-opt"|"-byte"asopt->depropt;oval|"-image"asopt->depropt;let_=next()inoval(* Non deprecated options *)|"-output-context"->{ovalwithoutput_context=true}(* Verbose == echo mode *)|"-verbose"->echo:=true;oval(* Output filename *)|"-o"->{ovalwithcompilation_output_name=Some(next())}|"-quick"->warn_deprecated_quick();set_compilation_modeovalBuildVio|"-vio"->set_compilation_modeovalBuildVio|"-vos"->Flags.load_vos_libraries:=true;{ovalwithcompilation_mode=BuildVos}|"-vok"->Flags.load_vos_libraries:=true;{ovalwithcompilation_mode=BuildVok}|"-check-vio-tasks"->lettno=get_task_list(next())inlettfile=next()inadd_vio_taskoval(tno,tfile)|"-schedule-vio-checking"->letoval={ovalwithvio_checking=true}inletoval=set_vio_checking_jovalopt(next())inletoval=add_vio_fileoval(next())inadd_vio_argspeek_nextnextoval|"-schedule-vio2vo"->letoval=set_vio_checking_jovalopt(next())inletoval=add_vio_fileoval(next())inadd_vio_argspeek_nextnextoval|"-vio2vo"->letoval=add_compile~echo:falseoval(next())inset_compilation_modeovalVio2Vo(* Glob options *)|"-no-glob"|"-noglob"->{ovalwithglob_out=Dumpglob.NoGlob}|"-dump-glob"->letfile=next()in{ovalwithglob_out=Dumpglob.Filefile}(* Rest *)|s->extras:=s::!extras;ovalendinparsenovalintryletopts,extra=parsedefaultinletargs=List.fold_leftadd_compileoptsextrainargswithany->fatal_erroranyletparseargs=letopts=parseargsin{optswithvio_tasks=List.revopts.vio_tasks;vio_files=List.revopts.vio_files}