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

开启soname时多次调用xmake导致编译产物被删除 #4706

Closed
xu-h opened this issue Feb 5, 2024 · 14 comments
Closed

开启soname时多次调用xmake导致编译产物被删除 #4706

xu-h opened this issue Feb 5, 2024 · 14 comments
Labels
Milestone

Comments

@xu-h
Copy link

xu-h commented Feb 5, 2024

Xmake 版本

2.8.6

操作系统版本和架构

Ubuntu (Windows 11 WSL2)

描述问题

使用 set_version 设置版本号并设置 soname=true 时,在未做修改的情况下多次调用xmake导致编译产物被删除。

检查 soname 实现逻辑发现以下代码在 after_link 阶段被执行:

if soname ~= filename and soname ~= path.filename(targetfile_with_version) then
    os.cp(target:targetfile(), targetfile_with_version)
    os.rm(target:targetfile())
    local oldir = os.cd(target:targetdir())
    os.ln(path.filename(targetfile_with_version), soname, {force = true})
    os.ln(soname, path.filename(targetfile), {force = true})
    os.cd(oldir)
end

上述代码执行完成后,targetfile被变为指向重命名后编译产物的软链接。重复调用xmake时,由于没有检测到修改,targetfile未被更新,再次执行上述逻辑,编译产物在targetfile重命名的过程中被覆盖。

期待的结果

多次调用xmake不更新targetfile

工程配置

set_project("test")
set_version("2.0", {soname = "2", build = "%Y%m%d"})

附加信息和错误日志

@xu-h xu-h added the bug label Feb 5, 2024
@Issues-translate-bot
Copy link

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


Title: When soname is turned on, calling xmake multiple times causes the compiled product to be deleted.

@waruqi
Copy link
Member

waruqi commented Feb 6, 2024

这里 ok,没法复现,如果代码没改,targetfile 不更新,按理 after_link 都不会被执行才对。。

ruki@0d35ffa77272:/mnt/xmake/tests/projects/c++/shared_library_with_soname$ tree build/
build/
`-- linux
    `-- x86_64
        `-- release
            |-- libfoo.so -> libfoo.so.1
            |-- libfoo.so.1 -> libfoo.so.1.0.1
            |-- libfoo.so.1.0.1
            `-- tests

3 directories, 4 files
ruki@0d35ffa77272:/mnt/xmake/tests/projects/c++/shared_library_with_soname$ xmake
libfoo.so.1
[100%]: build ok, spent 0.311s
ruki@0d35ffa77272:/mnt/xmake/tests/projects/c++/shared_library_with_soname$ tree build/
build/
`-- linux
    `-- x86_64
        `-- release
            |-- libfoo.so -> libfoo.so.1
            |-- libfoo.so.1 -> libfoo.so.1.0.1
            |-- libfoo.so.1.0.1
            `-- tests

3 directories, 4 files

@Issues-translate-bot
Copy link

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


This is ok, but it cannot be reproduced. If the code is not changed and the targetfile is not updated, then after_link will not be executed. .

ruki@0d35ffa77272:/mnt/xmake/tests/projects/c++/shared_library_with_soname$ tree build/
build/
`--linux
    `-- x86_64
        `-- release
            |-- libfoo.so -> libfoo.so.1
            |-- libfoo.so.1 -> libfoo.so.1.0.1
            |-- libfoo.so.1.0.1
            `--tests

3 directories, 4 files
ruki@0d35ffa77272:/mnt/xmake/tests/projects/c++/shared_library_with_soname$ xmake
libfoo.so.1
[100%]: build ok, spent 0.311s
ruki@0d35ffa77272:/mnt/xmake/tests/projects/c++/shared_library_with_soname$ tree build/
build/
`--linux
    `-- x86_64
        `-- release
            |-- libfoo.so -> libfoo.so.1
            |-- libfoo.so.1 -> libfoo.so.1.0.1
            |-- libfoo.so.1.0.1
            `--tests

3 directories, 4 files

@waruqi
Copy link
Member

waruqi commented Feb 6, 2024

提供个完整可复现的 demo 过来

@Issues-translate-bot
Copy link

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


Provide a complete and reproducible demo.

@xu-h
Copy link
Author

xu-h commented Feb 6, 2024

xmake.lua:

set_version("1.0.2", {soname = "1", build = "%Y%m%d"})

target("foo")
    set_kind("shared")
    add_files("src/*.c")

src/main.c:

#include <stdio.h>

void print()
{
    printf("hello world!\n");
}

复现:

❯ xmake -r
[ 25%]: cache compiling.release src/main.c
[ 50%]: linking.release libfoo.so
[100%]: build ok, spent 0.076s
❯ tree build
build
└── linux
    └── x86_64
        └── release
            ├── libfoo.so -> libfoo.so.1
            ├── libfoo.so.1 -> libfoo.so.1.0.2
            └── libfoo.so.1.0.2

3 directories, 3 files
❯ ls -lh build/linux/x86_64/release/
total 16K
lrwxrwxrwx 1 xuh xuh  11 Feb  6 17:01 libfoo.so -> libfoo.so.1
lrwxrwxrwx 1 xuh xuh  15 Feb  6 17:01 libfoo.so.1 -> libfoo.so.1.0.2
-rwxr-xr-x 1 xuh xuh 16K Feb  6 17:01 libfoo.so.1.0.2
❯ xmake
[100%]: build ok, spent 0.008s
❯ tree build
build
└── linux
    └── x86_64
        └── release
            ├── libfoo.so -> libfoo.so.1
            ├── libfoo.so.1 -> libfoo.so.1.0.2
            └── libfoo.so.1.0.2

3 directories, 3 files
❯ ls -lh build/linux/x86_64/release/
total 0
lrwxrwxrwx 1 xuh xuh 11 Feb  6 17:02 libfoo.so -> libfoo.so.1
lrwxrwxrwx 1 xuh xuh 15 Feb  6 17:02 libfoo.so.1 -> libfoo.so.1.0.2
-rwxr-xr-x 1 xuh xuh  0 Feb  6 17:02 libfoo.so.1.0.2

之前表述不太准确,第二次执行xmake后,libfoo.so.1.0.2变为空文件

@waruqi
Copy link
Member

waruqi commented Feb 6, 2024

再试试 xmake update -s dev

@Issues-translate-bot
Copy link

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


Try xmake update -s dev again

@xu-h
Copy link
Author

xu-h commented Feb 6, 2024

更新后动态库被覆盖的问题已解决。但现在只修改xmake.lua中版本号,对应的库不会被更新。

复现:

❯ ls -lh build/linux/x86_64/release/
total 16K
lrwxrwxrwx 1 xuh xuh  11 Feb  6 23:38 libfoo.so -> libfoo.so.1
lrwxrwxrwx 1 xuh xuh  15 Feb  6 23:38 libfoo.so.1 -> libfoo.so.1.0.2
-rwxr-xr-x 1 xuh xuh 16K Feb  6 23:38 libfoo.so.1.0.2
❯ nvim xmake.lua
❯ cat xmake.lua
set_version("1.0.3", { soname = "1", build = "%Y%m%d" })

target("foo")
set_kind("shared")
add_files("src/*.c")
❯ xmake
[100%]: build ok, spent 0.164s
❯ ls -lh build/linux/x86_64/release/
total 16K
lrwxrwxrwx 1 xuh xuh  11 Feb  6 23:38 libfoo.so -> libfoo.so.1
lrwxrwxrwx 1 xuh xuh  15 Feb  6 23:38 libfoo.so.1 -> libfoo.so.1.0.2
-rwxr-xr-x 1 xuh xuh 16K Feb  6 23:38 libfoo.so.1.0.2

@Issues-translate-bot
Copy link

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


The problem of dynamic libraries being overwritten after the update has been solved. But now only the version number in xmake.lua is modified, and the corresponding library will not be updated.

recurrent:

❯ ls -lh build/linux/x86_64/release/
total 16K
lrwxrwxrwx 1 xuh xuh 11 Feb 6 23:38 libfoo.so -> libfoo.so.1
lrwxrwxrwx 1 xuh xuh 15 Feb 6 23:38 libfoo.so.1 -> libfoo.so.1.0.2
-rwxr-xr-x 1 xuh xuh 16K Feb 6 23:38 libfoo.so.1.0.2
❯ nvimxmake.lua
❯ cat xmake.lua
set_version("1.0.3", { soname = "1", build = "%Y%m%d" })

target("foo")
set_kind("shared")
add_files("src/*.c")
❯ xmake
[100%]: build ok, spent 0.164s
❯ ls -lh build/linux/x86_64/release/
total 16K
lrwxrwxrwx 1 xuh xuh 11 Feb 6 23:38 libfoo.so -> libfoo.so.1
lrwxrwxrwx 1 xuh xuh 15 Feb 6 23:38 libfoo.so.1 -> libfoo.so.1.0.2
-rwxr-xr-x 1 xuh xuh 16K Feb 6 23:38 libfoo.so.1.0.2

@waruqi
Copy link
Member

waruqi commented Feb 7, 2024

再试试

@Issues-translate-bot
Copy link

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


try again

@xu-h
Copy link
Author

xu-h commented Feb 7, 2024

没问题了。感谢。祝春节快乐。

@xu-h xu-h closed this as completed Feb 7, 2024
@Issues-translate-bot
Copy link

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


No problem. grateful. Happy Chinese New Year.

@waruqi waruqi added this to the v2.8.7 milestone Feb 7, 2024
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

3 participants