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

只获取 target:deps 自身的 syslinks,不要递归获取 target:pkgs 的 syslinks #5331

Closed
TOMO-CAT opened this issue Jul 11, 2024 · 21 comments

Comments

@TOMO-CAT
Copy link

你在什么场景下需要该功能?

我在写一个打包的 phony target,希望将当前项目里所有的 dep 的 syslinks 和 deps 导出,但是这里的 syslinks 会把 add_packages("xx") 的 syslinks 都带上,有办法可以跳过吗,只拿 target 里面 add_syslinks 的部分。
d14d47d8cc76c1551f5f6d072545ed37

背景是现在项目接完了,想把一些之前定制化的脚本都抽到 rule 里,需要封装一下

描述可能的解决方案

描述你认为的候选方案

目前没啥好的解法

其他信息

No response

@waruqi
Copy link
Member

waruqi commented Jul 11, 2024

-- get values from the given sources
--
-- e.g.
--
-- only from the current target:
-- target:get_from("links")
-- target:get_from("links", "self")
--
-- from the given dep:
-- target:get_from("links", "dep::foo")
-- target:get_from("links", "dep::foo", {interface = true})
-- target:get_from("links", "dep::*")
--
-- from the given option:
-- target:get_from("links", "option::foo")
-- target:get_from("links", "option::*")
--
-- from the given package:
-- target:get_from("links", "package::foo")
-- target:get_from("links", "package::*")
--
-- from the given dep/option, dep/package
-- target:get_from("links", "dep::foo/option::bar")
-- target:get_from("links", "dep::foo/option::*")
-- target:get_from("links", "dep::foo/package::bar")
-- target:get_from("links", "dep::foo/package::*")
--
-- from the multiple sources:
-- target:get_from("links", {"self", "option::foo", "dep::bar", "package::zoo"})
-- target:get_from("links", {"self", "option::*", "dep::*", "package::*"})
--
-- from all:
-- target:get_from("links", "*")
--
-- return:
-- local values, sources = target:get_from("links", "*")
-- for idx, value in ipairs(values) do
-- local source = sources[idx]
-- end
--
function _instance:get_from(name, sources, opt)

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Only get the syslinks of target:deps itself, do not recursively get the syslinks of target:pkgs

@TOMO-CAT
Copy link
Author

TOMO-CAT commented Jul 11, 2024

-- get values from the given sources
--
-- e.g.
--
-- only from the current target:
-- target:get_from("links")
-- target:get_from("links", "self")
--
-- from the given dep:
-- target:get_from("links", "dep::foo")
-- target:get_from("links", "dep::foo", {interface = true})
-- target:get_from("links", "dep::*")
--
-- from the given option:
-- target:get_from("links", "option::foo")
-- target:get_from("links", "option::*")
--
-- from the given package:
-- target:get_from("links", "package::foo")
-- target:get_from("links", "package::*")
--
-- from the given dep/option, dep/package
-- target:get_from("links", "dep::foo/option::bar")
-- target:get_from("links", "dep::foo/option::*")
-- target:get_from("links", "dep::foo/package::bar")
-- target:get_from("links", "dep::foo/package::*")
--
-- from the multiple sources:
-- target:get_from("links", {"self", "option::foo", "dep::bar", "package::zoo"})
-- target:get_from("links", {"self", "option::*", "dep::*", "package::*"})
--
-- from all:
-- target:get_from("links", "*")
--
-- return:
-- local values, sources = target:get_from("links", "*")
-- for idx, value in ipairs(values) do
-- local source = sources[idx]
-- end
--
function _instance:get_from(name, sources, opt)

怎么跳过 dep 的 packages 呢?只希望获取 project 内部的 dep 的 links,不要递归返回 package 的 links
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


-- get values from the given sources
--
-- e.g.
--
-- only from the current target:
-- target:get_from("links")
-- target:get_from("links", "self")
--
-- from the given dep:
-- target:get_from("links", "dep::foo")
-- target:get_from("links", "dep::foo", {interface = true})
-- target:get_from("links", "dep::*")
--
-- from the given option:
-- target:get_from("links", "option::foo")
-- target:get_from("links", "option::*")
--
-- from the given package:
-- target:get_from("links", "package::foo")
-- target:get_from("links", "package::*")
--
-- from the given dep/option, dep/package
-- target:get_from("links", "dep::foo/option::bar")
-- target:get_from("links", "dep::foo/option::*")
-- target:get_from("links", "dep::foo/package::bar")
-- target:get_from("links", "dep::foo/package::*")
--
-- from the multiple sources:
-- target:get_from("links", {"self", "option::foo", "dep::bar", "package::zoo"})
-- target:get_from("links", {"self", "option::*", "dep::*", "package::*"})
--
-- from all:
-- target:get_from("links", "*")
--
-- return:
-- local values, sources = target:get_from("links", "*")
-- for idx, value in ipairs(values) do
-- local source = sources[idx]
-- end
--
function _instance:get_from(name, sources, opt)

How to skip dep packages?
image

@TOMO-CAT
Copy link
Author

好像可以通过对 source 做过滤,出现 package:: 就跳过,但不是太优雅

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


It seems that you can filter the source and skip it if package:: appears, but it is not too elegant.

@waruqi
Copy link
Member

waruqi commented Jul 11, 2024

dep:get_from("links", "self") 

@TOMO-CAT
Copy link
Author

dep:get_from("links", "self") 

这种写法还是递归获取了 target:dep 对应的所有 packages 导入的 syslinks:
image

有办法只获取 target 里面的 syslinks 吗: "ceres", "pcl_common", "pcl_filters", "pcl_segmentation" 只需要这四个

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


``lua
dep:get_from("links", "self")

This way of writing still recursively obtains the syslinks imported by all packages corresponding to target:dep:
image

Is there a way to only get the syslinks in the target: "ceres", "pcl_common", "pcl_filters", "pcl_segmentation" Only these four are needed

@TOMO-CAT
Copy link
Author

试了一下,过滤 dep::* 中带 package:: 的也不行,它已经递归拿到了 package 的 syslinks 了

        local values, sources = target:get_from("syslinks", "dep::localization.initialization_localization.reflector_detection")
        for idx, value in ipairs(values) do
            local source = sources[idx]
            print(source)
            print(value)
        end

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I tried it, but filtering dep::* with package:: doesn’t work either. It has already recursively obtained the syslinks of package.

        local values, sources = target:get_from("syslinks", "dep::localization.initialization_localization.reflector_detection")
        for idx, value in ipairs(values) do
            local source = sources[idx]
            print(source)
            print(value)
        end

@waruqi
Copy link
Member

waruqi commented Jul 11, 2024

不知道你说啥,反正我这可以,没法复现

add_requires("libuv")

target("foo")
    set_kind("static")
    add_packages("libuv")
    add_syslinks("z")

target("test")
    set_kind("binary")
    add_deps("foo")
    add_files("src/*.cpp")
    on_config(function (target)
	print("1111", target:dep("foo"):get("syslinks"))
	print("2222", (target:get_from("syslinks", "dep::*")))
    end)
1111 z
2222 { 
  "z",
  { 
    "pthread",
    "dl" 
  } 
}

target:get("syslinks") 原本就只会仅仅 get target 里面的 syslinks ,不会从 packages 里面取。除非你把这些设置到了 target

function _instance:get(name, opt)

代码里,也压根没有从 pkgs 取值的实现,只要 get_from 才有可能取到 package

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I don’t know what you’re talking about. Anyway, I can do this, but I can’t reproduce it.

add_requires("libuv")

target("foo")
    set_kind("static")
    add_packages("libuv")
    add_syslinks("z")

target("test")
    set_kind("binary")
    add_deps("foo")
    add_files("src/*.cpp")
    on_config(function (target)
print("1111", target:dep("foo"):get("syslinks"))
print("2222", (target:get_from("syslinks", "dep::*")))
    end)
1111z
2222 {
  "z",
  {
    "pthread",
    "dl"
  }
}

target:get("syslinks") will only get the syslinks in the target, not the packages. Unless you set these to target

@TOMO-CAT
Copy link
Author

不知道你说啥,反正我这可以,没法复现

是我本地 xmake 版本的问题吗?这有一个最小复现的 demo:
https://github.com/TOMO-CAT/xmake-template/blob/main/unexpected_deps_syslinks/README.md

我希望能不把依赖库 gtest 的 syslinks 引进来

@TOMO-CAT
Copy link
Author

不知道你说啥,反正我这可以,没法复现

是我本地 xmake 版本的问题吗?这有一个最小复现的 demo: https://github.com/TOMO-CAT/xmake-template/blob/main/unexpected_deps_syslinks/README.md

我希望能不把依赖库 gtest 的 syslinks 引进来

gtest 只有在 linux 会带 syslinks,windows 上可能复现不出来,我换个库试试
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I don’t know what you are talking about. Anyway, I can do this, but I can’t reproduce it.

Is it a problem with my local xmake version? Here is a minimally reproducible demo: https://github.com/TOMO-CAT/xmake-template/blob/main/unexpected_deps_syslinks/README.md

I hope that syslinks that depends on the library gtest can not be introduced.

gtest only supports syslinks on Linux. It may not be reproduced on Windows. I will try using another library.
image

@TOMO-CAT
Copy link
Author

代码里,也压根没有从 pkgs 取值的实现,只要 get_from 才有可能取到 package

试验了几次,你给的这个例子确实就没问题,主要出在 c++ rule 这,加上这一行就不行:

image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


In the code, there is no implementation of getting the value from pkgs at all. Only get_from can get the package.

After testing it several times, the example you gave is indeed no problem. The main problem lies in the c++ rule. Adding this line won't work:

image

waruqi added a commit that referenced this issue Jul 11, 2024
@waruqi
Copy link
Member

waruqi commented Jul 11, 2024

更新到这个 patch 再试试 #5334

@waruqi waruqi added this to the v2.9.4 milestone Jul 11, 2024
@TOMO-CAT
Copy link
Author

更新到这个 patch 再试试 #5334

可以的,测试过了。

waruqi added a commit that referenced this issue Jul 11, 2024
@waruqi waruqi closed this as completed Jul 11, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Update to this patch and try again #5334

Yes, tested.

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

3 participants