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

本地定义的 package 无法替换掉间接依赖 #5362

Open
TOMO-CAT opened this issue Jul 19, 2024 · 36 comments
Open

本地定义的 package 无法替换掉间接依赖 #5362

TOMO-CAT opened this issue Jul 19, 2024 · 36 comments
Labels

Comments

@TOMO-CAT
Copy link

Xmake 版本

v2.9.2

操作系统版本和架构

Linux 720ce3a659a2 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

描述问题

85fc70c20e7f8f6c562405baf2937c0a
背景是本地仿真需要用本地库替换掉某个库,比如我这里定义了 pnc 引用本地库,但是这里 sim 也依赖了 pnc,在安装 sim 时会报错:`package(zpnc): version(latest) not found!

期待的结果

能影响到间接 package。

工程配置

附加信息和错误日志

@TOMO-CAT TOMO-CAT added the bug label Jul 19, 2024
@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

你 package 定义里面啥 add_deps 都没加,等于没依赖,当然不生效了。。

xmake 不会去自动解析 你工程里面的 xmake.lua ,你得自己配置上 add_deps

@TOMO-CAT
Copy link
Author

你 package 定义里面啥 add_deps 都没加,等于没依赖,当然不生效了。。

xmake 不会去自动解析 你工程里面的 xmake.lua ,你得自己配置上 add_deps

不是自己定义的 package zpnc 缺少依赖,是 zsim package 找不到 zpnc package,zsim 里是带了 zpnc 的:

package("zsim", function()
    ...
    add_deps("zpnc", ...)
end)

@Issues-translate-bot
Copy link

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


Title: Locally defined packages cannot replace indirect dependencies

@Issues-translate-bot
Copy link

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


You haven't added any add_deps in your package definition, which means there are no dependencies, and of course it won't take effect. .

xmake will not automatically parse xmake.lua in your project, you have to configure add_deps yourself.

@Issues-translate-bot
Copy link

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


You have not added any add_deps in your package definition, which means there is no dependency, and of course it will not take effect. .

xmake will not automatically parse xmake.lua in your project. You have to configure add_deps yourself.

It’s not that the self-defined package zpnc lacks dependencies, it’s that the zsim package cannot find the zpnc package, and zsim contains zpnc:

package("zsim", function()
    ...
    add_deps("zpnc", ...)
end)

@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

既然你是 zsim 依赖 zpnc 。。为啥你配置的确是 add_requireconfs("**.zsim")? 不应该是 zsim.zpnc 或者 **.zpnc 么。。

@Issues-translate-bot
Copy link

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


Since you are zsim depends on zpnc . . Why is your configuration indeed add_requireconfs("**.zsim")? Shouldn't it be zsim.zpnc or **.zpnc. .

@TOMO-CAT
Copy link
Author

是这样的,这部分代码是自动生成的,一开始长这样,定义了所有直接依赖和间接依赖的版本:
image
然后 zpnc 需要用本地库做本地仿真,就注释掉了 zpnc 的 add_requires:

image
其中 zsim 依赖 zpnc,改完后 zsim 会报错找不到 zpnc

@Issues-translate-bot
Copy link

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


Yes, this part of the code is automatically generated. It looks like this at the beginning, and defines the versions of all direct dependencies and indirect dependencies:
image
Then zpnc needs to use the local library for local simulation, so we comment out the add_requires of zpnc:

image
Among them, zsim depends on zpnc. After the change, zsim will report an error that zpnc cannot be found.

@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

看不懂你的配置和需求,还是不知道你在干什么。

@Issues-translate-bot
Copy link

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


I don’t understand your configuration and requirements, or I still don’t know what you are doing.

@TOMO-CAT
Copy link
Author

看不懂你的配置和需求,还是不知道你在干什么。

举个例子说明就是,我现在有一个库,就叫仿真库吧 simulation,它依赖 A、B 两个库。然后 B 又依赖 A。

正常线上代码是直接在 simulation 里 add_requires("A version_a") add_requires("B version_b") 然后再通过 add_requireconfs("B.A") 把 B 依赖的 A 库版本也写死成 version_a。

现在我本地仿真需要将 A 和 B.A 都替换成 local package 里定义的,但是此时编译 B 找不到依赖库 A 的 latest 版本。

如果我哪里还是讲的不明白的话,我可以写个 demo 说明下。

@Issues-translate-bot
Copy link

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


I don’t understand your configuration and requirements, or I still don’t know what you are doing.

For example, I now have a library called simulation library, which depends on two libraries, A and B. Then B depends on A.

The normal online code is to add_requires("A version_a") add_requires("B version_b") directly in the simulation, and then use add_requireconfs("B.A") to hard-code the A library version that B depends on to version_a.

Now my local simulation needs to replace both A and B.A with those defined in the local package, but when compiling B, the latest version of the dependent library A cannot be found.

If I still don’t understand something, I can write a demo to explain.

@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

举个例子说明就是,我现在有一个库,就叫仿真库吧 simulation,它依赖 A、B 两个库。然后 B 又依赖 A。

说白了就是

simulation -> B -> A 
               -> A

呗。

正常线上代码是直接在 simulation 里 add_requires("A version_a") add_requires("B version_b") 然后再通过 add_requireconfs("B.A") 把 B 依赖的 A 库版本也写死成 version_a。

其实你 simulation 里,只需要 add_requires("B version_b") 就行了,B 会把 A 带进来。。没必要再去加 add_requires("A version_a")

现在我本地仿真需要将 A 和 B.A 都替换成 local package 里定义的,但是此时编译 B 找不到依赖库 A 的 latest 版本。

你 local package 里的 A 如果是 zpnc 的话,我也没看到你加任何 add_versions 配置,那当然找不到了。

@Issues-translate-bot
Copy link

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


For example, I now have a library called simulation library, which depends on two libraries A and B. Then B depends on A.

To put it bluntly, it is

simulation -> B -> A
                   -> A

chant.

The normal online code is to add_requires("A version_a") add_requires("B version_b") directly in the simulation, and then use add_requireconfs("B.A") to hard-code the A library version that B depends on to version_a.

In fact, in your simulation, you only need add_requires("B version_b") , and B will bring A in. . There is no need to add add_requires("A version_a")

Now my local simulation needs to replace both A and B.A with those defined in the local package, but when compiling B, the latest version of the dependent library A cannot be found.

If A in your local package is zpnc, I haven't seen you add any add_versions configuration, so of course it can't be found.

@TOMO-CAT
Copy link
Author

add_requires("B version_b")

但是 A 和 B 也都是 simulation 的直接依赖,所以都得带上

@Issues-translate-bot
Copy link

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


add_requires("B version_b")

But A and B are also direct dependencies of simulation, so they must be brought

@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

add_requires("B version_b")

但是 A 和 B 也都是 simulation 的直接依赖,所以都得带上

这个随你,效果一样。。跟现在的问题无关,你现在的问题是 local package 没有 add_versions

@Issues-translate-bot
Copy link

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


add_requires("B version_b")

But A and B are also direct dependencies of simulation, so they must be brought

It's up to you, the effect is the same. . It has nothing to do with the current problem. Your current problem is that local package does not have add_versions.

@TOMO-CAT
Copy link
Author

add_requires("B version_b")

但是 A 和 B 也都是 simulation 的直接依赖,所以都得带上

这个随你,效果一样。。跟现在的问题无关,你现在的问题是 local package 没有 add_versions

add_versions("latest") 吗,还是加什么 version 呢,用的是本地的代码

@Issues-translate-bot
Copy link

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


add_requires("B version_b")

But A and B are also direct dependencies of simulation, so they must be brought

This is up to you, the effect is the same. . It has nothing to do with the current problem. Your current problem is that local package does not have add_versions.

add_versions("latest"), or add some version, use local code

@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

既然你 add_requireconfs 指定了 version,就把对应 version 加进去,反正至少有一个 add_versions

@Issues-translate-bot
Copy link

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


Since you specify version in add_requireconfs, add the corresponding version. Anyway, there is at least one add_versions

@TOMO-CAT
Copy link
Author

既然你 add_requireconfs 指定了 version,就把对应 version 加进去,反正至少有一个 add_versions

但是我对 zpnc 没有指定 version,我把那两行都注释了。
image
报错也是 zsim 找不到 zpnc 的 latest version,不应该直接依赖我的 local package 吗?

@Issues-translate-bot
Copy link

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


Since you specify version in add_requireconfs, add the corresponding version. Anyway, there is at least one add_versions

But I did not specify version for zpnc, I commented out both lines.
image
The error reported is that zsim cannot find the latest version of zpnc. Shouldn't it rely directly on my local package?

@waruqi
Copy link
Member

waruqi commented Jul 19, 2024

报错也是 zsim 找不到 zpnc 的 latest version,不应该直接依赖我的 local package 吗?

就是因为已经用了你的 local package ,才会报错。。你的 local package 配置啥也没有,add_versions 没有。。。on_install 也没有,当然报错了。。

要是没用你的 local package ,用的线上有效的包,反而不会报错。。

这不是可以的么

package("zlib")
    set_sourcedir("src")
    add_versions("1.0", "xxxx")
    on_install(function (package)
    end)
package_end()

add_requires("libpng", {system = false})
add_requireconfs("libpng.zlib", {system = false})
note: install or modify (m) these packages (pass -y to skip confirm)?
  -> zlib 1.0 [from:libpng]
in xmake-repo:
  -> libpng v1.6.43

@TOMO-CAT
Copy link
Author

报错也是 zsim 找不到 zpnc 的 latest version,不应该直接依赖我的 local package 吗?

就是因为已经用了你的 local package ,才会报错。。你的 local package 配置啥也没有,add_versions 没有。。。on_install 也没有,当然报错了。。

要是没用你的 local package ,用的线上有效的包,反而不会报错。。

这不是可以的么

package("zlib")
    set_sourcedir("src")
    add_versions("1.0", "xxxx")
    on_install(function (package)
    end)
package_end()

add_requires("libpng", {system = false})
add_requireconfs("libpng.zlib", {system = false})
note: install or modify (m) these packages (pass -y to skip confirm)?
  -> zlib 1.0 [from:libpng]
in xmake-repo:
  -> libpng v1.6.43

好的感谢我试试,我琢磨下啥原理。

@TOMO-CAT
Copy link
Author

TOMO-CAT commented Aug 3, 2024

我猜是因为我定义 zpnc 的时候没有 add_versions(),只是通过版本号构造对应的 url,所以添加 local repo 的时候就走到了 xmake-repo 里定义的 zpnc(因为它没有定义 versions 所以包含了所有的 version?)。

@Issues-translate-bot
Copy link

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


I guess it's because I didn't add_versions() when I defined zpnc, I just constructed the corresponding URL through the version number, so when I added the local repo, I went to the zpnc defined in xmake-repo (because it didn't define versions, it included all version?).

@waruqi
Copy link
Member

waruqi commented Aug 4, 2024

不是,既然找到了你的包,就不会再用 xmake-repo 的包,但是你的包 没写 add_versions ,当然报错找不到 latest versions 了

@Issues-translate-bot
Copy link

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


No, now that I have found your package, I will no longer use the xmake-repo package. However, your package does not include add_versions. Of course, an error is reported that the latest versions cannot be found.

@SnowinterCat
Copy link

可以这样使用本地包:
zip包名称为:cJSON-1.7.15.zip,跟xmake.lua在同一个目录下

package("cjson")

    set_homepage("https://github.com/DaveGamble/cJSON")
    set_description("Ultralightweight JSON parser in ANSI C.")
    set_license("MIT")

    set_urls(os.scriptdir() .. "\\cJSON-$(version).zip")

    add_versions("1.7.10", "80a0584410656c8d8da2ba703744f44d7535fc4f0778d8bf4f980ce77c6a9f65")
    add_versions("1.7.14", "d797b4440c91a19fa9c721d1f8bab21078624aa9555fc64c5c82e24aa2a08221")
    add_versions("1.7.15", "c55519316d940757ef93a779f1db1ca809dbf979c551861f339d35aaea1c907c")

    add_deps("cmake")

    on_install("windows", "macosx", "linux", "iphoneos", "android", function (package)
        local configs = {"-DENABLE_CJSON_TEST=OFF"}
        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
        import("package.tools.cmake").install(package, configs)
    end)

    on_test(function (package)
        assert(package:has_cfuncs("cJSON_malloc", {includes = "cjson/cJSON.h"}))
    end)

@SnowinterCat
Copy link

只需要照着包仓库里面的改,将set_urls里面改成对应的本地路径就行了

@Issues-translate-bot
Copy link

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


Just follow the changes in the package warehouse and change set_urls to the corresponding local path.

@SnowinterCat
Copy link

不过这里的路径是Windows格式的(很久之前写的了)

set_urls(os.scriptdir() .. "\\cJSON-$(version).zip")

如果要跨操作系统兼容的话建议改成:

set_urls(path.translate(os.scriptdir() .. "/cJSON-$(version).zip"))

或者

set_urls(path.translate("$(scriptdir)/cJSON-$(version).zip"))

@Issues-translate-bot
Copy link

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


But the path here is in Windows format (written a long time ago)

set_urls(os.scriptdir() .. "\\cJSON-$(version).zip")

If you want cross-operating system compatibility, it is recommended to change it to:

set_urls(path.translate(os.scriptdir() .. "/cJSON-$(version).zip"))

or

set_urls(path.translate("$(scriptdir)/cJSON-$(version).zip"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants