Repository navigation
Conversation
|
I'm a bit worried by the implication of this patch in terms of maintainability. I don't know how it's going to interact when we start switching to proper namespaces either. There is another solution that gives the same power to the user and I think would fit better in the current design: instead of looking for modules in arbitrary directories, we could simply bring them to the directory of the library. You could do this right now: (rule
((targets (foo.ml))
(deps (subdir/foo.ml))
(action (copy_and_add_line_directive ${<} ${@}))))It is painful if you have to setup rules for 140 files, but we could add something to make it easier: (copy_files_here_and_add_line_directives (subdir/*.ml))There are a few things to be careful about, but it should be less invasive and should cover more cases. |
I don't know what are proper namespaces (Leo's ideas?), so it could indeed interact badly. But I though that the main question was more after installation (.cmi, .cmo) than before.
It's an interesting solution and it explicits the implicit intent of the proposition "consider all the directories as one". But it seems to lost too much information. For example the configuration of the source directory of merlin Many project use directory to order files even if they are in the same namespace, why3 is another example. |
It is just a generalization of |
Yeah that's @lpw25 proposal I'm still not convinced we need to add more special concepts to support this case now. Some time ago we setup the build of the OCaml compiler with jbuilder for some specific usage. The compiler does the same thing and yet it was trivial to setup the build with jbuilder, even before If you can convert a library split into several directories into several libraries, this means that the various sub-directories are closed, and you gain nothing by trying to regroup everything into the same build stanza. I agree that the need to add these opens is a bit annoying, but hopefully this is something that can be improved in the future when we get proper namespaces. Moreover there are simple workarounds in the meantime. For instance you can add an and then you open this module in every file, either manually or with |
|
I think I want to far in this branch, sorry, I will create new MR but perhaps you can already tell me if you think these modifications are interesting:
Now the collapsing is done directly in |
Sure. I didn't read the patch in this feature, so I just commenting on the feature themselves. They should be split into several PRs so that review is easier.
I'd have to see the PR to understand better what it means.
This looks good to me, I welcome these features!
I'm not sure I follow this change, I'd have to see the patch
Before doing anymore work in this direction, can you try the method I described to see what are the limitations? I'm not ready to commit into maintaining a complex feature like this, especially if it's not future proof and reasonable workarounds exist. |
Ok I will do that.
Ok. |
|
I gave a quick try to the solution of adding rules to copy the .ml/.mli and adding line directives. I did this manually by writing some If you are still interested in this, this seem to me like the most straightforward solution. Moreover it will work out of the box when we have the bridge with jenga. Technically, we would need a stanza like this: which would setup the copy rules and add the right lines to the |
|
Thank you for looking into it yourself.
In case of error in the ml file do you go to the right file ? Should the copy rule add a preprocessor pragma ? Or should the filenames be converted back in the command output ? |
yes
The copy rule should add a pragma. This is the jbuild I used for the experiment: (library
((name plop)
))
(rule
((targets (bidule.mli))
(deps (a/b/c/bidule.mli))
(action (copy-and-add-line-directive ${<} ${@}))))
(rule
((targets (bidule.ml))
(deps (a/b/c/bidule.ml))
(action (copy-and-add-line-directive ${<} ${@}))))
(rule
((targets (lex.ml))
(deps (a/b/c/lex.ml))
(action (copy-and-add-line-directive ${<} ${@})))) |
|
Sorry for the intermediate closing (I pushed a reset of master branch...). The branch now contains an implementation of your proposition. Except perhaps it copies and add preprocessing information to all the files not just ocaml modules. I think it is better to not single out The name of the new rule should perhaps be changed in |
|
I initially suggested to copy only the .ml/.mli files for the following reasons:
I don't mind too much going the route of copying everything, but we should be consistent with the forms available in actions for copying files. Currently there are two forms available:
So we should be consistent with that. We could have two different stanzas that take globs: (copy_files a/b/*.bin)
(copy_files_and_add_lines_directives a/b/*.{ml,mli})Regarding the implementation, there is currently an unwritten invariant about However, if we reject source directories that aren't descendant, then we can just make sure that we visit the children before the parents. |
Ok, I'm going to do that.
I think jbuild work well because you have to do things a certain way, I don't want to push it more out of its track 🛤️ I think it is a good and natural property to have. |
|
Cool, BTW |
I think I will not relax this limitation for |
|
I also have a plan to build jbuilder projects with jenga, and jenga has the same limitation. So I'd rather keep it for now |
|
Why "copy-..." in action and "copy_" in rule name? |
|
I guess because except for actions everything uses underscores. But I don't really mind, if you prefer The reason for using underscores in some places and dashes in other is more historical than anything else. Initially most of the jbuild syntax was imported from our jenga-rules where the parser are generated by ppx_sexp_conv which dictates the use of underscore. I made up the action DSL at some point during the development of jbuilder and I thought dashes were nicer since it's what program names usually contain. |
|
Even if Can you take a new look at this MR, thank you. |
| ---------- | ||
|
|
||
| The ``copy_files`` and ``copy_files_and_add_lines_directives`` stanza | ||
| allows to specify that files in another directory could be copied to |
There was a problem hiding this comment.
shouldn't it be "from another directory"? Also why "could" rather than "will"?
There was a problem hiding this comment.
"could" because if the file is not needed it will not be copied. but I will precise and rephrase.
| copy_files | ||
| ---------- | ||
|
|
||
| The ``copy_files`` and ``copy_files_and_add_lines_directives`` stanza |
|
|
||
| The ``copy_files`` and ``copy_files_and_add_lines_directives`` stanza | ||
| allows to specify that files in another directory could be copied to | ||
| the current directory. The stanza ``copy_files#`` is a shortcut for |
There was a problem hiding this comment.
Change to: You can use copy_files# as a shorthand for ...
|
|
||
| (copy_files <glob>) | ||
|
|
||
| ``<glob>`` represent the set of files matched, see the :ref:`glob |
There was a problem hiding this comment.
--> "represents the set of files to copy"
| (copy_files <glob>) | ||
|
|
||
| ``<glob>`` represent the set of files matched, see the :ref:`glob | ||
| <glob>` for details |
|
|
||
| let copy_files_rules (def: Copy_files.t) ~src_dir ~dir ~package_context:_ = | ||
| let src_glob = SC.expand_vars sctx ~dir def.glob in | ||
| let glob_in_src = Path.relative src_dir src_glob in |
There was a problem hiding this comment.
This doesn't enforce that the path must be a sub-directory of the current directory. You could write this instead:
Path.append src_dir (Path.relative Path.root src_glob)and print a better error when Path.relative Path.root src_glob fails. Please capture the location of the glob as well so that the error is properly located.
BTW, there are many variables defined here and src_glob is used only once. I think it'd be easier to read if it was scoped accordingly:
let glob_in_src =
let src_glob = ... in
...
in| die "invalid glob in %s/jbuild: %s" (Path.to_string src_dir) msg | ||
| in | ||
| (* add rules *) | ||
| let modules = SC.sources_and_targets_known_so_far sctx ~src_path:src_in_src in |
| (file_src,file_dst) | ||
| else Action.Mini_shexp.Ast.Copy (file_src,file_dst) | ||
| in | ||
| (Build.action |
There was a problem hiding this comment.
There is already Build.copy. Let's add Build.copy_and_add_line_directive as well. This will make this code less verbose.
| let () = | ||
| (* Goes first in subdirectories *) | ||
| let subtree_smaller x y = | ||
| - (Path.compare x.SC.Dir_with_jbuild.src_dir y.SC.Dir_with_jbuild.src_dir) in |
| @@ -0,0 +1,8 @@ | |||
| (jbuild_version 1) | |||
|
|
|||
| (ocamllex (lexer1)) | |||
There was a problem hiding this comment.
It seems nicer to me if this stanza is next to the .mll. I think we should move it lexers/jbuild and change the glob to lexers/*.{ml,mli}
|
Alright, I tried this on jbuilder itself; I wanted to see if merging the vendored libraries into the main one would increase parallelism. The main issue I had is that I initially made a few typos while typing the globs and as a result nothing was happening, I was just getting errors about unknown modules, which is not very helpful. I think a glob that match nothing should be an error. |
|
BTW, @mshinwell says that you should finish your OCaml PRs 😛 |
|
(Oh! I completely missed the new comments in them..... sorry. next week) |
|
All the fixes have been done. |
|
Thanks, I want to release the 1.0.0 next week. I'll probably review non-bugfix PRs after that. |
Add (copy_files <glob>) and (copy_files# <glob>) stanzas. These stanzas setup rules for copying files from a sub-directory to the current directory. This provides a reasonable way to support multi-directory library/executables in jbuilder.
|
Ok, as discussed yesterday during the design meeting, I merged this PR. I rebased and merged it manually. I got rid of |
Fix #34
The .ml and .mli filenames are not kept as
stringbut asPath.t