-
Notifications
You must be signed in to change notification settings - Fork 407
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
Subsystem versioned #937
Subsystem versioned #937
Conversation
When the sub-system is defined in a jbuild file, dune should generate |
Actually I see that this is what is implemented by this PR |
src/installed_dune_file.ml
Outdated
| acc -> | ||
begin match (Sexp.Lexer.token lexbuf : Sexp.Lexer.Token.t) with | ||
| Eof -> | ||
Loc.fail (Loc.in_file (Path.to_string fname)) "%s" bad_dune_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return List.rev acc
, the error will be caught by the match loop [] with ...
.
That seems right. BTW, thinking about this again, where we read:
we could set the |
And we set it to |
src/install_rules.ml
Outdated
@@ -39,8 +39,9 @@ module Gen(P : Install_params) = struct | |||
let gen_lib_dune_file lib = | |||
SC.add_rule sctx | |||
(Build.arr (fun () -> | |||
let lang = Option.value_exn (Lib.defined_using_lang lib) in | |||
Format.asprintf "%a@." (Sexp.pp Dune) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Dune/lang/
src/installed_dune_file.ml
Outdated
in | ||
Sexp.Of_sexp.parse of_sexp | ||
(Univ_map.singleton (Syntax.key Stanza.syntax) syntax) | ||
(Io.Sexp.load ~lexer ~mode:Single fname)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't reopen the file a second time here. We need to construct a lexer
function that first return the three extracted token and then switch to the real lexer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure how to do it the way you say however. Seems like we'd need to call parser with an initial set of lexemes (the 3 lexemes that we already parsed).
What should be possible is just reading the file into a string and then constructing the lexer from_string a second time. That should cut down on the sys calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways of doing it:
first one:
let pending_tokens = ref ... in
let lexer lb =
match !pending_tokens with
| [] -> lexer lb
| x :: l -> pending_tokens := l; x
in
...
second one, which implements all the logic in one function:
let state = ref 0 in
let lexer = ref !Sexp.Lexer.token in
let lexer lb =
let token = !lexer lb in
(match !state, token with
| 0, Lparen -> state := 1
| 1, Atom (A "dune") -> state := 2
| 2, Atom (A "1") -> state := 3; lexer := Sexp.Lexer.jbuild_token
| 2, Atom (A "2") -> state := 3;
| 2, Atom (A s) -> error ()
| 3, _ -> ()
| _ -> error ());
token
in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I went for the first approach. Did not it was allowed to reuse the same state between possibly different lexer functions like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. After reading this again, it seemed to me that the second version was clearer as all the logic is more self-contained, so I rewrote it using the second version.
Jérémie Dimino <notifications@github.com> writes:
When the sub-system is defined in a jbuild file, dune should generate
`dune 1` files. Otherwise it's not going to work for the released
versions of ppx_inline_test, ppx_expect, ppxlib, etc...
Agreed. The simplification would apply to subsystems in dene files.
|
112816c
to
1438391
Compare
BTW, should we just save the whole parsing context in libraries? |
a74d978
to
5afad68
Compare
Do you see other uses for it? I'd rather have Jbuild.Library.t abstract away the parsing related details kind of like Lib.Info.t abstracts away the source of libraries when making a Lib.t. |
Sorry, this might be obtuse but isn't this done already? The X.Y in your example is a sub system version. |
Maybe when we switch to
If I read the code correctly, currently we set only |
I see, thanks for clarifiyng. Why only for dune 2 files however? We don't hide the syntax version when parsing other sexps that comes from jbuild files. |
Because in dune 1 files the version of sub-systems is set to 1.0, and |
e530192
to
8db47b2
Compare
@diml I tried doing this in my last commit. I admit that I'm not fully confident about my change however. |
12bb62b
to
ede39db
Compare
That looks fine, we just a comment in the code explaining why we do this |
ede39db
to
e441e0d
Compare
@diml added a comment |
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This will be necessary for some manual parsing Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
We read the first 3 tokens of a dune file and use it recognize if the file was generated using jbuilder or dune Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This field is necessary to know how to generate .dune files for a particular library. Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Reuse the same lexer by pushing back some tokens manually Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
…tems Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
e441e0d
to
04ee6b0
Compare
src/installed_dune_file.ml
Outdated
(match dune_version with | ||
| (0, 0) -> "1" | ||
| (1, 0) -> "2" | ||
| _ -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we should be that strict. In practice, it's likely that we'll be increasing the version of the dune language often. In version 2 files, the exact version is saved in each sub-system, so we can accept any version >= 1.0 here.
src/stanza.ml
Outdated
type t = Sexp.syntax = Jbuild | Dune | ||
|
||
let of_syntax = function | ||
| (0, 0) -> Jbuild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though we are not going to release another version of jbuilder, we should write (0, _)
here (it's slightly clearer IMO)
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
src/installed_dune_file.ml
Outdated
in | ||
Sexp.Of_sexp.parse of_sexp | ||
(Univ_map.singleton (Syntax.key Stanza.syntax) syntax) | ||
Sexp.Of_sexp.parse of_sexp Univ_map.empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you aren't passing the version in the parsing context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is passed in of_sexp
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
@diml the last commit relax the version checks I had before. |
Fix #909
This is still WIP because I should really be saving the syntax version rather than the Jbuild vs. Dune version in the Info files. But this PR is still useful for initial review.
One thing that I'm wondering about is we should still generate the per subsystem versions in syntax
(1, 0)
. Seems like jbuilder will not be able to load .dune files generated by dune anyway because of that initial 2.0 language.