Skip to content

Add --stdin#7284

Merged
waruqi merged 75 commits intoxmake-io:devfrom
luadebug:stdin
Feb 3, 2026
Merged

Add --stdin#7284
waruqi merged 75 commits intoxmake-io:devfrom
luadebug:stdin

Conversation

@luadebug
Copy link
Member

@luadebug luadebug commented Jan 31, 2026

#7277
Just test. This looks very complicated to implement as need test another OS.
On windows OS there is cmd and powershell or pwsh.
Dunno maybe this sort of feature needs os.shell improved for winos.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @luadebug, 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 enhancement to the xmake lua command by implementing the --from-stdin option. This new capability allows users to execute Lua scripts by providing their content directly through standard input, greatly improving the command's utility for dynamic scripting and integration into shell pipelines. The changes include the core logic for reading from stdin, proper argument handling, and robust error management, all backed by a new suite of tests to ensure reliable operation across different operating system shells.

Highlights

  • New --from-stdin option: The xmake lua command now supports a --from-stdin option, allowing Lua scripts to be executed by reading their content from standard input.
  • Standard Input Script Execution: This feature enables piping Lua code directly to xmake lua or redirecting content from a file, enhancing scripting flexibility.
  • Comprehensive Test Coverage: New test cases have been added to tests/projects/test_stdin/xmake.lua to verify the --from-stdin functionality under various scenarios, including successful execution and error handling, for both standard shell and PowerShell.
  • os.isexec Robustness Improvement: A minor adjustment in xmake/core/base/os.lua improves the os.isexec function by ensuring it correctly handles file executability checks, even if os._access is not available.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 the --from-stdin flag for the xmake lua command, allowing script execution from standard input. The core implementation is sound, but there are a few areas for improvement in both the implementation and the accompanying tests. Specifically, the new test file contains critical flaws in how it checks command exit statuses, which undermines the validity of the failure-case tests. The tests could also benefit from more robust resource cleanup. The main implementation file has some minor redundancies that can be cleaned up for better code clarity.

@waruqi
Copy link
Member

waruqi commented Jan 31, 2026

If the implementation is too complex and makes it difficult to maintain, I will not consider supporting it.

@luadebug
Copy link
Member Author

luadebug commented Jan 31, 2026

If the implementation is too complex and makes it difficult to maintain, I will not consider supporting it.

  1. I am just confused about stack trace. Should it really show stack trace?

  2. Windows OS probably has sh tool if it has installed GIT/MinGW/Cygwin. I just tested on my Linux machine current implementation.

XMAKE_PROGRAM_DIR: /home/lin/xmake-luadebug/xmake
xmake binary: /usr/bin/xmake
Feature presence check: PASS
running: echo 'print("hello from pipe")' | /usr/bin/xmake lua --from-stdin
STDOUT 1:
hello from pipe
{ }

STDERR 1:

running: /usr/bin/xmake lua --from-stdin < /home/lin/xmake-luadebug/tests/projects/test_stdin/test.lua
STDOUT 2:
hello from file
{ }

STDERR 2:

running: echo 'raise("error_pipe")' | /usr/bin/xmake lua --from-stdin
STDOUT 3:
error: cannot import module: _2169751cbd80ae9a82df4e0ab747dfd5, error_pipe

STDERR 3:

running: /usr/bin/xmake lua --from-stdin < /home/lin/xmake-luadebug/tests/projects/test_stdin/error.lua
STDOUT 4:
error: cannot import module: _2169751cbd80ae9a82df4e0ab747dfd5, error_file

STDERR 4:

PowerShell 7.5.4
pwsh detected, running pwsh tests...
running pwsh: Write-Output "print(`"hello from pwsh pipe`")" | & '/usr/bin/xmake' lua --from-stdin
STDOUT 5:
hello from pwsh pipe
{ }

STDERR 5:

running pwsh: Get-Content '/home/lin/xmake-luadebug/tests/projects/test_stdin/test_pwsh.lua' | & '/usr/bin/xmake' lua --from-stdin
STDOUT 6:
hello from pwsh file
{ }

STDERR 6:

running pwsh: Write-Output "raise(`"error_pwsh_pipe`")" | & '/usr/bin/xmake' lua --from-stdin
STDOUT 7:
error: cannot import module: _2169751cbd80ae9a82df4e0ab747dfd5, error_pwsh_pipe

STDERR 7:

running pwsh: Get-Content '/home/lin/xmake-luadebug/tests/projects/test_stdin/error_pwsh.lua' | & '/usr/bin/xmake' lua --from-stdin
STDOUT 8:
error: cannot import module: _2169751cbd80ae9a82df4e0ab747dfd5, error_pwsh_file

STDERR 8:

I am not completely asure is it good or should behave different way for tests/projects/test_stdin. But I assume windows OS would require to wrap every variable related to path like xmath path or script path should be wrapped inside of path.unix(...)...

@luadebug
Copy link
Member Author

luadebug commented Feb 2, 2026

After changes in .c file it would print out

./build/xmake lua -c "print(os.programfile())"
/home/lin/xmake-luadebug/core/build/xmake

as expected to be from a start.

@luadebug
Copy link
Member Author

luadebug commented Feb 2, 2026

I dunno what's wrong now :?

@waruqi
Copy link
Member

waruqi commented Feb 2, 2026

I think I am still unable to resolve APE file issue on my Linux machine yet.

testing pwsh_single: pwsh -c "echo \"print('hello_pwsh')\" | env "/usr/bin/ape" l --stdin"
  -> failed
     out: 
     err: ape error: l: not found (maybe chmod +x or ./ needed)

error: [test_stdin]: Test failed! Expect: 

I don't understand what the APE problem is? Why is the xmake binary file located at /usr/bin/ape?

whereis ape ape: /usr/bin/ape APE loader aur package. I assume that is required in order to execute those sort of com files? Sorry mystery why os.programfile() returns /usr/bin/ape still remains unsolved.

./core/build/xmake l os.programfile
"/usr/bin/ape"
whereis cosmocc
cosmocc: /usr/bin/cosmocc /opt/cosmocc/bin/cosmocc
whereis ape
ape: /usr/bin/ape

I've tried using cosmocc to compile xmake on macOS/Linux, but I haven't been able to reproduce your problem.

It works for me. (dev branch)

ruki@dcc74edcdedc:/mnt/xmake$ file ./build/xmake
./build/xmake: DOS/MBR boot sector; partition 1 : ID=0x7f, active, start-CHS (0x0,0,1), end-CHS (0x3ff,255,63), startsector 0, 4294967295 sectors
ruki@dcc74edcdedc:/mnt/xmake$ xmake l core.base.binutils.format ./build/xmake
"ape"
ruki@dcc74edcdedc:/mnt/xmake$ ./build/xmake l os.programfile
"/mnt/xmake/build/xmake"

@waruqi
Copy link
Member

waruqi commented Feb 2, 2026

well, I got it. but it still does not work.

ruki@dcc74edcdedc:/mnt/xmake$ ./build/xmake l os.programfile
"/home/ruki/.ape-1.10"

@luadebug
Copy link
Member Author

luadebug commented Feb 2, 2026

Well I am busy for now maybe I will look into this in a future.

@waruqi
Copy link
Member

waruqi commented Feb 2, 2026

Well I am busy for now maybe I will look into this in a future.

I have fixed it.

@waruqi
Copy link
Member

waruqi commented Feb 2, 2026

/gemini review

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 a useful feature to run Lua scripts from stdin via the --stdin flag. The implementation covers different shells on both Windows and non-Windows platforms, and includes a good set of tests. My review includes a few suggestions to improve robustness and maintainability, such as making a check for APE binaries more specific, simplifying some of the new logic, and ensuring temporary files are cleaned up even when errors occur. Overall, this is a great addition.

@waruqi waruqi added this to the v3.0.7 milestone Feb 3, 2026
@waruqi waruqi merged commit 1bcce9d into xmake-io:dev Feb 3, 2026
35 checks passed
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.

2 participants