Skip to content

Commit ae0b5d9

Browse files
committed
Asset: fix marshalling to a file
The previous saving to file did not include the root first, making the loading fail. This commits also includes proper testing and completes lang_desc Signed-off-by: Paul-Elliot <[email protected]>
1 parent 9fe192f commit ae0b5d9

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/model_desc/lang_desc.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,11 @@ and source_tree_page_t =
719719
F ("digest", (fun t -> t.digest), Digest.t);
720720
F ("source_children", (fun t -> t.source_children), List identifier);
721721
]
722+
723+
and asset_t =
724+
let open Lang.Asset in
725+
Record
726+
[
727+
F ("name", (fun t -> t.name), identifier);
728+
F ("root", (fun t -> t.root), root);
729+
]

src/odoc/odoc_file.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ let save_impl file ~warnings impl =
7373
save_unit file impl.Lang.Implementation.root
7474
{ content = Impl_content impl; warnings }
7575

76+
let save_asset file ~warnings asset =
77+
let dir = Fs.File.dirname file in
78+
let base = Fs.File.(to_string @@ basename file) in
79+
let file =
80+
if Astring.String.is_prefix ~affix:"asset-" base then file
81+
else Fs.File.create ~directory:dir ~name:("asset-" ^ base)
82+
in
83+
let t = { content = Asset_content asset; warnings } in
84+
save_unit file asset.root t
85+
7686
let save_unit file ~warnings m =
7787
save_unit file m.Lang.Compilation_unit.root
7888
{ content = Unit_content m; warnings }
@@ -117,13 +127,3 @@ let load_root file =
117127
let save_index dst idx = save_ dst (fun oc -> Marshal.to_channel oc idx [])
118128

119129
let load_index file = load_ file (fun ic -> Ok (Marshal.from_channel ic))
120-
121-
let save_asset file ~warnings impl =
122-
let dir = Fs.File.dirname file in
123-
let base = Fs.File.(to_string @@ basename file) in
124-
let file =
125-
if Astring.String.is_prefix ~affix:"asset-" base then file
126-
else Fs.File.create ~directory:dir ~name:("asset-" ^ base)
127-
in
128-
let t = { content = Asset_content impl; warnings } in
129-
save_ file (fun oc -> Marshal.to_channel oc t [])

test/odoc_print/odoc_print.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ let run inp short long_paths show_canonical show_expansions
252252
| false, None, _ ->
253253
print_json_desc Lang_desc.compilation_unit_t u;
254254
Ok ())
255-
| Asset_content _ -> failwith "todo"
255+
| Asset_content a ->
256+
print_json_desc Lang_desc.asset_t a;
257+
Ok ()
256258

257259
open Compatcmdliner
258260

test/pages/new_assets.t/run.t

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
$ odoc compile-asset --name img.png --parent-id root/test --output-dir odoc
22

3-
$ ls odoc/root/test
4-
asset-img.png.odoc
3+
$ odoc_print odoc/root/test/asset-img.png.odoc
4+
{
5+
"name": {
6+
"`AssetFile": [
7+
{ "`Page": [ { "Some": { "`Page": [ "None", "root" ] } }, "test" ] },
8+
"img.png"
9+
]
10+
},
11+
"root": "<root>"
12+
}

0 commit comments

Comments
 (0)