123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107(*
* Copyright (c) 2013-2020 Thomas Gazagnaire <thomas@gazagnaire.org>
* Copyright (c) 2013-2020 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2015-2020 Gabriel Radanne <drupyog@zoho.com>
*
* 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.
*)openAstringtypestanza=stringoptiontypet=stringlistletstanzav=Some(String.trimv)letstanzaffmt=Fmt.kstrstanzafmtletvx:t=List.fold_left(funacc->functionNone->acc|Somef->f::acc)[](List.revx)letpp_listpp=Fmt.(list~sep:(any"\n\n")pp)letppppf(t:t)=Fmt.pfppf"%a"(pp_listFmt.string)tletto_stringt=Fmt.to_to_stringppt^"\n"(* emulate the dune compact form for lists *)letcompact_list?(indent=2)fieldppfl=letall=Buffer.create1024inletline=Buffer.create70inletsep="\n"^String.v~len:indent(fun_->' ')inletfirst_char=reftrueinletfirst_line=reftrueinletflush()=Buffer.add_bufferallline;Buffer.clearline;Buffer.add_stringlinesep;first_line:=falseinList.iter(funw->letmax=if!first_linethen75-indent-String.lengthfieldelse75inletwn=String.lengthwinifwn>=40||Buffer.lengthline+wn>=maxthenflush();ifnot!first_charthenBuffer.add_charline' ';first_char:=false;Buffer.add_stringlinew)l;flush();Fmt.pfppf"%s"(Buffer.contentsall)letconfig_rule~config_ml_file~packages=letpkgs=matchpackageswith|[]->""|pkgs->letpkgs=List.fold_left(funaccpkg->letpkgs=String.Set.of_list(Package.librariespkg)inString.Set.unionpkgsacc)String.Set.emptypkgs|>String.Set.elementsinString.concat~sep:" "pkgsinletrename_config_file=letconfig_ml_file=Fpath.baseconfig_ml_fileinletext=Fpath.get_extconfig_ml_fileinletname=Fpath.rem_extconfig_ml_file|>Fpath.to_stringinifname="config"then[]else[stanzaf"(rule (copy# %s config%s))"(Fpath.to_stringconfig_ml_file)ext;]inletcontents=stanzaf{|
(executable
(name config)
(modules config)
(flags :standard -warn-error -A)
(libraries %s))
|}pkgsinv(rename_config_file@[contents])letbase~packages~config_ml_file=letdune_base=config_rule~config_ml_file~packagesinletdisable_conflicting_directories="(data_only_dirs duniverse dist)"indisable_conflicting_directories::dune_baseletbase_project=[stanza"(lang dune 2.9)"]letbase_workspace=v[stanza"(lang dune 2.9)\n(context default)"]