summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-06 10:14:39 +0800
committerruki <[email protected]>2017-09-06 10:14:54 +0800
commitacdcde640f89df691cbaee89b71682e295de030b (patch)
tree43c5bcb084e91b424fd3659987758f672a6f12c5
parentfa7b871c4880fd8947e872a8fcef815de36ea358 (diff)
add required packages and deps to targets
-rw-r--r--tests/projects/requires/xmake.lua6
-rw-r--r--xmake/actions/require/install.lua56
-rw-r--r--xmake/actions/require/package.lua24
-rw-r--r--xmake/core/package/package.lua20
4 files changed, 76 insertions, 30 deletions
diff --git a/tests/projects/requires/xmake.lua b/tests/projects/requires/xmake.lua
index fd67d64fb..725e3ef05 100644
--- a/tests/projects/requires/xmake.lua
+++ b/tests/projects/requires/xmake.lua
@@ -1,13 +1,13 @@
-- define package
package("mbedtls")
set_urls("https://github.com/ARMmbed/mbedtls.git")
- add_requires("https://github.com/glennrp/libpng.git@libpng >=1.6.28")
+ add_deps("https://github.com/glennrp/libpng.git@libpng >=1.6.28")
package_end()
-- group packages
package("zlib-mbedtls")
- add_requires("zlib >=1.2.11")
- add_requires("mbedtls master optional")
+ add_deps("zlib >=1.2.11")
+ add_deps("mbedtls master optional")
package_end()
-- requires
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 709289ed4..4c4c91901 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -31,6 +31,41 @@ import("package")
import("repository")
import("environment")
+-- attach package to target
+function _attach_to_target(instance, target)
+ target:add(instance:fetch())
+ local orderdeps = instance:orderdeps()
+ if orderdeps then
+ local total = #orderdeps
+ for idx, _ in ipairs(orderdeps) do
+ local dep = orderdeps[total + 1 - idx]
+ target:add(dep:fetch())
+ end
+ end
+end
+
+-- attach all packages to targets
+function _attach_to_targets(packages)
+
+ -- get all local paclages
+ local packages_local = {}
+ for _, instance in ipairs(packages) do
+ packages_local[instance:fullname()] = instance
+ end
+
+ -- add all local packages to targets
+ for _, target in pairs(project.targets()) do
+ for _, opt in ipairs(target:options()) do
+ if opt:enabled() then
+ local instance = packages_local[opt:name()]
+ if instance then
+ _attach_to_target(instance, target)
+ end
+ end
+ end
+ end
+end
+
-- install packages
function main(requires)
@@ -108,25 +143,8 @@ function main(requires)
action.install(instance)
end
- -- fetch all local paclages
- local packages_local = {}
- for _, instance in ipairs(packages) do
- if instance:phony() then
- -- TODO
- print(instance:fullname())
- else
- packages_local[instance:fullname()] = instance:fetch()
- end
- end
-
- -- TODO add installed package infos to the given targets
- for _, target in pairs(project.targets()) do
- for _, opt in ipairs(target:options()) do
- if opt:enabled() then
- target:add(packages_local[opt:name()])
- end
- end
- end
+ -- attach required local package to targets
+ _attach_to_targets(packages)
-- leave environment
environment.leave()
diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua
index 3b872d800..f9d7f52ae 100644
--- a/xmake/actions/require/package.lua
+++ b/xmake/actions/require/package.lua
@@ -201,6 +201,16 @@ function _load_package(packagename, requireinfo)
return instance
end
+-- sort package deps
+function _sort_packagedeps(package)
+ local orderdeps = {}
+ for _, dep in pairs(package:deps()) do
+ table.join2(orderdeps, _sort_packagedeps(dep))
+ table.insert(orderdeps, dep)
+ end
+ return orderdeps
+end
+
-- load all required packages
function _load_packages(requires)
@@ -216,10 +226,16 @@ function _load_packages(requires)
-- load package instance
local package = _load_package(packagename, requireinfo)
- -- load required packages and save them first of this package
- requires = package:get("requires")
- if requires then
- table.join2(packages, _load_packages(requires))
+ -- load dependent packages and save them first of this package
+ local deps = package:get("deps")
+ if deps then
+ local packagedeps = {}
+ for _, dep in ipairs(_load_packages(deps)) do
+ table.insert(packages, dep)
+ packagedeps[dep:name()] = dep
+ end
+ package._DEPS = packagedeps
+ package._ORDERDEPS = table.unique(_sort_packagedeps(package))
end
-- save this package instance
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 267594faa..fc93539dd 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -118,6 +118,16 @@ function _instance:urls_set(urls)
self._URLS = urls
end
+-- get deps
+function _instance:deps()
+ return self._DEPS
+end
+
+-- get order deps
+function _instance:orderdeps()
+ return self._ORDERDEPS
+end
+
-- phony package?
function _instance:phony()
return #self:urls() == 0
@@ -248,9 +258,11 @@ end
function _instance:fetch()
-- find package
- self._find_package = self._find_package or import("lib.detect.find_package", {anonymous = true})
- self._FETCHINFO = self._FETCHINFO or self._find_package(self:name(), {packagedirs = self:installdir()})
- return self._FETCHINFO
+ if not self:phony() then
+ self._find_package = self._find_package or import("lib.detect.find_package", {anonymous = true})
+ self._FETCHINFO = self._FETCHINFO or self._find_package(self:name(), {packagedirs = self:installdir()})
+ return self._FETCHINFO
+ end
end
-- exists this package in local
@@ -294,7 +306,7 @@ function package.apis()
, "package.set_homepage"
, "package.set_description"
-- package.add_xxx
- , "package.add_requires"
+ , "package.add_deps"
}
, script =
{