From d9021ad4c05a4f968979d948ab40aa9dd89a363f Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Wed, 8 Sep 2021 14:27:20 +0200 Subject: Improve install --- xmake/modules/target/action/install/unix.lua | 20 ++++++++++++++------ xmake/modules/target/action/install/windows.lua | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/xmake/modules/target/action/install/unix.lua b/xmake/modules/target/action/install/unix.lua index ae06ed3bc..521ed40de 100644 --- a/xmake/modules/target/action/install/unix.lua +++ b/xmake/modules/target/action/install/unix.lua @@ -37,15 +37,23 @@ end -- install shared libraries for package function _install_shared_for_package(target, pkg, outputdir) + _g.installed_libfiles = _g.installed_libfiles or {} for _, sopath in ipairs(table.wrap(pkg:get("libfiles"))) do if sopath:endswith(".so") or sopath:match(".+%.so%..+$") or sopath:endswith(".dylib") then - local soname = path.filename(sopath) - if os.isfile(path.join(outputdir, soname)) then - wprint("'%s' already exists in install dir, overwriting it from package(%s).", soname, pkg:name()) + -- prevent packages using the same system libfiles from overwriting each other + if not _g.installed_libfiles[sopath] then + local soname = path.filename(sopath) + local targetname = path.join(outputdir, soname) + if os.isfile(targetname) then + wprint("'%s' already exists in install dir, overwriting it from package(%s).", soname, pkg:name()) + -- rm because symlink cannot overwrite existing file + os.rm(targetname) + end + -- we need reserve symlink + -- @see https://github.com/xmake-io/xmake/issues/1582 + os.vcp(sopath, outputdir, {symlink = true}) + _g.installed_libfiles[sopath] = true end - -- we need reserve symlink - -- @see https://github.com/xmake-io/xmake/issues/1582 - os.vcp(sopath, outputdir, {symlink = true}) end end end diff --git a/xmake/modules/target/action/install/windows.lua b/xmake/modules/target/action/install/windows.lua index dfb8d2bd3..609e87389 100644 --- a/xmake/modules/target/action/install/windows.lua +++ b/xmake/modules/target/action/install/windows.lua @@ -40,13 +40,18 @@ end -- install shared libraries for package function _install_shared_for_package(target, pkg, outputdir) + _g.installed_dllfiles = _g.installed_dllfiles or {} for _, dllpath in ipairs(table.wrap(pkg:get("libfiles"))) do if dllpath:endswith(".dll") then - local dllname = path.filename(dllpath) - if os.isfile(path.join(outputdir, dllname)) then - wprint("'%s' already exists in install dir, overwriting it from package(%s).", dllname, pkg:name()) + -- prevent packages using the same libfiles from overwriting each other + if not _g.installed_dllfiles[dllpath] then + local dllname = path.filename(dllpath) + if os.isfile(path.join(outputdir, dllname)) then + wprint("'%s' already exists in install dir, overwriting it from package(%s).", dllname, pkg:name()) + end + os.vcp(dllpath, outputdir) + _g.installed_dllfiles[dllpath] = true end - os.vcp(dllpath, outputdir) end end end @@ -74,11 +79,15 @@ function install_binary(target, opt) -- install the dependent shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/961 + _g.installed_dllfiles = _g.installed_dllfiles or {} for _, dep in ipairs(target:orderdeps()) do if dep:kind() == "shared" then local depfile = dep:targetfile() if os.isfile(depfile) then - os.vcp(depfile, binarydir) + if not _g.installed_dllfiles[depfile] then + os.vcp(depfile, binarydir) + _g.installed_dllfiles[depfile] = true + end end end -- install all shared libraries in packages in all deps -- cgit v1.3.1