Skip to content

Raise an error when trying to mark the current directory as vendored or data-only#3056

Merged
rgrinberg merged 1 commit intoocaml:masterfrom
voodoos:vendors-issue
Feb 9, 2020
Merged

Raise an error when trying to mark the current directory as vendored or data-only#3056
rgrinberg merged 1 commit intoocaml:masterfrom
voodoos:vendors-issue

Conversation

@voodoos
Copy link
Copy Markdown
Collaborator

@voodoos voodoos commented Jan 24, 2020

This PR add new error messages triggered when:

  • Trying to declare the current directory as data_only_dirs
  • Trying to declare the current directory as vendored_dirs

The check is quite naive and tricky globs like ../name-of-the-current-dir will not trigger it.

Fixes #3019

@voodoos voodoos requested a review from a user January 24, 2020 08:46
@voodoos voodoos requested a review from rgrinberg as a code owner January 24, 2020 08:46
Copy link
Copy Markdown
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Looks good apart from some small nits. A change entry is appropriate as well.

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Jan 24, 2020

Do you think it would be worth it to have a smarter algorithm in the is_dot helper function line 176 ?

I was considering using Build_system.eval_pred to resolve the glob and then check if the current folder is in the list.

@voodoos voodoos changed the title Vendors issue Raise an error when trying to describe the current directory as vendored or data-only Jan 24, 2020
@voodoos voodoos changed the title Raise an error when trying to describe the current directory as vendored or data-only Raise an error when trying to mark the current directory as vendored or data-only Jan 24, 2020
@rgrinberg
Copy link
Copy Markdown
Member

rgrinberg commented Jan 24, 2020

Do you think it would be worth it to have a smarter algorithm in the is_dot helper function line 176 ?

We could also disallow all path components if you'd like. In fact, I'm pretty sure we do this elsewhere when parsing globs.

I was considering using Build_system.eval_pred to resolve the glob and then check if the current folder is in the list.

Yeah, that might be a lot harder than you think. It will certainly introduce circular dependencies for example.

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Jan 24, 2020

Ok, the current PR is probably an acceptable compromise between complexity and helpfulness.

@rgrinberg
Copy link
Copy Markdown
Member

Ok, the current PR is probably an acceptable compromise between complexity and helpfulness.

Yeah, however what about sharing the validation that we have we for ignored sub dirs:

    let ignored =
      let+ l =
        enter
          (repeat
             (plain_string (fun ~loc dn ->
                  if
                    Filename.dirname dn <> Filename.current_dir_name
                    ||
                    match dn with
                    | ""
                    | "."
                    | ".." ->
                      true
                    | _ -> false
                  then
                    User_error.raise ~loc
                      [ Pp.textf "Invalid sub-directory name %S" dn ]
                  else
                    dn)))
      in
      Predicate_lang.Glob.of_string_set (String.Set.of_list l)

This prevents globs that are outside the current dir.

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Jan 27, 2020

I have the impression that this validation is too restrictive for data_only_dirs or vendored_dirs:

If I am not mistaken we want to allow:

  • Direct subdirectories: ./dataonlydirs
  • Deeper subdirectories: ./somedir/dalaonlydir

And disallow:

  • Current directory: .

Should also be disallowed (but it may not be worth the trouble):

  • Sneaky globs containing the current directory: ./somedir/../ or ../*
  • Or those pointing to a directory parent of the current directory: ..

May also be allowed:

  • Non-sub directories which are not parents of the current dir: ../dataonly

@rgrinberg
Copy link
Copy Markdown
Member

Deeper subdirectories: ./somedir/dalaonlydir

We want to allow this but I don't think this currently works. We might as well reflect this in the validation.

Should also be disallowed (but it may not be worth the trouble):

Agreed with disallowing all of this.

May also be allowed:

I don't think we should allow this either. Directories shouldn't be able to affect how rules are setup in parent or sibling directories.

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Jan 27, 2020

Deeper subdirectories: ./somedir/dalaonlydir

We want to allow this but I don't think this currently works. We might as well reflect this in the validation.

I just checked and indeed it doesn't work. It should indeed be reflected by the validation, I will start reworking the PR.

@rgrinberg
Copy link
Copy Markdown
Member

rgrinberg commented Jan 27, 2020 via email

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Feb 5, 2020

Yeah, however what about sharing the validation that we have we for ignored sub dirs:

    let ignored =
     let+ l =
       enter
         (repeat
            (plain_string (fun ~loc dn -> some_validation)))
     in
      Predicate_lang.Glob.of_string_set (String.Set.of_list l)

This prevents globs that are outside the current dir.

It also prevent * to function, in fact, if I understand well, the same result could be obtained with a simple string. Thus I cannot use it for vendored_dirs or data_only_dirs because we want to be able to vendor all subfolders with *.

I am unsure of how I could adapt the present validation to work as intended with *.

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Feb 5, 2020

I guess I can use something like that instead:

Predicate_lang.Glob.of_glob (Glob.of_string_exn loc some_string)

Will give it a try.

@voodoos voodoos requested a review from rgrinberg February 6, 2020 13:43
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
@rgrinberg rgrinberg merged commit 035c93a into ocaml:master Feb 9, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Feb 15, 2020
…lugin, dune-private-libs and dune-glob (2.3.0)

CHANGES:

- Improve validation and error handling of arguments to `dune init` (ocaml/dune#3103, fixes
  ocaml/dune#3046, @shonfeder)

- `dune init exec NAME` now uses the `NAME` argument for private modules (ocaml/dune#3103,
  fixes ocaml/dune#3088, @shonfeder)

- Avoid linear walk to detect children, this should greatly improve
  performance when a target has a large number of dependencies (ocaml/dune#2959,
  @ejgallego, @aalekseyev, @Armael)

- [coq] Add `(boot)` option to `(coq.theories)` to enable bootstrap of
  Coq's stdlib (ocaml/dune#3096, @ejgallego)

- [coq] Deprecate `public_name` field in favour of `package` (ocaml/dune#2087, @ejgallego)

- Better error reporting for "data only" and "vendored" dirs. Using these with
  anything else than a strict subdirectory or `*` will raise an error. The
  previous behavior was to just do nothing  (ocaml/dune#3056, fixes ocaml/dune#3019, @voodoos)

- Fix bootstrap on bytecode only switches on windows or where `-j1` is set.
  (ocaml/dune#3112, @xclerc, @rgrinberg)

- Allow `enabled_if` fields in `executable(s)` stanzas (ocaml/dune#3137, fixes ocaml/dune#1690
  @voodoos)

- Do not fail if `ocamldep`, `ocamlmklib`, or `ocaml` are absent. Wait for them
  to be used to fail (ocaml/dune#3138, @rgrinberg)

- Introduce a `strict_package_deps` mode that verifies that dependencies between
  packages in the workspace are specified correctly. (@rgrinberg, ocaml/dune#3117)
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Feb 15, 2020
…lugin, dune-private-libs and dune-glob (2.3.0)

CHANGES:

- Improve validation and error handling of arguments to `dune init` (ocaml/dune#3103, fixes
  ocaml/dune#3046, @shonfeder)

- `dune init exec NAME` now uses the `NAME` argument for private modules (ocaml/dune#3103,
  fixes ocaml/dune#3088, @shonfeder)

- Avoid linear walk to detect children, this should greatly improve
  performance when a target has a large number of dependencies (ocaml/dune#2959,
  @ejgallego, @aalekseyev, @Armael)

- [coq] Add `(boot)` option to `(coq.theories)` to enable bootstrap of
  Coq's stdlib (ocaml/dune#3096, @ejgallego)

- [coq] Deprecate `public_name` field in favour of `package` (ocaml/dune#2087, @ejgallego)

- Better error reporting for "data only" and "vendored" dirs. Using these with
  anything else than a strict subdirectory or `*` will raise an error. The
  previous behavior was to just do nothing  (ocaml/dune#3056, fixes ocaml/dune#3019, @voodoos)

- Fix bootstrap on bytecode only switches on windows or where `-j1` is set.
  (ocaml/dune#3112, @xclerc, @rgrinberg)

- Allow `enabled_if` fields in `executable(s)` stanzas (ocaml/dune#3137, fixes ocaml/dune#1690
  @voodoos)

- Do not fail if `ocamldep`, `ocamlmklib`, or `ocaml` are absent. Wait for them
  to be used to fail (ocaml/dune#3138, @rgrinberg)

- Introduce a `strict_package_deps` mode that verifies that dependencies between
  packages in the workspace are specified correctly. (@rgrinberg, ocaml/dune#3117)

- Make sure the `@all` alias is defined when no `dune` file is present
  in a directory (ocaml/dune#2946, fix ocaml/dune#2927, @diml)
mgree pushed a commit to mgree/opam-repository that referenced this pull request Feb 19, 2020
…lugin, dune-private-libs and dune-glob (2.3.0)

CHANGES:

- Improve validation and error handling of arguments to `dune init` (ocaml/dune#3103, fixes
  ocaml/dune#3046, @shonfeder)

- `dune init exec NAME` now uses the `NAME` argument for private modules (ocaml/dune#3103,
  fixes ocaml/dune#3088, @shonfeder)

- Avoid linear walk to detect children, this should greatly improve
  performance when a target has a large number of dependencies (ocaml/dune#2959,
  @ejgallego, @aalekseyev, @Armael)

- [coq] Add `(boot)` option to `(coq.theories)` to enable bootstrap of
  Coq's stdlib (ocaml/dune#3096, @ejgallego)

- [coq] Deprecate `public_name` field in favour of `package` (ocaml/dune#2087, @ejgallego)

- Better error reporting for "data only" and "vendored" dirs. Using these with
  anything else than a strict subdirectory or `*` will raise an error. The
  previous behavior was to just do nothing  (ocaml/dune#3056, fixes ocaml/dune#3019, @voodoos)

- Fix bootstrap on bytecode only switches on windows or where `-j1` is set.
  (ocaml/dune#3112, @xclerc, @rgrinberg)

- Allow `enabled_if` fields in `executable(s)` stanzas (ocaml/dune#3137, fixes ocaml/dune#1690
  @voodoos)

- Do not fail if `ocamldep`, `ocamlmklib`, or `ocaml` are absent. Wait for them
  to be used to fail (ocaml/dune#3138, @rgrinberg)

- Introduce a `strict_package_deps` mode that verifies that dependencies between
  packages in the workspace are specified correctly. (@rgrinberg, ocaml/dune#3117)

- Make sure the `@all` alias is defined when no `dune` file is present
  in a directory (ocaml/dune#2946, fix ocaml/dune#2927, @diml)
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.

Current directory as vendored is not working

2 participants