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
在on_build 裡面有條件的添加移除原始碼 #350
Comments
暂时不建议通过target:add去动态修改文件列表,尽量在xmake.lua的描述域直接添加,因为files以及对应的objectfiles, dependfiles都有cache,目前不保证能够很好的支持target:add的方式去动态修改。 谨慎使用。
自定义on_build相当于重写内置的 build 逻辑了,这个时候改files后,也不会执行内置build,除非你自己调用了opt.origin()脚本 另外建议动态改flags, files此类放在target.on_load阶段做。。
脚本内部通过target:add()添加,比较原始,不会自动处理路径变换,你需要自己通过os.files去模式匹配文件,通过path.join去获取实际的文件绝对路径 target:add("files", os.files(path.join(os.projectdir(), "src/*.c")))
target:del还没实现 |
回頭仔細看過了一次正在用的代碼,的確是on_load ,是我在這篇問題內寫錯了,目前使用 os.files 這種方法,但遭遇到些小問題: target:add("files", os.files(path.join(os.projectdir(), "vp8/common/x86/*.c")))
error: xmake\bin/core/base/os.lua:705: xmake\bin/core/project/target.lua:1018:
attempt to index local 'file' (a number value) 轉而使用稍微麻煩一些的語法才成功: for _, filepath in ipairs(os.files("$(scriptdir)/vp8/common/x86/*.c")) do
target:add("files", filepath)
end |
|
有機會的話,若可以用條件來控制源碼是否要被編譯,對於一些複雜的專案移植來說會比較方便,例如 libvpx / ffmpeg 在 windows 上的移植就是一個例子。。 |
直接外面 if + add_files 控制不行吗?target:add 这块 我后面有时间改进下 |
删除这块,可以到 #353 跟进 |
这块我改进过了,见 #352 (comment) |
The text was updated successfully, but these errors were encountered: