-
Notifications
You must be signed in to change notification settings - Fork 413
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
Symbolic Paths #744
Symbolic Paths #744
Conversation
That seems fine to me, I expected the implementation of BTW, looking at how
Before, the second class corresponded exactly to local paths, but this is no longer the case now. I think we should call this class managed paths and update the code accordingly, for instance with a |
It shouldn't. If we rely on Note that this can potentially break user jbuild files if they try to escape the build directory to access the source tree directly. |
I trid this change out locally and I think that it effectively obsoletes |
Yeah, but I think that's fine. I guess we should really be preventing the user from doing this by making sure the actions don't act on source dirs. |
OK. How about we change |
That seems fine |
Okay, so this is getting closer to completion. There's a couple of other points that I think we should handle:
Back to the point with managed vs. local. Do you think we should go ahead with this change? Internally in |
Yh, I think we need to make this change |
43b76ee
to
7a6921a
Compare
Ok, @diml this is getting close. Now the build dir is allowed to be external vs. local so it should be easy to just set it to the other thing. There are still some issues with other functions (see path.mlt), but I'm planning to fix those. |
src/stdune/path.ml
Outdated
if String.is_prefix s ~prefix:"_build" then ( | ||
Exn.code_error "in_source_tree: path is in build dir" | ||
[ "s", Sexp.To_sexp.string s ] | ||
); |
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'll get rid of these checks, they were just useful for debugging.
@diml latest is issue is with regards to configurator:
The above isn't actually necessary. |
Okay so The failure on 4.02.3 is reproducible, but I don't yet understand what's causing it and why bootstrap works on other versions. Any ideas here would be welcome. |
Maybe it's due to some change in the Unix library? |
It was just a bug on my part. The only reason it was only reproducible on 4.02.3 was because that's where we used sandboxes. |
src/stdune/path.ml
Outdated
let drop_build_dir p = | ||
match build_dir_kind (), Kind.of_string p with | ||
| Kind.External bd, Kind.External p -> | ||
let open Option.O 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.
This seems a bit fragile to me. Because we don't normalize external paths, we might miss cases here. Why do we need this exactly?
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.
If the user does something like $ jbuilder build --build-dir /foo/bar /foo/bar/baz
I'd expect the path to be resolved to a build dir.
I also think that the db file also relies on this. Though we can fix that by changing the sexp reading/writing not to erase the the constructor of Path.t
.
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.
Yes, but what if the the user does jbuilder build --build-dir /foo//bar /foo/bar/baz
?
The last two uses of |
I think it would be easier to reason about the code if we have the guarantee that exactly one of the following assertion holds:
If the user passes an absolute path for the build directory, we don't check whether it points to the source tree or not. I suggest to do the following: we implement a function similar to |
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This avoids a few conversions Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
with | ||
| Unix.Unix_error (EEXIST, _, _) -> () | ||
| Unix.Unix_error (ENOENT, _, _) -> | ||
Exn.fatalf "Cannot create external build directory %s. \ |
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 have External.mkdir_p
now, should we use it here and in Path.mkdir_p
?
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's not quite the same b/c mkdir_p would re-create the parents. What should this do when foo doesn't exist for example:
$ jbuilder build --build-dir /home/ocaml/foo/bar
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 would want foo
to be created.
src/stdune/path.ml
Outdated
(build_dir, build_dir_prefix, set_build_dir) | ||
|
||
module T : sig | ||
type t = private |
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.
Why the private
?
I used the constructor functions to help with debugging. I think I removed
those extra checks since, so we can get rid of it now.
…On Tue, May 29, 2018, 12:40 AM Jérémie Dimino ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/stdune/path.ml
<#744 (comment)>:
> @@ -490,29 +776,39 @@ let unlink_no_err t = try unlink t with _ -> ()
let build_dir_exists () = is_directory build_dir
-let ensure_build_dir_exists () = Local.mkdir_p build_dir
-
-let extend_basename t ~suffix = t ^ suffix
+let ensure_build_dir_exists () =
+ match kind build_dir with
+ | Local p -> Local.mkdir_p p
+ | External p ->
+ let p = External.to_string p in
+ try
+ Unix.mkdir p 0o777
+ with
+ | Unix.Unix_error (EEXIST, _, _) -> ()
+ | Unix.Unix_error (ENOENT, _, _) ->
+ Exn.fatalf "Cannot create external build directory %s. \
We have External.mkdir_p now, should we use it here and in Path.mkdir_p?
------------------------------
In src/stdune/path.ml
<#744 (comment)>:
> + let build_dir = lazy (
+ match !build_dir with
+ | None ->
+ Exn.code_error "build_dir: cannot use build dir before it's set" []
+ | Some build_dir -> build_dir)
+ in
+ let build_dir_prefix = lazy (
+ match !build_dir_prefix with
+ | None ->
+ Exn.code_error "build_dir: cannot use build dir before it's set" []
+ | Some prefix -> prefix)
+ in
+ (build_dir, build_dir_prefix, set_build_dir)
+
+module T : sig
+ type t = private
Why the private?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#744 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIe-1VrY2MJ-SUzG0goa0Zlh49AoIcKks5t3DZzgaJpZM4TyZwc>
.
|
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
= | ||
let build_dir = Option.value ~default:"_build" build_dir 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.
Why not put the default value in the Arg.(value ...)
?
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 think it's because the default would have to be duplciated for bootstrap, but I'm no longer sure. I agree that making the default part of the CLI is correct.
I find this confusing. If we re-enable interning, we'll need to make sure the ordering in sets preserve the natural ordering. Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
The previous name was not very clear Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
|}] | ||
|
||
(* This is not right, but kind of annoying to fix :/ *) | ||
Path.relative (r "foo") "../_build" |
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.
Previously, I tried addressing this by having logic in the in_source_tree
smart constructor to automatically change such paths to In_build_dir
. This wasn't really necessary to make the feature work, so I dropped it. In any case, I wasn't comfortable with that approach either.
@diml I've read over your changes and I welcome them all. Github doesn't let me approve since I created this PR. I approve "manually". |
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Ok, I pushed a couple of additional changes. I let you review them |
Okay, looks fine. |
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
This is in master. |
This is my attempt at porting to symbolic paths. Putting this up while this is WIP as I'm not sure I'm going in the right direction as I think you imagined this change being simpler than it's turning out for me here.
Repeating the question from slack: I'm not sure if Path.parent should escape the build dir for paths inside the build dir.