xmake-io / xmake

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

Cannot override package descriptions in a remote xmake-repo added by `add_repositories` #5840

Open for2years opened 6 days ago

for2years commented 6 days ago

Xmake Version

v2.9.6

Operating System Version and Architecture

wsl ubuntu 2204

Describe Bug

I have a project that references a remote xmake-repo containing many packages. However, I need to locally debug one of the packages, and I found that I cannot override the package description from the remote xmake-repo.

-- this remote repo contains a log of packages
add_repositories("my-repo https://github.com/for-2-years/xmake-repo.git")

-- I want to override a specific package to debug
package("my-package", function()
    set_policy("package.install_always", true)
    set_sourcedir("/root/my-package-dir")
    on_install(function(package)
        import("package.tools.xmake").install(package)
    end)
end)

Is there a way to prioritize local package descriptions over those in the remote repository?

After debugging the xmake source code, I found that this function merges the packages defined in the project with those defined in the remote repository.

-- load the package from the project file
function package.load_from_project(packagename, project)

    -- get it directly from cache first
    local instance = package._memcache():get2("packages", packagename)
    if instance then
        return instance
    end

    -- load packages (with cache) 
    local packages, errors = project.packages()
    if not packages then
        return nil, errors
    end

    -- get package info
    local packageinfo = packages[packagename]
    if not packageinfo then
        return
    end

    -- new an instance
    instance = _instance.new(packagename, packageinfo)
    package._memcache():set2("packages", instance)
    return instance
end

https://github.com/xmake-io/xmake/blob/959106bc784e0a8c218c331970afc25bed52e9c6/xmake/core/package/package.lua#L2955

Expected Behavior

I can override a remote-repo package description by a local package.

Project Configuration

none

Additional Information and Error Logs

none

smac89 commented 6 days ago

I don't think there is a way to do this from within the project file itself. You have to create a custom repo, copy the original xmake.lua file in there and configure your project to use it.

See https://xmake.io/#/package/remote_package?id=using-self-built-private-package-repository

After this you can run xmake require --info my-package, and it will show you where the package will be retrieved from.

waruqi commented 6 days ago

you can use set_base to do it. see https://xmake.io/#/manual/package_dependencies?id=packageset_base

for2years commented 6 days ago

I don't think there is a way to do this from within the project file itself. You have to create a custom repo, copy the original xmake.lua file in there and configure your project to use it.

See https://xmake.io/#/package/remote_package?id=using-self-built-private-package-repository

After this you can run xmake require --info my-package, and it will show you where the package will be retrieved from.

this remote repo contains a log of packages so I don't want to do this. but thanks for your idea anyway.