123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208(* Copyright (c) 2017 Anil Madhavapeddy <anil@recoil.org>
*
* 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.
*
*)typet={major:int;minor:int;patch:intoption;extra:stringoption}letv?patch?extramajorminor={major;minor;patch;extra}letmajor{major;_}=majorletminor{minor;_}=minorletpatch{patch;_}=patchletextra{extra;_}=extraletto_string?(sep='+')=function|{major;minor;patch=None;extra=None}->Printf.sprintf"%d.%02d"majorminor|{major;minor;patch=Somepatch;extra=None}->Printf.sprintf"%d.%02d.%d"majorminorpatch|{major;minor;patch=Somepatch;extra=Someextra}->Printf.sprintf"%d.%02d.%d%c%s"majorminorpatchsepextra|{major;minor;patch=None;extra=Someextra}->Printf.sprintf"%d.%02d%c%s"majorminorsepextraletparses=tryScanf.sscanfs"%d.%d.%d+%s"(funmajorminorpatchextra->v~patch~extramajorminor)withEnd_of_file|Scanf.Scan_failure_->begintryScanf.sscanfs"%d.%d+%s"(funmajorminorextra->v~extramajorminor)withEnd_of_file|Scanf.Scan_failure_->begintryScanf.sscanfs"%d.%d.%d"(funmajorminorpatch->v~patchmajorminor)withEnd_of_file|Scanf.Scan_failure_->beginScanf.sscanfs"%d.%d"(funmajorminor->vmajorminor)endendendletof_strings=tryOk(parses)with|_->Error(`Msg(Printf.sprintf"Unable to parse OCaml version '%s'"s))letof_string_exns=tryparseswith|_->raise(Invalid_argument(Printf.sprintf"Unable to parse OCaml version '%s'"s))letppppfv=Format.pp_print_stringppf(to_stringv)let(++)xfn=matchxwith|0->fn()|r->rletcompare{major;minor;patch;extra}a=comparemajora.major++fun()->compareminora.minor++fun()->comparepatcha.patch++fun()->compareextraa.extraletsys_version=of_string_exnSys.ocaml_versionletwith_varianttextra={twithextra}letwith_patchtpatch={twithpatch}letwithout_patcht={twithpatch=None}moduleReleases=structletv4_00_0=of_string_exn"4.00.0"letv4_00_1=of_string_exn"4.00.1"letv4_00=v4_00_1letv4_01_0=of_string_exn"4.01.0"letv4_01=v4_01_0letv4_02_0=of_string_exn"4.02.0"letv4_02_1=of_string_exn"4.02.1"letv4_02_2=of_string_exn"4.02.2"letv4_02_3=of_string_exn"4.02.3"letv4_02=v4_02_3letv4_03_0=of_string_exn"4.03.0"letv4_03=v4_03_0letv4_04_0=of_string_exn"4.04.0"letv4_04_1=of_string_exn"4.04.1"letv4_04_2=of_string_exn"4.04.2"letv4_04=v4_04_2letv4_05_0=of_string_exn"4.05.0"letv4_05=v4_05_0letv4_06_0=of_string_exn"4.06.0"letv4_06_1=of_string_exn"4.06.1"letv4_06=v4_06_1letv4_07_0=of_string_exn"4.07.0"letv4_07=v4_07_0letv4_08_0=of_string_exn"4.08.0"letv4_08=v4_08_0letall_patches=[v4_00_1;v4_01_0;v4_02_0;v4_02_1;v4_02_2;v4_02_3;v4_03_0;v4_04_0;v4_04_1;v4_04_2;v4_05_0;v4_06_0;v4_06_1;v4_07_0;v4_08_0]letall=[v4_00;v4_01;v4_02;v4_03;v4_04;v4_05;v4_06;v4_07;v4_08]letrecent=[v4_03;v4_04;v4_05;v4_06;v4_07]letlatest=v4_06letdev=[v4_08]letrecent_with_dev=List.concat[recent;dev]endtypearch=[`X86_64|`Aarch64|`Ppc64le]letarches=[`X86_64;`Aarch64;`Ppc64le]letstring_of_arch=function|`Aarch64->"arm64"|`X86_64->"amd64"|`Ppc64le->"ppc64le"letarch_of_string=function|"arm64"|"aarch64"->Ok`Aarch64|"amd64"|"x86_64"->Ok`X86_64|"ppc64le"->Ok`Ppc64le|arch->Error(`Msg("Unknown architecture "^arch))letarch_of_string_exna=matcharch_of_stringawith|Oka->a|Error(`Msgm)->raise(Invalid_argumentm)moduleSince=structletbytes=Releases.v4_03_0letarch(a:arch)=matchawith|`Aarch64->Releases.v4_05_0|`Ppc64le->Releases.v4_06_0|`X86_64->Releases.v4_00_0(* TODO obviously earlier *)endmoduleHas=structletbytesv=matchcompareSince.bytesvwith|(-1)|0->true|_->falseletarch(a:arch)v=matchcompare(Since.archa)vwith|(-1)|0->true|_->falseendmoduleOpam=structletvariants{major;minor;_}=matchmajor,minorwith|4,8->["trunk";"trunk+afl";"trunk+flambda"]|4,7->["beta2";"beta2+afl";"beta2+flambda";"beta2+default-unsafe-string"]|4,6->["afl";"flambda";"default-unsafe-string";"force-safe-string"]|4,5->["afl";"flambda"]|4,4->["flambda"]|4,3->["flambda"]|_->[]letdefault_variant{major;minor;_}=matchmajor,minorwith|4,8->Some"trunk"|4,7->Some"beta2"|4,6->None|4,5->None|4,4->None|4,3->None|_->Noneletdefault_switcht={twithextra=default_variantt}letswitchest=matchdefault_varianttwith|None->{twithextra=None}::(List.map(fune->{twithextra=Somee})(variantst))|Some_->List.map(fune->{twithextra=Somee})(variantst)letvariant_switchest=letdefault_variant=default_varianttinswitchest|>List.filter(fun{extra;_}->extra<>default_variant)moduleV2=structletpackaget=matcht.extrawith|None->"ocaml-base-compiler."^(to_stringt)|Some_->"ocaml-variants."^(to_stringt)endend