-
Notifications
You must be signed in to change notification settings - Fork 105
Better handling of build preset targets #295
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,7 +331,9 @@ function cmake.build(opt, callback) | |
| end) | ||
| end | ||
|
|
||
| if opt.target == nil and config.build_target == nil then | ||
| local presets = Presets:parse(config.cwd) | ||
| local build_preset = presets:get_build_preset(config.build_preset) | ||
| if (not config.build_preset or config.build_preset and not build_preset.targets) and opt.target == nil and config.build_target == nil then | ||
| return cmake.select_build_target(true, function(result) | ||
| if result:is_ok() then | ||
| cmake.build(opt, callback) | ||
|
|
@@ -353,23 +355,26 @@ function cmake.build(opt, callback) | |
| } | ||
| end | ||
|
|
||
| if opt.target ~= nil then | ||
| vim.list_extend(args, { "--target", opt.target }) | ||
| vim.list_extend(args, fargs) | ||
| elseif config.build_target == "all" then | ||
| vim.list_extend(args, { "--target", "all" }) | ||
| vim.list_extend(args, fargs) | ||
| else | ||
| vim.list_extend(args, { "--target", config.build_target }) | ||
| vim.list_extend(args, fargs) | ||
| if not build_preset or build_preset and not build_preset.targets then | ||
| if opt.target ~= nil then | ||
| vim.list_extend(args, { "--target", opt.target }) | ||
| vim.list_extend(args, fargs) | ||
| elseif config.build_target == "all" then | ||
| vim.list_extend(args, { "--target", "all" }) | ||
| vim.list_extend(args, fargs) | ||
| else | ||
| vim.list_extend(args, { "--target", config.build_target }) | ||
| vim.list_extend(args, fargs) | ||
| end | ||
|
Comment on lines
+358
to
+368
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want the build_preset.targets to take precedence, you can check for |
||
| end | ||
|
|
||
| if config.build_type ~= nil then | ||
| vim.list_extend(args, { "--config", config.build_type }) | ||
| if not build_preset then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this additional if? |
||
| if config.build_type ~= nil then | ||
| vim.list_extend(args, { "--config", config.build_type }) | ||
| end | ||
| vim.list_extend(args, config:build_options()) | ||
| end | ||
|
|
||
| vim.list_extend(args, config:build_options()) | ||
|
|
||
| local env = environment.get_build_environment(config) | ||
| local cmd = const.cmake_command | ||
| return utils.execute(cmd, config.env_script, env, args, config.cwd, config.executor, callback) | ||
|
|
@@ -825,8 +830,24 @@ function cmake.select_build_preset(callback) | |
| if config.build_preset ~= choice then | ||
| config.build_preset = choice | ||
| end | ||
| local build_preset = presets:get_build_preset(choice) | ||
| if build_preset.targets then | ||
| if type(build_preset.targets) == string then | ||
| config.build_target = build_preset.targets | ||
| else -- build preset is an array | ||
| if #(build_preset.targets) == 1 then | ||
| config.build_target = build_preset.targets[1] | ||
| else | ||
| -- XXX: Array targets are not supported in other code paths | ||
| -- As a workaround, unset the current build_target if any (it is not used when using build presets) | ||
| config.build_target = nil | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we do not have a handling for multiple build targets currently, you could either keep the currently selected one (if it is part of the array) or always select the first one from the list. The user can still change the target, if needed. I think a refactoring to support multiple targets might be helpful. But this is beyond the scope of this MR for sure. |
||
| end | ||
| end | ||
| else -- build preset does not have a target, ask | ||
| config.build_target = nil | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the build_preset does not have a target, the currently selected one should be kept. |
||
| end | ||
| local associated_configure_preset = presets:get_configure_preset( | ||
| presets:get_build_preset(choice).configurePreset, | ||
| build_preset.configurePreset, | ||
| { include_hidden = true } | ||
| ) | ||
| local associated_configure_preset_name = associated_configure_preset | ||
|
|
||
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.
build_preset could be nil. You will run into an index into nill error on
build_preset.targetsin this case. Maybe check forif (not build_preset or not build_preset.targets) ...?