Conversation
Summary of ChangesHello @waruqi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant new feature to Xmake: the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces xmake check syntax support, a valuable feature for performing syntax checks without a full build. The implementation is well-thought-out, correctly modifying the build process to inject syntax-check flags and bypass linking. The new checker is cleanly implemented. I've provided a few suggestions to enhance code clarity and maintainability by refactoring some functions and addressing minor code duplication. Overall, this is a solid contribution.
| -- is syntax check enabled? | ||
| function _is_syntax_check() | ||
| return memcache.get("syntax_check", "enabled") or false | ||
| end |
| function project.policy_set(name, value) | ||
| -- get current policies from cache or initialize | ||
| local policies = project._memcache():get("policies") | ||
| if not policies then | ||
| -- force initialization by calling policy() once | ||
| project.policy(name) | ||
| policies = project._memcache():get("policies") | ||
| end | ||
| policies = policies or {} | ||
|
|
||
| -- set the policy value | ||
| policies[name] = value | ||
|
|
||
| -- update cache | ||
| project._memcache():set("policies", policies) | ||
| end |
There was a problem hiding this comment.
The logic for initializing and setting policies can be simplified. You can make the implementation more straightforward by always calling project.policy() to ensure policies are loaded, and then retrieving them from the cache.
function project.policy_set(name, value)
-- ensure policies are loaded and get them
project.policy(name)
local policies = project._memcache():get("policies") or {}
-- set the policy value
policies[name] = value
-- update cache
project._memcache():set("policies", policies)
end
| function _has_cpp_rules(target) | ||
| for _, ruleinst in ipairs(target:orderules()) do | ||
| local rulename = ruleinst:name() | ||
| if rulename == "c++.build" or rulename == "c.build" or | ||
| rulename == "objc++.build" or rulename == "objc.build" then | ||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end |
There was a problem hiding this comment.
This function can be made more readable and maintainable by using a table lookup for the rule names. This avoids a long chain of or conditions and makes it easier to manage the list of supported rules.
function _has_cpp_rules(target)
local cpp_rules = {["c++.build"] = true, ["c.build"] = true, ["objc++.build"] = true, ["objc.build"] = true}
for _, ruleinst in ipairs(target:orderules()) do
if cpp_rules[ruleinst:name()] then
return true
end
end
return false
end
| function _check_compiler_support(target) | ||
| local has_support = false | ||
| if target:has_tool("cc", "gcc", "clang") or target:has_tool("cxx", "gxx", "clangxx") then | ||
| -- gcc/clang: -fsyntax-only | ||
| has_support = true | ||
| elseif target:has_tool("cc", "cl") or target:has_tool("cxx", "cl") then | ||
| -- MSVC: /Zs | ||
| has_support = true | ||
| end | ||
| return has_support | ||
| end |
There was a problem hiding this comment.
This function can be simplified to be more concise and readable by returning the boolean expression directly.
function _check_compiler_support(target)
-- gcc/clang: -fsyntax-only
-- MSVC: /Zs
return (target:has_tool("cc", "gcc", "clang") or target:has_tool("cxx", "gxx", "clangxx"))
or (target:has_tool("cc", "cl") or target:has_tool("cxx", "cl"))
end
xmake check syntaxmesonbuild/meson#12228