Fix: allow build with no selected build preset#334
Fix: allow build with no selected build preset#334bailwillharr wants to merge 1 commit intoCivitasv:masterfrom
Conversation
lceWolf
left a comment
There was a problem hiding this comment.
Nice finding and I very much appreciate this MR!
While your changes do work, I think the handling of the "None" build-preset itself could be improved.
I don't like the special handling for a "None" choice and checking for that hardcoded string.
Hope you don't feel bad about this, but I've got another idea for a solution. I'd love hearing your feedback on #335
| end | ||
|
|
||
| function Presets.createEmptyBuildPreset() | ||
| return BuildPreset.None |
There was a problem hiding this comment.
That does not actually return a new instance. It returns the same table for each invocation. Modifications of that table would be shared across every "instance" you created that way. To properly create a new instance you should use
return setmetatable({}, <NonePreset-Table>)
| local BuildPreset = {} | ||
|
|
||
| -- 'None' instance for when no build preset should be used. | ||
| BuildPreset.None = { |
There was a problem hiding this comment.
I think this is not quite the effect you are trying to achieve. This is not an instance. It is something like a subclass within the BuildPreset class which re-uses the methods and fields of the BuildPreset class, yet some methods are overwritten/hidden (get_build_target and get_build_type)
See my comment on the createEmptyBuildPreset method on how to create individual instances of a None Preset
|
Closed in favor of #335 |
|
Thanks a lot for this fix man. Tbh my experience with Lua is pretty limited so I'm glad someone who knows what they're doing stepped up :). |
This pull requests fixes the behaviour I mentioned in Issue #333 (CMake build presets are required when using configure presets). It allows the user to proceed with building if a CMake configure preset has been selected but no build presets are available.
This change was implemented by creating a sentinel object for the
BuildPresetclass which represents the choice of no build preset. This choice cannot be specified withbuild_preset = nilas that represents the case where a build preset is yet to be selected.Code can check for this 'no build preset wanted' state by calling
build_preset.is_nonewhich returnstruein that case.A few
ifstatements inlua/cmake-tools/init.luaare modified to ensure thatbuild_presetis not used when set toBuildPreset.None.In addition, a minor typo causing undersired behaviour was fixed on line 33 (previously line 21) of
lua/cmake-tools/build_preset.lua.