mohkale / projection

Projectile like project management library built on Emacs project.el
GNU General Public License v3.0
58 stars 3 forks source link

Setting projection-cmake-build-directory to nil breaks projection-commands-configure-project #12

Closed jobor closed 2 months ago

jobor commented 3 months ago

I have a CMakePresets.json with a configurePreset that sets binaryDir.

A simplified version looks like this:

{
    "version": 6,
    "configurePresets": [
        {
            "name": "base",
            "hidden": true,
            "binaryDir": "build/${presetName}"
        },
        {
            "inherits": "base",
            "name": "debug",
            "displayName": "Debug",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        }
    ]
}

Now, projection-commands-configure-project calls cmake -S . -B build --preset debug, which overrides the build directory in the preset.

The documentation of projection-cmake-build-directory suggests to set this variable to nil:

When unset no -B flag will be passed to CMake. You may want this if the build directory is configured directly in the CMakePresets or elsewhere.

However, configuration now fails with the following error and call stack:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  f-absolute-p(nil)
  f-relative-p(nil)
  f-join(nil ".cmake/api/v1/query/client-emacs-projection/query....")
  projection-cmake--file-api-create-query-file()
  projection-cmake--file-api-create-query-hook(:project (vc Git "~/dev/personal/untitled666/"))
  projection-commands--run-command-for-type((vc Git "~/dev/personal/untitled666/") "cmake -S . --preset\\=release" configure projection-commands-pre-configure-hook projection-commands-post-configure-hook)
  projection-commands-configure-project((vc Git "~/dev/personal/untitled666/") "cmake -S . --preset\\=release")
  funcall-interactively(projection-commands-configure-project (vc Git "~/dev/personal/untitled666/") "cmake -S . --preset\\=release")
  command-execute(projection-commands-configure-project record)
  execute-extended-command(nil "projection-commands-configure-project" nil)
  funcall-interactively(execute-extended-command nil "projection-commands-configure-project" nil)
  command-execute(execute-extended-command)

This seems to stem from using the CMake file API, which needs to know the build directory at configure time. With CMake presets we have a chicken-egg-problem: we don't know the build directory before configuring (and besides, to know the build directory after configuring we'd have to do jump through some hoops too).

The README suggests that there's a way to turn off the CMake file API usage:

Target resolution through the CMake file API. This is disabled by default but can be enabled by customizing projection-cmake-target-backend (for example: (setq projection-cmake-target-backend 'code-model)) and then re-configuring the project. but the mentioned variable has been obsoleted and removed.

Long story short, I suggest two changes:

P.S. Thanks for this very nice project! :)

mohkale commented 2 months ago

Now, projection-commands-configure-project calls cmake -S . -B build --preset debug, which overrides the build directory in the preset.

I don't think it will do that because of this bug ticket. Honestly I'd prefer if it did since it makes a whole lot of editor integration simpler but alas.

update of README.org

The README is as you mentioned out of date. In the past we supported using the help build target to parse available CMake targets but that was removed due to extra complexity and a sub-par experience when compared to the file-api. I'll update the README.

don't use the CMake file API if projection-cmake-build-directory is nil

This makes sense, although be warned this'll essentially invalidate compile-multi integration with CMake projects. So you won't be able to interactively select build or test targets.

mohkale commented 2 months ago

Should be fixed now. Please reopen if the issue persists.

jobor commented 2 months ago

Now, projection-commands-configure-project calls cmake -S . -B build --preset debug, which overrides the build directory in the preset.

I don't think it will do that because of this bug ticket. Honestly I'd prefer if it did since it makes a whole lot of editor integration simpler but alas.

I was imprecise. The build directory in a configure preset can be overridden. In a build preset, which #22276 is about, that's unfortunately not possible.

Build presets seem to have quite some fundamental problems, as further reading suggests. An IDE seems to be best off by directly controlling the build directory for now. Honestly, I've never used build presets in some serious manner and always pass the build dir to CMake (or Ninja).

don't use the CMake file API if projection-cmake-build-directory is nil

This makes sense, although be warned this'll essentially invalidate compile-multi integration with CMake projects. So you won't be able to interactively select build or test targets.

Yes, I also don't see a way around that other than adjusting my workflow.

jobor commented 2 months ago

Should be fixed now. Please reopen if the issue persists.

Thanks!