summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-04-17 22:47:26 +0800
committerruki <[email protected]>2023-04-17 22:47:26 +0800
commit52e41c376c5cd183af01849dca184ead710048b6 (patch)
treecf04cd55011b8411218ee9ef6f9badd02791e4c1
parentc11fce61b392aa59dfb269960c201015db6c3f8c (diff)
improve longpaths policy for package
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua62
1 files changed, 45 insertions, 17 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 8d24b050e..dbb4d26c9 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -246,8 +246,8 @@ function _clear_sourcedir(package)
end
end
--- install the given package
-function main(package)
+-- enter working directory
+function _enter_workdir(package)
-- get working directory of this package
local workdir = package:cachedir()
@@ -255,7 +255,7 @@ function main(package)
-- lock this package
package:lock()
- -- enter the working directory
+ -- enter directory
local oldir = nil
local sourcedir = package:sourcedir()
if sourcedir then
@@ -275,6 +275,47 @@ function main(package)
oldir = os.cd(workdir)
end
+ -- we need copy source codes to the working directory with short path on windows
+ --
+ -- Because the target name and source file path of this project are too long,
+ -- it's absolute path exceeds the windows path length limit.
+ --
+ if is_host("windows") and package:policy("platform.longpaths") then
+ local sourcedir_tmp = os.tmpdir() .. ".dir"
+ os.tryrm(sourcedir_tmp)
+ os.cp(os.curdir(), sourcedir_tmp)
+ os.cd(sourcedir_tmp)
+ end
+
+ return oldir
+end
+
+-- leave working directory
+function _leave_workdir(package, oldir)
+
+ -- clean the empty package directory
+ local installdir = package:installdir()
+ if os.emptydir(installdir) then
+ os.tryrm(installdir)
+ end
+
+ -- unlock this package
+ package:unlock()
+
+ -- leave source codes directory
+ if oldir then
+ os.cd(oldir)
+ end
+
+ -- clean source directory if it is no longer needed
+ _clear_sourcedir(package)
+end
+
+function main(package)
+
+ -- enter working directory
+ local oldir = _enter_workdir(package)
+
-- init tipname
local tipname = package:name()
if package:version_str() then
@@ -432,19 +473,6 @@ function main(package)
}
}
- -- clean the empty package directory
- local installdir = package:installdir()
- if os.emptydir(installdir) then
- os.tryrm(installdir)
- end
-
- -- unlock this package
- package:unlock()
-
- -- leave source codes directory
- os.cd(oldir)
-
- -- clean source directory if it is no longer needed
- _clear_sourcedir(package)
+ _leave_workdir(package, oldir)
return ok
end