summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-09-12 00:45:05 +0800
committerruki <[email protected]>2018-09-11 22:30:34 +0800
commit26271fd2ef89939e415d6ab206a413358b9045d4 (patch)
tree09562e38ef62fb874508832d9c861525d4b2fab2
parentf79eb8dfdb0e94aec8d656cdc1f3fe88cc040d40 (diff)
improve to install package
-rw-r--r--xmake/actions/require/action/build.lua175
-rw-r--r--xmake/actions/require/action/install.lua13
-rw-r--r--xmake/actions/require/info.lua3
-rw-r--r--xmake/core/sandbox/modules/import/core/package/repository.lua11
4 files changed, 25 insertions, 177 deletions
diff --git a/xmake/actions/require/action/build.lua b/xmake/actions/require/action/build.lua
index 74e53c587..878e7f10f 100644
--- a/xmake/actions/require/action/build.lua
+++ b/xmake/actions/require/action/build.lua
@@ -28,179 +28,6 @@ import("core.project.config")
import("core.sandbox.sandbox")
import("filter")
--- build for xmake file
-function _build_for_xmakefile(package, buildfile)
-
- -- init argv
- local plat = config.plat()
- local argv = {"f", "-c", "-p", plat, "-a", config.arch(), "-m", config.mode()}
-
- -- verbose?
- if option.get("verbose") then
- table.insert(argv, "-v")
- end
-
- -- init config keys
- local keys =
- {
- android = {"ndk", "ndk_sdkver"},
- linux = {"sdk", "cross", "toolchains"},
- cross = {"sdk", "cross", "toolchains"},
- mingw = {"sdk", "cross", "toolchains"},
- macosx = {"xcode", "xcode_sdkver"},
- iphoneos = {"xcode", "xcode_sdkver"},
- windows = {"vs"}
- }
-
- -- inherit some configs
- for _, key in ipairs(keys[plat]) do
- local val = config.get(key)
- if val ~= nil then
- table.insert(argv, "--" .. key .. "=" .. tostring(val))
- end
- end
-
- -- configure it first
- os.vrunv("xmake", argv)
-
- -- build it
- if option.get("verbose") then
- os.vrun("xmake -v")
- else
- os.vrun("xmake")
- end
-end
-
--- build for makefile
-function _build_for_makefile(package, buildfile)
-
- -- only for host platform now
- assert(os.host() == config.plat() and os.arch() == config.arch())
-
- -- build it
- os.vrun("make")
-end
-
--- build for configure
-function _build_for_configure(package, buildfile)
-
- -- only for host platform now
- assert(os.host() == config.plat() and os.arch() == config.arch())
-
- -- make prefix directory
- os.mkdir(".prefix")
-
- -- configure it first
- os.vrun("./configure --prefix=%s", path.absolute(".prefix"))
-
- -- build it
- os.vrun("make")
-
- -- install to .prefix
- os.vrun("make install")
-end
-
--- build for cmakelist
-function _build_for_cmakelists(package, buildfile)
-
- -- only for host platform now
- assert(os.host() == config.plat() and os.arch() == config.arch())
-
- -- make makefile first
- --
- -- @note it will only attempt to build, so we need install cmake manually first if we want to build it successfully
- --
- os.vrun("cmake -DCMAKE_INSTALL_PREFIX=%s .", path.absolute(".prefix"))
-
- -- build on windows
- if os.host() == "windows" then
- local slnfiles = os.files("*.sln")
- if slnfiles and #slnfiles > 0 then
- _build_for_sln(package, slnfiles[1])
- return
- end
- end
-
- -- build it
- os.vrun("make")
-
- -- install to .prefix
- os.vrun("make install")
-end
-
--- build for *.sln
-function _build_for_sln(package, buildfile)
-
- -- only for host platform now
- assert(os.host() == config.plat())
-
- -- TODO handle arch and mode
- -- build it for windows
- if config.plat() == "windows" then
- os.vrun("msbuild %s -nologo -t:Rebuild -p:Configuration=Release", buildfile)
- return
- end
-
- -- continue to attempt to build using other tools
- raise()
-end
-
--- on build the given package
-function _on_build_package(package)
-
- -- TODO *.vcproj, premake.lua, scons, autogen.sh, Makefile.am, ...
- -- init build scripts
- local buildscripts =
- {
- {"xmake.lua", _build_for_xmakefile }
- , {"*.sln", _build_for_sln }
- , {"CMakeLists.txt", _build_for_cmakelists }
- , {"configure", _build_for_configure }
- , {"[mM]akefile", _build_for_makefile }
- }
-
- -- attempt to build it
- for _, buildscript in pairs(buildscripts) do
-
- -- save the current directory
- local oldir = os.curdir()
-
- -- try building
- local ok = try
- {
- function ()
-
- -- attempt to build it if file exists
- local files = os.files(buildscript[1])
- if #files > 0 then
- buildscript[2](package, files[1])
- return true
- end
- end,
-
- catch
- {
- function (errors)
-
- -- trace verbose info
- if errors then
- vprint(errors)
- end
- end
- }
- }
-
- -- restore directory
- os.cd(oldir)
-
- -- ok?
- if ok then return end
- end
-
- -- failed
- raise("attempt to build package %s failed!", package:name())
-end
-
-- build the given package
function main(package)
@@ -208,7 +35,7 @@ function main(package)
local scripts =
{
package:script("build_before")
- , package:script("build", _on_build_package)
+ , package:script("build")
, package:script("build_after")
}
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua
index 08782d20f..620327f89 100644
--- a/xmake/actions/require/action/install.lua
+++ b/xmake/actions/require/action/install.lua
@@ -110,6 +110,16 @@ option("%s")
end
end
+-- prepare directories
+function _prepare_directories(...)
+ for _, dir in ipairs({...}) do
+ os.tryrm(dir)
+ if not os.isdir(dir) then
+ os.mkdir(dir)
+ end
+ end
+end
+
-- install the given package
function main(package)
@@ -156,6 +166,9 @@ function main(package)
-- create the install task
local installtask = function ()
+ -- prepare the install and package directories
+ _prepare_directories(package:installdir(), package:directory())
+
-- build it
build(package)
diff --git a/xmake/actions/require/info.lua b/xmake/actions/require/info.lua
index 1a64f5393..6398a240f 100644
--- a/xmake/actions/require/info.lua
+++ b/xmake/actions/require/info.lua
@@ -99,6 +99,9 @@ function main(requires)
-- show install directory
cprint(" -> ${magenta}installdir${clear}: %s", instance:installdir())
+
+ -- show package directory
+ cprint(" -> ${magenta}packagedir${clear}: %s", instance:directory())
end
-- leave environment
diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua
index 16fab448a..499d2e902 100644
--- a/xmake/core/sandbox/modules/import/core/package/repository.lua
+++ b/xmake/core/sandbox/modules/import/core/package/repository.lua
@@ -88,9 +88,9 @@ function sandbox_core_package_repository.repositories(is_global)
fasturl.add(mainurls)
mainurls = fasturl.sort(mainurls)
- -- add main urls
- for _, mainurl in ipairs(mainurls) do
- local repo = repository.load("xmake-repo", mainurl, true)
+ -- add main url
+ if #mainurls > 0 then
+ local repo = repository.load("xmake-repo", mainurls[1], true)
if repo then
table.insert(repositories, repo)
end
@@ -107,6 +107,11 @@ function sandbox_core_package_repository.repositories(is_global)
end
-- load repositories from project file
+ --
+ -- in project xmake.lua:
+ --
+ -- add_repositories("other-repo https://github.com/other/other-repo.git")
+ --
if not is_global then
for _, repo in ipairs(table.wrap(project.get("repositories"))) do
local repoinfo = repo:split(' ')