Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html-deps: Fix package flatness assumption. #307

Merged
merged 1 commit into from
Feb 19, 2019

Conversation

dbuenzli
Copy link
Contributor

Make html-deps look recursively in the package directory for odoc files. Before this patch it only looked at the first level of the given package directory which is not what you want in practice.

A lot of packages have a hierarchy in their install libdir (try e.g. ls $(opam var odoc:lib)). When you generate the odoc files you copycat that hierarchy. As mentioned html-deps would not lookup the hierarchy but only the first level of the hierarchy. For a package like odoc itself this would return an empty set of deps, which would then result in failures further down the pipeline.

let elts = Sys.readdir (to_string t) |> Array.to_list in
List.fold_left elts ~init:[] ~f:(fun acc elt ->
let file = File.create ~directory:t ~name:elt in
if Fpath.is_file_path file then file :: acc else acc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone wonders w.r.t. what I'm replacing with that line was absurd. Fpath works syntactically it nevers queries the OS.

html-deps now looks recursively in the package directory
for odoc files.
@lpw25
Copy link
Contributor

lpw25 commented Feb 15, 2019

When you generate the odoc files you copycat that hierarchy

Is this right? I would have expected to create a flat structure for the odoc files, the structure has no meaning for them.

@dbuenzli
Copy link
Contributor Author

Is this right? I would have expected to create a flat structure for the odoc files, the structure has no meaning for them.

The problem is that nothing prevents a package from installing a cmti file with the same name in different parts of their hierarchy.

@lpw25
Copy link
Contributor

lpw25 commented Feb 15, 2019

But IIRC then we can't generate the html for that package anyway, right?

@dbuenzli
Copy link
Contributor Author

But IIRC then we can't generate the html for that package anyway, right?

You can. See https://github.com/ocaml/odoc/blob/master/src/odoc/env.ml#L20-L35

@lpw25
Copy link
Contributor

lpw25 commented Feb 15, 2019

But don't the names of the html files for the modules collide and override each other?

@dbuenzli
Copy link
Contributor Author

dbuenzli commented Feb 15, 2019

But don't the names of the html files for the modules collide and override each other?

Maybe I don't know about the details, I'll let people who work on odoc figure it out.

I'm working this way for now in odig because real world packages do this (ocaml behind the first one) and I don't want to see it rewriting its own outputs and let it work if that happens to be fixed in the future.

In any case I don't think looking things up recursively in the directory is harmful, if you generate things flatly no cost is incurred by this patch, so I'm not sure what your objection is here. Besides you could also imagine a tool that works directly in the libdir in place, putting .odoc files alongside the other compilation objects in which case you want odoc html-deps on the package's libdir to report the appropriate outputs.

(Not that I think that odoc html-deps is a bit odd, see #274, but then maybe someone should have a closer look at the *-{deps,targets} design and bugs, which I guess might happen once the model rewrite happens).

@jonludlam
Copy link
Member

The point of that bit in Env was to not die horribly, rather than to actively support the idea that having module name clashes within a package is a good idea.

The use in OCaml itself is an interesting one - threads and vmthreads are mostly interchangable, but not quite; so we can't quite use the virtual libraries idea without a bit of rearragement. @dbuenzli - do you happen to know if this is the only clash?

@lpw25
Copy link
Contributor

lpw25 commented Feb 15, 2019

In any case I don't think looking things up recursively in the directory is harmful, if you generate things flatly no cost is incurred by this patch, so I'm not sure what your objection is here.

No objection, I was just surprised that it was needed.

@dbuenzli
Copy link
Contributor Author

@dbuenzli - do you happen to know if this is the only clash?

There are others like ptime.clock and mtime.clock but these are due to the way I implemented virtual libraries in the past (I would still allow cross unit inlining to occur --- the disadvantage being that if you wanted to make a library that depended on them, you also had to provide a variant for each of the one provided by the virtual lib you dependend on, which of course may combinatorially explode).

Regarding vmthreads note that they are on their way out.

In other words I'm not sure I arealdy saw such a second case but regardless, I'll proceed that way for the time being. It will be a single line change in odig to flatten the result in the result once these things have been thought over.

@aantron
Copy link
Contributor

aantron commented Feb 15, 2019

The code looks good, but I defer to @lpw25, @dbuenzli, @jonludlam on whether recursive scan is justified.

@dbuenzli dbuenzli merged commit b90780b into ocaml:master Feb 19, 2019
@dbuenzli
Copy link
Contributor Author

Merging this. No strong objection it seems. Also useful in build scenarios where your might want to generate your .odoc files next to the cmti files which may be in sub-dirs.

@dbuenzli dbuenzli deleted the fix-html-deps branch February 19, 2019 09:55
@trefis
Copy link
Contributor

trefis commented Feb 19, 2019

Meh.

Independently of whether people think there should be a flat structure to store odoc files or not, one thing that I don't understand is why you can't just pass the right include dirs to odoc.

Btw:

The problem is that nothing prevents a package from installing a cmti file with the same name in different parts of their hierarchy.

In a case like this I think you're introducing issue by making the search recursive. And the example of "well ocaml has such a structure" is not convincing, or rather, I see it as a good example that you shouldn't do this! For example, ocaml expects you to pass a -I +threads or -I +vmthreads.

Does this make sense or did I misunderstand what's going on here?

@dbuenzli
Copy link
Contributor Author

Independently of whether people think there should be a flat structure to store odoc files or not, one thing that I don't understand is why you can't just pass the right include dirs to odoc.

There is no include option in the odoc html-deps command. Moreover includes are usually used to denote where to look for dependencies not to denote where you should lookup the objects for which you want to report the dependencies...

Again I would have found it much more natural for html-deps to apply directly on odoc files since it would have been more precise for incremental rebuilds -- when one uses the resolved dependencies of the current html-deps with odoc html on an odoc file you have as dependencies the union of all those odoc files of the package rather than just those of the odoc file itself which is much less precise. I don't know what was the idea here, see #274 and I'm happy to change things when these things have been properly clarified.

In a case like this I think you're introducing issue by making the search recursive.

I don't think it will introduce any issue. It will just mix the dependencies of all the odoc files as html-deps does at the moment, see #274 again.

And the example of "well ocaml has such a structure" is not convincing, or rather, I see it as a good example that you shouldn't do this! For example, ocaml expects you to pass a -I +threads or -I +vmthreads.

Of course you can only link with only one of these units name. But a package may install more than one unit with the same name; if those have different documentation how do you document them ? One answer I'd be perfectly happy with would be this is illegal; but so far that's has not been the case.

@trefis
Copy link
Contributor

trefis commented Feb 19, 2019

OK so I had just forgotten how html-deps was working, that's my bad.
Thanks for reminding me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants