diff options
| author | ruki <[email protected]> | 2017-09-19 22:48:11 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-19 10:49:09 +0800 |
| commit | 32423290638ffa3963d131abbb4280bd4f3baa53 (patch) | |
| tree | bde9e7881230b215a18185fcb74b1d2b4bfe3692 | |
| parent | 48e86182ee1b3a73f5c16e2fbb2fdebfe5c75d89 (diff) | |
add kind for package
| -rw-r--r-- | xmake/actions/require/action/install.lua | 11 | ||||
| -rw-r--r-- | xmake/actions/require/install.lua | 50 | ||||
| -rw-r--r-- | xmake/actions/require/repository.lua | 12 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 56 | ||||
| -rw-r--r-- | xmake/core/package/repository.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 2 | ||||
| -rw-r--r-- | xmake/packages/git/xmake.lua | 9 |
7 files changed, 100 insertions, 42 deletions
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index 857849c07..3f7bc0caa 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -198,6 +198,7 @@ function main(package) -- get working directory of this package local workdir = package:cachedir() + -- TODO -- enter source files directory local oldir = nil for _, srcdir in ipairs(os.dirs(path.join(workdir, "source", "*"))) do @@ -205,8 +206,14 @@ function main(package) break end + -- init tipname + local tipname = package:fullname() + if package:version_str() then + tipname = tipname .. "-" .. package:version_str() + end + -- trace - cprintf("${yellow} => ${clear}installing %s-%s .. ", package:fullname(), package:version_str()) + cprintf("${yellow} => ${clear}installing %s .. ", tipname) if option.get("verbose") then print("") end @@ -247,7 +254,7 @@ function main(package) end -- fetch package - assert(package:fetch(), "fetch %s-%s failed!", package:fullname(), package:version_str()) + assert(package:fetch(), "fetch %s failed!", tipname) -- trace cprint("${green}ok") diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index fdf38f7c1..6d16de732 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -26,6 +26,7 @@ import("core.base.option") import("core.base.task") import("core.project.project") +import("detect.tools.find_git") import("action") import("package") import("repository") @@ -63,9 +64,11 @@ end function _attach_to_targets(packages) for _, instance in ipairs(packages) do - local opt = project.option(instance:fullname()) - if opt and opt:enabled() then - _attach_to_option(instance, opt) + if instance:kind() ~= "binary" then + local opt = project.option(instance:fullname()) + if opt and opt:enabled() then + _attach_to_option(instance, opt) + end end end end @@ -96,11 +99,7 @@ function _check_missing_packages(packages) end -- install packages -function main(requires) - - -- avoid to run this task repeatly - if _g.installed then return end - _g.installed = true +function _install_packages(requires) -- init requires local requires_extra = nil @@ -111,12 +110,11 @@ function main(requires) return end - -- TODO - -- enter environment - environment.enter() - -- pull all repositories first if not exists - if not repository.exists() then + -- + -- attempt to install git from the builtin-packages first if git not found + -- + if find_git() and not repository.pulled() then task.run("repo", {update = true}) end @@ -175,9 +173,31 @@ function main(requires) end) -- install all required packages from repositories - for _, instance in ipairs(packages_remote) do - action.install(instance) + for _, instance in ipairs(packages) do + if (option.get("force") or not instance:exists()) and (#instance:urls() > 0 or instance:script("install")) then + action.install(instance) + end end +end + +-- install packages +function main(requires) + + -- avoid to run this task repeatly + if _g.installed then return end + _g.installed = true + + -- TODO move the global modules + -- enter environment + environment.enter() + + -- git not found? install it first + if not find_git() then + _install_packages("git") + end + + -- install packages + _install_packages(requires) -- check missing packages _check_missing_packages(packages) diff --git a/xmake/actions/require/repository.lua b/xmake/actions/require/repository.lua index d7db954e0..63a52ed61 100644 --- a/xmake/actions/require/repository.lua +++ b/xmake/actions/require/repository.lua @@ -43,8 +43,8 @@ function repositories() return repos end --- exists repositories -function exists() +-- the remote repositories have been pulled? +function pulled() for _, repo in ipairs(repositories()) do local repodir = path.join(repository.directory(repo.global), repo.name) if not os.isdir(repodir) then @@ -92,6 +92,14 @@ function packagedir(packagename, reponame) end end + -- not found? find this package from the builtin packages directory + if not foundir then + local dir = path.join(os.programdir(), "packages", (packagename:gsub('%.', path.seperator()))) + if os.isdir(dir) then + foundir = {dir, true} + end + end + -- found? if foundir then diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index a1f19b8a5..6df0f5326 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -166,6 +166,11 @@ function _instance:from(kind) return self._FROMKIND == kind end +-- get the package kind, binary or nil(static, shared) +function _instance:kind() + return self:get("kind") +end + -- get the cached directory of this package function _instance:cachedir() return path.join(package.cachedir(), self:fullname(), self:version_str()) @@ -264,7 +269,7 @@ function _instance:script(name, generic) result = result or generic -- imports some modules first - if result then + if result and result ~= generic then local scope = getfenv(result) if scope then for _, modulename in ipairs(table.wrap(self:get("imports"))) do @@ -283,27 +288,41 @@ end -- function _instance:fetch() - -- import find_package - self._find_package = self._find_package or sandbox_module.import("lib.detect.find_package", {anonymous = true}) - - -- fetch it from the package directories first + -- fetch binary tool? local fetchfrom = self._FETCHFROM local fetchinfo = self._FETCHINFO - local installdir = self:installdir() - if not fetchinfo and installdir then - fetchinfo = self._find_package(self:name(), {packagedirs = installdir, system = false, force = true}) -- disable cache and system packages - if fetchinfo then fetchfrom = self._FROMKIND end - end + if self:kind() == "binary" then + + -- import find_tool + self._find_tool = self._find_tool or sandbox_module.import("lib.detect.find_tool", {anonymous = true}) + + -- fetch it from the system directories + fetchinfo = self._find_tool(self:name()) + if fetchinfo then + fetchfrom = "system" -- ignore self:requireinfo().system + end + else + + -- import find_package + self._find_package = self._find_package or sandbox_module.import("lib.detect.find_package", {anonymous = true}) - -- fetch it from the system directories - if not fetchinfo then - local system = self:requireinfo().system - if system == nil then -- find system package by default - system = true + -- fetch it from the package directories first + local installdir = self:installdir() + if not fetchinfo and installdir then + fetchinfo = self._find_package(self:name(), {packagedirs = installdir, system = false, force = true}) -- disable cache and system packages + if fetchinfo then fetchfrom = self._FROMKIND end end - if system then - fetchinfo = self._find_package(self:name()) - if fetchinfo then fetchfrom = "system" end + + -- fetch it from the system directories + if not fetchinfo then + local system = self:requireinfo().system + if system == nil then -- find system package by default + system = true + end + if system then + fetchinfo = self._find_package(self:name()) + if fetchinfo then fetchfrom = "system" end + end end end @@ -351,6 +370,7 @@ function package.apis() { -- package.set_xxx "package.set_urls" + , "package.set_kind" , "package.set_sha256s" , "package.set_versions" , "package.set_homepage" diff --git a/xmake/core/package/repository.lua b/xmake/core/package/repository.lua index 41feaa5a8..16b29e286 100644 --- a/xmake/core/package/repository.lua +++ b/xmake/core/package/repository.lua @@ -125,8 +125,6 @@ end -- get all repositories from global or local directory function repository.repositories(is_global) - - -- get repositories return repository._cache(is_global):get("repositories") end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 99649216a..f643834b1 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -729,7 +729,7 @@ function target:script(name, generic) result = result or generic -- imports some modules first - if result then + if result and result ~= generic then local scope = getfenv(result) if scope then for _, modulename in ipairs(table.wrap(self:get("imports"))) do diff --git a/xmake/packages/git/xmake.lua b/xmake/packages/git/xmake.lua index e703a4246..f2112ee8c 100644 --- a/xmake/packages/git/xmake.lua +++ b/xmake/packages/git/xmake.lua @@ -1,11 +1,16 @@ package("git") + set_kind("binary") set_homepage("https://git-scm.com/") set_description("A free and open source distributed version control system") - add_imports("devel.package_manager", "lib.detect.find_tool") +-- add_imports("devel.package_manager", "lib.detect.find_tool") + + on_build(function (package) + end) on_install(function (package) - package_manager.install("git") + print("install git") +-- package_manager.install("git") end) on_install("windows", function (package) |
