Skip to content
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

Closed
orzuk-lmj opened this issue Feb 13, 2019 · 7 comments
Closed

在on_build 裡面有條件的添加移除原始碼 #350

orzuk-lmj opened this issue Feb 13, 2019 · 7 comments

Comments

@orzuk-lmj
Copy link
Contributor

  • 目前已知 on_build 裡面使用 target:add("files", "src/xxx.c") 這種使用方式
  • 若打算添加 "src/*.c" 這類的呢,現在貌似會有底下這種錯誤,該如何解決?
    warning: cannot match target(vpx).add_files("vp8/common/x86/*.c") at :-1
    warning: cannot match target(vpx).add_files("vp8/common/x86/*.asm") at :-1 
    
  • 若打算在 on_build 內先判斷 arch == xxx 之後移除某些檔案,功能近似於 del_files 但需要有先判斷條件,該怎麼辦? 查了一下好像不存在 target:del(......) 這種接口。
@waruqi
Copy link
Member

waruqi commented Feb 13, 2019

暂时不建议通过target:add去动态修改文件列表,尽量在xmake.lua的描述域直接添加,因为files以及对应的objectfiles, dependfiles都有cache,目前不保证能够很好的支持target:add的方式去动态修改。

谨慎使用。

目前已知 on_build 裡面使用 target:add("files", "src/xxx.c") 這種使用方式

自定义on_build相当于重写内置的 build 逻辑了,这个时候改files后,也不会执行内置build,除非你自己调用了opt.origin()脚本

另外建议动态改flags, files此类放在target.on_load阶段做。。

若打算添加 "src/*.c" 這類的呢,現在貌似會有底下這種錯誤,該如何解決?

脚本内部通过target:add()添加,比较原始,不会自动处理路径变换,你需要自己通过os.files去模式匹配文件,通过path.join去获取实际的文件绝对路径

target:add("files", os.files(path.join(os.projectdir(), "src/*.c")))

若打算在 on_build 內先判斷 arch == xxx 之後移除某些檔案,功能近似於 del_files 但需要有先判斷條件,該怎麼辦? 查了一下好像不存在 target:del(......) 這種接口。

target:del还没实现

@orzuk-lmj
Copy link
Contributor Author

orzuk-lmj commented Feb 14, 2019

回頭仔細看過了一次正在用的代碼,的確是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

@waruqi
Copy link
Member

waruqi commented Feb 14, 2019

target:add("files", (os.files(path.join(os.projectdir(), "vp8/common/x86/*.c")))) 试试, os.files外面在包个括号,因为os.files返回的是 filelists, filecount,后面有个count

@orzuk-lmj
Copy link
Contributor Author

orzuk-lmj commented Feb 14, 2019

有機會的話,若可以用條件來控制源碼是否要被編譯,對於一些複雜的專案移植來說會比較方便,例如 libvpx / ffmpeg 在 windows 上的移植就是一個例子。。
目前這樣堪用,但因為少了 del 稍微不太方便,主要也是因為檔案量多,這時候排除部分會少維護一些檔名。。

@waruqi
Copy link
Member

waruqi commented Feb 14, 2019

直接外面 if + add_files 控制不行吗?target:add 这块 我后面有时间改进下

@waruqi waruqi added this to the v2.2.5 milestone Feb 15, 2019
@waruqi
Copy link
Member

waruqi commented Feb 15, 2019

删除这块,可以到 #353 跟进

@waruqi
Copy link
Member

waruqi commented Feb 18, 2019

这块我改进过了,见 #352 (comment)

@waruqi waruqi closed this as completed Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants