Skip to content

Tracking paths to error locations #138

Closed
ocaml/opam-repository
#23349

Description

@mmottl

My directory structure is as follows:

jbuild
jbuild-workspace
src/
  jbuild
  ...
examples/
  foo.ml
  jbuild
  ...

src contains a library and examples example applications. If I go to the examples directory and issue a build command from there (e.g. from an editor), an error in example foo.ml would be reported using location examples/foo.ml. This is a problem for inferring correct error locations. The editor does not know where the root of this path is, because we are in a (potentially even deeper) subdirectory.

Could you please print the absolute path of the root for error messages for a particular build when jbuilder is invoked so editors can infer the correct path? E.g. Vim allows you to pattern match on the build output to keep track of directory stacks for correct errors locations. A somewhat unique string should be used to correctly identify this location message, preferably an existing make-like Entering directory message that Vim or Emacs already understand.

Activity

  1. mmottl commented on Jun 12, 2017

    @mmottl
    ContributorAuthor

    Yes, something like that would work. I don't think it would be a good idea to have everybody write their own editor scripts for how jbuilder determines build roots or maybe even changes directories during build operations.

  2. bobot commented on Jun 13, 2017

    @bobot
    Contributor

    Instead of an option that should be added manually, can't jbuilder always print Entering "<absolute path>" when it is not the current directory?

    PS: I personally use projectile, where projectile-compile run the command where the .git is.

  3. mmottl commented on Jun 13, 2017

    @mmottl
    ContributorAuthor

    It's not a big deal. Various messages can coexist. You can choose your own, maybe something like jbuilder root is ....

    I'm not sure how jbuilder works, but it would certainly be necessary to never change directories if different directories are built in parallel. All paths would have to start at the root to avoid confusing editors.

  4. mmottl commented on Jun 14, 2017

    @mmottl
    ContributorAuthor

    Btw., if anybody needs a quickfix for now when building from within a subdirectory of the root, just create a Makefile containing e.g.:

    .PHONY: all
    all:
            @echo jbuilder: Entering directory \`$(abspath $(dir $(lastword $(PWD))))\'
            @jbuilder build --dev @all

    Then a simple call to make should do what you want.

  5. mmottl commented on Jun 15, 2017

    @mmottl
    ContributorAuthor

    The handling of C-files makes things more complicated then. Since you presumably build them in parallel, I guess the best way would be to only print the directory change right before emitting an error message, making sure that there is no race condition that could insert another message between the directory change message and the error message.

    I'm not sure (cd <dir> && ...) is unique enough. There may also be a chance that the S-expression pretty printer, if it's being used here, will break lines, which makes pattern matching in editors more difficult.

  6. Chris00 commented on Aug 19, 2017

    @Chris00
    Member

    The standard way of launching a build system in Emacs is M-x compile, usually bound to C-c C-c.

    Unless there is a strong motivation, it would be better to keep the sentence Entering directory '<dir>' — you can put anything you want before it but it must end the line —, otherwise editors will need to be told about it.

    Another possibility (which I'm not particularly fond of) is to invoke OCaml compilers with absolute file names, the errors will then contain the full path and links to errors will work.

  7. ghost closed this as completedin 157e4d6on Sep 22, 2017
  8. mmottl commented on Nov 26, 2017

    @mmottl
    ContributorAuthor

    jbuilder now prints directory changes, but the format does not match the patterns typically defined in Vim configurations for make. E.g. it prints:

    Entering directory '...'
    

    But most Vim errorformat configurations would expect something like the following:

    jbuilder: Entering directory `...'
    

    This would require the following changes:

    1. Print jbuilder: before Entering directory to indicate the build tool.
    2. Use a backtick to open the quoted directory (keep the regular tick at the end).

    I have updated my personal (public) OCaml Vim configuration to support both kinds of ticks, which is what other configurations do now, too. GNU make is apparently switching to saner quoting. But it would help if jbuilder stayed compatible with legacy make error formats.

  9. bobot commented on Nov 27, 2017

    @bobot
    Contributor

    But it would help if jbuilder stayed compatible with legacy make error formats.

    The format that jbuilder is currently using is the output used by gnu make since 4.0 (2013). Editors have been updated (for example four years ago for emacs).

    Even if gnu make 4.0 had been adopted slowly it is now. So I don't want jbuilder to support an old format that is deprecated.

  10. Chris00 commented on Nov 27, 2017

    @Chris00
    Member

    I agree about not supporting deprecated formats but @mmottl has a point when he says that the line is still prefixed by make: (hence, here, jbuilder:). Emacs is not sensitive to that but Vim may be.

  11. bobot commented on Nov 27, 2017

    @bobot
    Contributor

    Indeed I forget to say that I don't see any problem for the first point.

  12. 10 remaining items

  13. cpitclaudel commented on Feb 1, 2020

    @cpitclaudel
    Contributor

    Done (roughly 4 months later 🎉) in #3072

  14. added 9 commits that reference this issue on Nov 10, 2022
    e72ae5b
    8d1fcc9
    523b415
    3def666
    19d76ab
    9308f53
    14f3be6
    77a2a61
    49a75b9
  15. added a commit that references this issue on Feb 6, 2023
    4eab166
  16. added a commit that references this issue on Feb 17, 2023
    c5fc79e
  17. added this to the 3.7.0 milestone on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions