summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-31 12:51:20 +0800
committerGitHub <[email protected]>2022-08-31 12:51:20 +0800
commitcfb302ba06a479ffddcf28e8acf727bea5d638fa (patch)
tree7191ddbb89c4812cf0b28f2e7aa5d3027363adad /xmake
parent3e398cf349c1ff3b9e9ebfa92f9dff99dfa8a97f (diff)
parent6046e78b4d3ba893ef99f3e821736830dca1e5c2 (diff)
Merge pull request #2745 from xmake-io/symlink
improve symlink
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/os.lua25
-rw-r--r--xmake/rules/xcode/application/build.lua24
-rw-r--r--xmake/rules/xcode/framework/xmake.lua4
3 files changed, 17 insertions, 36 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 271e5546d..b67a497d1 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -67,8 +67,9 @@ function os._cp(src, dst, rootdir, opt)
end
end
- -- is file?
- if os.isfile(src) or os.islink(src) then
+ -- is file or link?
+ local symlink = opt and opt.symlink
+ if os.isfile(src) or (symlink and os.islink(src)) then
-- the destination is directory? append the filename
if os.isdir(dst) or path.islastsep(dst) then
@@ -79,16 +80,14 @@ function os._cp(src, dst, rootdir, opt)
end
end
- -- link file if reserve symlink
- if opt and opt.symlink and os.islink(src) then
- local reallink = os.readlink(src)
- if not os.link(reallink, dst) then
- return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, os.strerror())
- end
- else
- -- copy file
- if not os.cpfile(src, dst) then
- return false, string.format("cannot copy file %s to %s, %s", src, dst, os.strerror())
+ -- copy or link file
+ if not os.cpfile(src, dst, symlink) then
+ local errors = os.strerror()
+ if symlink and os.islink(src) then
+ local reallink = os.readlink(src)
+ return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, errors)
+ else
+ return false, string.format("cannot copy file %s to %s, %s", src, dst, errors)
end
end
-- is directory?
@@ -104,7 +103,7 @@ function os._cp(src, dst, rootdir, opt)
end
-- copy directory
- if not os.cpdir(src, dst) then
+ if not os.cpdir(src, dst, symlink) then
return false, string.format("cannot copy directory %s to %s, %s", src, dst, os.strerror())
end
diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua
index 8089be966..fba9f319f 100644
--- a/xmake/rules/xcode/application/build.lua
+++ b/xmake/rules/xcode/application/build.lua
@@ -25,25 +25,6 @@ import("core.project.depend")
import("private.tools.codesign")
import("utils.progress")
--- copy frameworks with symlink
---
--- TODO we should improve os.cp to support for copying directory with symlink
--- os.vcp(frameworkdir, frameworksdir, {symlink = true})
-function copy_frameworks(frameworkdir, frameworksdir)
- os.mkdir(frameworksdir)
- local frameworkdir_dst = path.join(frameworksdir, path.filename(frameworkdir))
- os.tryrm(frameworkdir_dst)
- for _, filepath in ipairs(os.filedirs(path.join(frameworkdir, "*"))) do
- if path.filename(filepath) == "Versions" then
- copy_frameworks(filepath, frameworkdir_dst)
- else
- local dstpath = path.join(frameworkdir_dst, path.filename(filepath))
- os.tryrm(dstpath)
- os.cp(filepath, dstpath, {symlink = true})
- end
- end
-end
-
-- main entry
function main (target, opt)
@@ -77,7 +58,10 @@ function main (target, opt)
if dep:kind() == "shared" then
local frameworkdir = dep:data("xcode.bundle.rootdir")
if dep:rule("xcode.framework") and frameworkdir then
- copy_frameworks(frameworkdir, frameworksdir, {symlink = true})
+ if not os.isdir(frameworkdir) then
+ os.mkdir(frameworksdir)
+ end
+ os.cp(frameworkdir, frameworksdir, {symlink = true})
else
os.vcp(dep:targetfile(), binarydir)
end
diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua
index 687b67208..6fffa8f46 100644
--- a/xmake/rules/xcode/framework/xmake.lua
+++ b/xmake/rules/xcode/framework/xmake.lua
@@ -172,9 +172,7 @@ rule("xcode.framework")
if not os.isdir(installdir) then
os.mkdir(installdir)
end
- -- TODO we should improve os.cp to support symlink
- --os.vcp(bundledir, installdir, {symlink = true})
- appbuild.copy_frameworks(bundledir, installdir)
+ os.vcp(bundledir, installdir, {symlink = true})
end
end)