summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-10-04 21:04:27 +0800
committerruki <[email protected]>2018-10-04 00:26:44 +0800
commit22a62caad1297fcb6f2239aa2429c7f38ca620f1 (patch)
tree64236130d5ebb947056cf887fd4092ff5345086e
parent922a1f5d89ddd79f9413bd4fa4c98903cfc2bdde (diff)
fix the previous package info when link conflicts
-rw-r--r--xmake/actions/require/impl/action/prefix/install.lua70
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_package.lua36
2 files changed, 72 insertions, 34 deletions
diff --git a/xmake/actions/require/impl/action/prefix/install.lua b/xmake/actions/require/impl/action/prefix/install.lua
index e6487c14a..78c6f1ed0 100644
--- a/xmake/actions/require/impl/action/prefix/install.lua
+++ b/xmake/actions/require/impl/action/prefix/install.lua
@@ -64,9 +64,10 @@ function _copy_filedirs(pattern)
end
-- do link
-function _do_link(sourcepath, destpath)
+function _do_link(sourcepath, relativepath)
-- link conflicts?
+ local destpath = path.absolute(relativepath, _g.prefixdir)
if os.islink(destpath) then
-- get the original path of destpath
@@ -74,24 +75,59 @@ function _do_link(sourcepath, destpath)
if os.isdir(sourcepath) and os.isdir(originpath) then
-- trace
- vprint("unlinking %s ..", destpath)
+ vprint("unlinking %s ..", relativepath)
+
+ -- find the prefix info file of the previous package
+ local parentdir = path.directory(originpath)
+ while parentdir and os.isdir(parentdir) and not os.isfile(path.join(parentdir, "prefixinfo.txt")) do
+ parentdir = path.directory(parentdir)
+ end
+
+ -- get the prefix info
+ local prefixfile = nil
+ local prefixinfo = nil
+ if parentdir then
+ prefixfile = path.join(parentdir, "prefixinfo.txt")
+ if os.isfile(prefixfile) then
+ prefixinfo = io.load(prefixfile)
+ end
+ end
-- remove the previous link
os.rm(destpath)
+ if prefixinfo then
+ for idx, installfile in ipairs(prefixinfo.installed) do
+ if installfile == relativepath then
+ table.remove(prefixinfo.installed, idx)
+ break
+ end
+ end
+ end
-- expand and relink the previous directories
for _, filedir in ipairs(os.filedirs(path.join(originpath, "*"))) do
+ -- get file or directory name
+ local filename = path.filename(filedir)
+
-- trace
- vprint("relinking %s ..", path.join(destpath, path.filename(filedir)))
+ vprint("relinking %s ..", path.join(relativepath, filename))
-- do link
- os.ln(filedir, path.join(destpath, path.filename(filedir)))
+ os.ln(filedir, path.join(destpath, filename))
+
+ -- save this relative path
+ table.insert(prefixinfo.installed, path.join(relativepath, filename))
+ end
+
+ -- update the previous prefix info file
+ if prefixinfo then
+ io.save(prefixfile, prefixinfo)
end
-- link the child pathes
for _, filedir in ipairs(os.filedirs(path.join(sourcepath, "*"))) do
- _do_link(filedir, path.join(destpath, path.filename(filedir)))
+ _do_link(filedir, path.join(relativepath, path.filename(filedir)))
end
else
-- link conflicts
@@ -101,35 +137,26 @@ function _do_link(sourcepath, destpath)
-- link the child pathes
for _, filedir in ipairs(os.filedirs(path.join(sourcepath, "*"))) do
- _do_link(filedir, path.join(destpath, path.filename(filedir)))
+ _do_link(filedir, path.join(relativepath, path.filename(filedir)))
end
else
-- trace
- vprint("linking %s ..", destpath)
+ vprint("linking %s ..", relativepath)
-- do link
os.ln(sourcepath, destpath)
+
+ -- save this relative path
+ table.insert(_g.relative_pathes, relativepath)
end
end
-- link files to the prefix directory
function _link(mode, pattern)
-
- -- do install
- local prefixdir = _g.prefixdir
- local installdir = _g.installdir
- local relative_pathes = _g.relative_pathes
+ local installdir = _g.installdir
for _, sourcepath in ipairs(os.match(path.join(installdir, pattern), mode)) do
-
- -- get relative path
- local relative_path = path.relative(sourcepath, installdir)
-
- -- link file to the prefix directory
- _do_link(sourcepath, path.absolute(relative_path, prefixdir))
-
- -- save this relative path
- table.insert(relative_pathes, relative_path)
+ _do_link(sourcepath, path.relative(sourcepath, installdir))
end
end
@@ -207,6 +234,7 @@ function main(package)
-- save the prefix info to file
local prefixinfo = package:prefixinfo()
prefixinfo.installed = _g.relative_pathes
+ prefixinfo.prefixdir = _g.prefixdir
io.save(package:prefixfile(), prefixinfo)
-- register this package
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
index 57d57d6d1..507ed5847 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
@@ -155,10 +155,16 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
local links = {}
local linkdirs = {}
local includedirs = {}
- local prefixinfo = {}
- if prefixfile then
+ local prefixinfo = (prefixfile and os.isfile(prefixfile) and io.load(prefixfile)) or nil
+ if prefixinfo then
- prefixinfo = io.load(prefixfile) or {}
+ -- get prefix directory of this package
+ local prefixdir = prefixinfo.prefixdir
+ if not prefixdir then
+ prefixdir = path.directory(path.directory(path.directory(path.directory(prefixfile)))):gsub("installed", "prefix")
+ end
+
+ -- get link and include directories
for _, includedir in ipairs(table.wrap(prefixinfo.includedirs)) do
table.insert(includedirs, path.join(prefixdir, includedir))
end
@@ -175,9 +181,7 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
if line:endswith(".lib") or line:endswith(".a") then
found = true
if not prefixinfo.linkdirs then
- for _, prefixdir in ipairs(prefixdirs) do
- table.insert(linkdirs, path.join(prefixdir, path.directory(line)))
- end
+ table.insert(linkdirs, path.join(prefixdir, path.directory(line)))
end
if not prefixinfo.links then
table.insert(links, target.linkname(path.filename(line)))
@@ -189,9 +193,7 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
line = line:trim()
if line:endswith(".so") or line:endswith(".dylib") then
if not prefixinfo.linkdirs then
- for _, prefixdir in ipairs(prefixdirs) do
- table.insert(linkdirs, path.join(prefixdir, path.directory(line)))
- end
+ table.insert(linkdirs, path.join(prefixdir, path.directory(line)))
end
if not prefixinfo.links then
table.insert(links, target.linkname(path.filename(line)))
@@ -200,16 +202,24 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
end
end
end
- end
- -- add root include and link directories
- for _, prefixdir in ipairs(prefixdirs) do
+ -- add root include and link directories
if #linkdirs == 0 then
table.insert(linkdirs, path.join(prefixdir, "lib"))
end
if #includedirs == 0 then
table.insert(includedirs, path.join(prefixdir, "include"))
end
+ else
+ -- add root include and link directories
+ for _, prefixdir in ipairs(prefixdirs) do
+ if #linkdirs == 0 then
+ table.insert(linkdirs, path.join(prefixdir, "lib"))
+ end
+ if #includedirs == 0 then
+ table.insert(includedirs, path.join(prefixdir, "include"))
+ end
+ end
end
-- uses name as links directly .e.g libname.a
@@ -239,7 +249,7 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
-- inherit the other prefix variables
for name, values in pairs(prefixinfo) do
- if name ~= "links" and name ~= "linkdirs" and name ~= "includedirs" and name ~= "installed" then
+ if name ~= "links" and name ~= "linkdirs" and name ~= "includedirs" and name ~= "installed" and name ~= "prefixdir" then
result[name] = values
end
end