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

xmake的获取变量 #15

Open
chenyanzz opened this issue Dec 2, 2017 · 5 comments
Open

xmake的获取变量 #15

chenyanzz opened this issue Dec 2, 2017 · 5 comments

Comments

@chenyanzz
Copy link

希望可以获取targetdir,targetname,dependfile这样的变量内容

@chenyanzz chenyanzz changed the title 获取变量 xmake的获取变量 Dec 2, 2017
@waruqi
Copy link
Member

waruqi commented Dec 2, 2017

targetdir 在 2.1.9 开发版本是有提供的:

target("xxxx")
    after_build(function (target)
         print(target:targetdir())
    end)

如果2.1.8等之前的版本可以这样获取:

target("xxxx")
    after_build(function (target)
         print(path.directory(target:targetfile()))
    end)

targetname也是有的target:name(),这些你可以详细看下文档,文档手册下面target相关api介绍里面都有。

依赖文件,可以通过以下方式获取:

target("test")
    after_build(function (target)
        for _, incdepfile in ipairs(target:incdepfiles()) do
               print(incdepfile) -- 这个只是打印每个依赖文件的路径,你可以先看下里面的内容,然后用io接口进行读取
               local deps =  io.load(incdepfile)
               print(deps)
        end
    end)

另外xmake相关问题,尽量提到xmake/issues里面去,谢谢

@chenyanzz
Copy link
Author

image

唔手册是又换地址了吗...为什么没找到

@waruqi
Copy link
Member

waruqi commented Dec 2, 2017

地址没错,部分接口我漏写了,不好意思,这块我之后更新下文档,你先看下上面的接口使用例子好了,如果现在就需要更完整target接口,可以先去源码里面看:target.lua

@chenyanzz
Copy link
Author

嗯哼,好的作者大大加油 emoji.嘿哈

@waruqi
Copy link
Member

waruqi commented Dec 2, 2017

其实这部分target接口,文档里面已经写了的,在project.target

你截图的那部分接口是target()外层域的描述接口api,用于配置target的各种定义,例如:

target("xxx")
     set_kind("static")

而自定义脚本on_run, after_build里面的target对象接口,用于自定义脚本中对之前配置的target进行访问和维护,属于core.project.target对象模块,因此需要查阅文档中,扩展模块-core.project.target接口才行,这个模块文档还没有,但是project.target接口里面有大部分对于target的描述,可以先看下。。

on_run(function (target)
    print(target:name())
    print(target:targetfile())
end)

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

No branches or pull requests

2 participants