123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687(*********************************************************************************)(* Dunolint - A tool to lint and help manage files in dune projects *)(* Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)(* *)(* This file is part of Dunolint. *)(* *)(* Dunolint 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 3 of the License, or any later *)(* version, with the LGPL-3.0 Linking Exception. *)(* *)(* Dunolint 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 GNU Lesser General Public License *)(* and the file `NOTICE.md` at the root of this repository for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* and the LGPL-3.0 Linking Exception along with this library. If not, see *)(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)(*********************************************************************************)letsrc=Logs.Src.create"dunolint"~doc:"dunolint"moduleLoad_result=structtypet=|Absent|PresentofDunolint.Config.t|ErrorofErr.tendtypet=Load_result.tHashtbl.M(Relative_path).tletcreate():t=Hashtbl.create(moduleRelative_path)letload_config_in_dir(t:t)~dir:Load_result.t=letconfig_path=Relative_path.extenddir(Fsegment.v"dunolint")inmatchHashtbl.findtconfig_pathwith|Someresult->result|None->letresult:Load_result.t=matchmatch(Unix.stat(Relative_path.to_stringconfig_path)).st_kindwith|exceptionUnix.Unix_error(ENOENT,_,_)->`Absent|file_kind->(match[@coverageoff]file_kindwith|S_REG|S_LNK->`Present|S_DIR|S_CHR|S_BLK|S_FIFO|S_SOCK->`Not_a_file)with|`Absent|`Not_a_file->Log.debug~src(fun()->Pp.O.[Pp.text"Config file does not exist at "++Pp_tty.path(moduleRelative_path)config_path++Pp.text"."]);Absent|`Present->(tryletconfig=Dunolinter.Config_handler.load_config_exn~filename:(Relative_path.to_stringconfig_path)inLog.info~src(fun()->Pp.O.[Pp.text"Loaded dunolint config from "++Pp_tty.path(moduleRelative_path)config_path++Pp.text"."]);Presentconfigwith|Err.Eerr->Errorerr|exn->(leterr=Err.createPp.O.[Pp.textf"Failed to load config at "++Pp_tty.path(moduleRelative_path)config_path++Pp.text".";Err.exnexn]inErrorerr)[@coverageoff])inHashtbl.sett~key:config_path~data:result;result;;