Skip to content

Commit

Permalink
Add extra-files to opam files
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Sep 7, 2024
1 parent fa71f15 commit 03f3f03
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/lib/packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ let mandatory_fields case ?seed opam =
|> OpamFile.OPAM.with_descr_opt descr
|> OpamFile.OPAM.with_dev_repo dev_repo

let add_xfiles repo files opam =
let orig =
match OpamFile.OPAM.extra_files opam with
| None -> OpamFilename.Base.Map.empty
| Some xfiles ->
OpamFilename.Base.Map.of_list xfiles
in
let xfiles =
List.fold_left (fun map (file, nv) ->
let bfile =
OpamFilename.Base.of_string
(OpamFilename.remove_prefix
(OpamRepositoryPath.files repo None nv) file)
in
OpamFilename.Base.Map.add bfile
(OpamHash.compute (OpamFilename.to_string file))
map)
orig files
in
OpamFile.OPAM.with_extra_files
(OpamFilename.Base.Map.bindings xfiles)
opam

let opam nv kind path seed =
let opam = OpamFile.OPAM.create nv in
Expand Down Expand Up @@ -230,16 +252,20 @@ let write repo contents_root t =
archive
];
OpamFilename.rmdir files;
OpamFile.OPAM.write opam t.opam;
write_opt (OpamFilename.write archive) t.archive;
content_write contents_root t.nv t.contents;
if t.files <> [] then
(OpamFilename.mkdir files;
List.iter (fun (base, str, mode) ->
let file = OpamFilename.create files base in
OpamFilename.write file str;
OpamFilename.chmod file mode
) t.files)
let opamfile =
if t.files <> [] then
(OpamFilename.mkdir files;
List.fold_left (fun opam (base, str, mode) ->
let file = OpamFilename.create files base in
OpamFilename.write file str;
OpamFilename.chmod file mode;
add_xfiles repo [file, t.nv] opam)
t.opam t.files)
else t.opam
in
OpamFile.OPAM.write opam opamfile

let read_opt f file =
if OpamFilename.exists file then Some (f file)
Expand Down

0 comments on commit 03f3f03

Please # to comment.