xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

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

Closed TOMO-CAT closed 2 months ago

TOMO-CAT commented 2 months ago

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

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

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

描述可能的解决方案

描述你认为的候选方案

目前没啥好的解法

其他信息

No response

waruqi commented 2 months ago

https://github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/core/project/target.lua#L656-L696

Issues-translate-bot commented 2 months ago

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 commented 2 months ago

https://github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/core/project/target.lua#L656-L696

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

Issues-translate-bot commented 2 months ago

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


https://github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/core/project/target.lua#L656-L696

How to skip dep packages? image

TOMO-CAT commented 2 months ago

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

Issues-translate-bot commented 2 months ago

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 commented 2 months ago
dep:get_from("links", "self") 
TOMO-CAT commented 2 months ago
dep:get_from("links", "self") 

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

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

Issues-translate-bot commented 2 months ago

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 commented 2 months ago

试了一下,过滤 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 commented 2 months ago

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 commented 2 months ago

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

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

https://github.com/xmake-io/xmake/blob/c90b483177dd45fb6e7a546b73fcd17c32bbaf23/xmake/core/project/target.lua#L573

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

Issues-translate-bot commented 2 months ago

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 commented 2 months ago

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

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

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

TOMO-CAT commented 2 months ago

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

是我本地 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 commented 2 months ago

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 commented 2 months ago

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

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

image

Issues-translate-bot commented 2 months ago

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 commented 2 months ago

更新到这个 patch 再试试 https://github.com/xmake-io/xmake/pull/5334

TOMO-CAT commented 2 months ago

更新到这个 patch 再试试 #5334

可以的,测试过了。

Issues-translate-bot commented 2 months ago

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


Update to this patch and try again #5334

Yes, tested.