Skip to content

Add json output for xmake show -t target#7024

Merged
waruqi merged 8 commits intodevfrom
show
Nov 14, 2025
Merged

Add json output for xmake show -t target#7024
waruqi merged 8 commits intodevfrom
show

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Nov 14, 2025

xmake show -t target --json
xmake show -t target --json --pretty

@waruqi waruqi added this to the v3.0.5 milestone Nov 14, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 enhances the xmake show command by adding support for JSON output, specifically for basic project information and detailed target configurations. The changes involve introducing a new serialization utility and refactoring existing information retrieval and display functions to accommodate both human-readable and machine-parseable JSON formats.

Highlights

  • JSON Output for xmake show -t target: This pull request introduces the capability to output information in JSON format for the xmake show -t target command, providing structured data for programmatic consumption.
  • New string.serializable Utility: A new utility function, string.serializable, has been added to xmake/core/base/string.lua. This function recursively converts Lua objects into a format suitable for JSON serialization, handling tables and converting functions/userdata/threads to strings.
  • Refactored Information Display Logic: The display logic in xmake/plugins/show/info/basic.lua and xmake/plugins/show/info/target.lua has been refactored. Data collection is now separated from presentation, allowing information to be gathered into structured tables before being either printed in the traditional human-readable format or encoded as JSON.
  • Structured Source Information: Functions like _get_sourceinfo_str have been updated to return structured data (file, line, tips) instead of formatted strings, facilitating the generation of detailed JSON output for source locations of various target properties (dependencies, rules, options, packages, files).
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces JSON output for xmake show commands, particularly for target information. The changes are well-structured, separating data collection from presentation, which is a good design choice. A new string.serializable helper has been added to prepare Lua objects for JSON encoding. My review includes suggestions to remove some minor code redundancies, fix a small regression in the human-readable output, and a refactoring suggestion to improve maintainability.

Comment on lines +73 to +74
local sourceinfo = _get_sourceinfo(opt_, name, value, {tips = tips})
values[value] = sourceinfo or {tips = tips}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The or {tips = tips} part of this assignment is redundant. The _get_sourceinfo function will always return a table when tips is provided, as it is in this context. It will never return nil, so the fallback is unnecessary.

            values[value] = _get_sourceinfo(opt_, name, value, {tips = tips})

Comment on lines 174 to 184
local deps = target:get("deps")
if deps then
cprint(" ${color.dump.string}deps${clear}:")
local entries = {}
for _, dep in ipairs(deps) do
cprint(" ${color.dump.reference}->${clear} %s%s", dep, _get_sourceinfo_str(target, "deps", dep))
local entry = {name = dep, source = _get_sourceinfo(target, "deps", dep)}
table.insert(entries, entry)
end
if #entries > 0 then
info.deps = entries
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is some code duplication in how deps, rules, and packages are collected. The logic for iterating over target:get(key), creating entries, and adding them to the info table is very similar for these three.

Consider creating a helper function to reduce this repetition, for example:

local function _collect_simple_entries(target, info, key)
    local values = target:get(key)
    if not values then return end
    local entries = {}
    for _, value in ipairs(values) do
        table.insert(entries, {name = value, source = _get_sourceinfo(target, key, value)})
    end
    if #entries > 0 then
        info[key] = entries
    end
end

You could then call this for deps, rules, and packages, which would make the _collect_target_info function shorter and more maintainable.

end
if info.compilers then
for _, compiler in ipairs(info.compilers) do
cprint(" ${color.dump.string}compiler (%s)${clear}: %s", compiler.sourcekind, compiler.program)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The human-readable output for compilers is missing the general compiler flags (compiler.flags). The previous implementation displayed them. To restore this information and for consistency with how linker flags are displayed, you should also print compiler.flags here.

            cprint("    ${color.dump.string}compiler (%s)${clear}: %s", compiler.sourcekind, compiler.program)
            cprint("      ${color.dump.reference}->${clear} %s", compiler.flags)

local info = _collect_target_info(target)
if opt.json then
info.api_entries = nil
print(json.encode(string.serializable(info) or {}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The _collect_target_info function is designed to produce a table that is already serializable by calling string.serializable on potentially problematic values. Therefore, the outer string.serializable(info) call is likely redundant and adds a performance overhead by traversing the entire info table again. Additionally, since info is always a table, or {} is also unnecessary. You can simplify this line.

        print(json.encode(info))

@waruqi waruqi merged commit 100900c into dev Nov 14, 2025
44 checks passed
@waruqi waruqi deleted the show branch November 14, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant