summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdel Vilkov <[email protected]>2019-04-15 12:30:01 +0300
committerAdel Vilkov <[email protected]>2019-04-15 12:30:01 +0300
commit02b3bcfce1e24a8f4978519db1bf8bde415bdc41 (patch)
tree9a0bbb01ba1418002ffd8efa9984439601e626a2
parentab5fabf72e0f8cef831312683a2e7603c5269089 (diff)
Config options for clib, code cleanup and fixes, proper API usage
-rw-r--r--xmake/core/sandbox/modules/io.lua10
-rw-r--r--xmake/modules/package/manager/clib/find_package.lua23
-rw-r--r--xmake/modules/package/manager/clib/install_package.lua59
-rw-r--r--xmake/modules/package/manager/install_package.lua3
4 files changed, 42 insertions, 53 deletions
diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua
index 7f93f020d..53d8399f4 100644
--- a/xmake/core/sandbox/modules/io.lua
+++ b/xmake/core/sandbox/modules/io.lua
@@ -77,16 +77,6 @@ function sandbox_io.gsub(filepath, pattern, replace)
return data, count
end
--- check if file exists
-function sandbox_io.exists(filepath)
- local file, _ = io.open(filepath, "r")
- if file then
- file:close()
- return true
- end
- return false
-end
-
-- open file
function sandbox_io.open(filepath, mode)
diff --git a/xmake/modules/package/manager/clib/find_package.lua b/xmake/modules/package/manager/clib/find_package.lua
index 39b18834f..7aa9d6ad1 100644
--- a/xmake/modules/package/manager/clib/find_package.lua
+++ b/xmake/modules/package/manager/clib/find_package.lua
@@ -11,7 +11,7 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
---
+--
-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
--
-- @author Adel Vilkov (aka RaZeR-RBI)
@@ -24,22 +24,17 @@ import("core.project.config")
function main(name, opt)
-- check if a package marker file with install directory exists
- local cache_dir = path.join(os.projectdir(), ".xmake", "cache", "packages")
+ local cache_dir = path.join(config.directory(), "clib", "cache", "packages")
local marker_filename = string.gsub(name, "%/", "=")
local marker_path = path.join(cache_dir, marker_filename)
+ dprint("looking for marker file for %s at %s", name, marker_path)
- if not io.exists(marker_filename) then
+ if not os.isfile(marker_path) then
+ dprint("no marker file found for %s", name)
return
end
- local marker_file = io.open(marker_path, "r")
- if marker_file then
- local install_path = marker_file:read("*all")
- marker_file:close()
- dprint("%s is installed to %s", name, install_path)
-
- return {
- includedirs = { install_path }
- }
- end
-end \ No newline at end of file
+ local install_path = io.readfile(marker_path)
+ dprint("%s is installed to %s", name, install_path)
+ return {includedirs = { install_path }}
+end
diff --git a/xmake/modules/package/manager/clib/install_package.lua b/xmake/modules/package/manager/clib/install_package.lua
index 54bb49f14..9c2743cbb 100644
--- a/xmake/modules/package/manager/clib/install_package.lua
+++ b/xmake/modules/package/manager/clib/install_package.lua
@@ -11,7 +11,7 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
---
+--
-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
--
-- @author Adel Vilkov (aka RaZeR-RBI)
@@ -22,10 +22,23 @@
import("core.base.option")
import("core.project.config")
import("lib.detect.find_tool")
+
+-- get configurations
+function configurations()
+ return
+ {
+ verbose = {description = "enable verbose output", default = "true", values = {"true", "false"}},
+ save = {description = "save dependency in project's package.json", default = "false", values = {"true", "false"}},
+ save_dev = {description = "save as development dependency in project's package.json", default = "false", values = {"true", "false"}},
+ out_dir = {description = "package installation directory relative to project root", default = "clib"},
+ }
+end
+
-- install package
-- @param name the package name, e.g. clib::clibs/[email protected]
--- @param opt the options, .e.g { verbose = true, out_dir = "clib",
--- save = false, save_dev = false }
+-- @param opt the options, .e.g { verbose = true, mode = "release", plat = , arch = ,
+-- remote = "", build = "all", options = {}, imports = {}, build_requires = {},
+-- settings = {verbose = "false", out_dir = "deps", save = "true", save_dev = "false"}}
--
-- @return true or false
--
@@ -36,45 +49,35 @@ function main(name, opt)
raise("clib not found!")
end
- -- default options
- local all_opts = {
- verbose = true,
- out_dir = "clib",
- save = false,
- save_dev = false
- }
- -- copy specified options
- if opt then
- for k, v in ipairs(opt) do
- all_opts[k] = v
- end
- end
-
local argv = {"install", name}
-
- local abs_out = path.join(os.projectdir(), all_opts.out_dir)
+ local abs_out = path.join(os.projectdir(), opt.out_dir)
dprint("installing %s to %s", name, abs_out)
table.insert(argv, "-o " .. abs_out)
- if not all_opts.verbose then
+ if opt.verbose ~= "true" then
table.insert(argv, "-q")
end
- if all_opts.save then
+ if opt.save == "true" then
table.insert(argv, "--save")
end
- if all_opts.save_dev then
+ if opt.save_dev == "true" then
table.insert(argv, "--save-dev")
end
+ -- save previous directory and cd to project directory
+ local old_dir = os.curdir()
+ os.cd(os.projectdir())
+
-- do install
os.vrunv(clib.program, argv)
+ -- restore old directory
+ os.cd(old_dir)
+
-- add a package marker file with install directory
- local cache_dir = path.join(os.projectdir(), ".xmake", "cache", "packages")
+ local cache_dir = path.join(config.directory(), "clib", "cache", "packages")
local marker_filename = string.gsub(name, "%/", "=")
local marker_path = path.join(cache_dir, marker_filename)
- dprint("writing clib marker file for %s to %s", name, marker_filename)
- local marker_file = io.open(marker_path, "w")
- marker_file:write(abs_out)
- marker_file:close()
-end \ No newline at end of file
+ dprint("writing clib marker file for %s to %s", name, marker_path)
+ io.writefile(marker_path, abs_out)
+end
diff --git a/xmake/modules/package/manager/install_package.lua b/xmake/modules/package/manager/install_package.lua
index 62256ebb6..fdc68e7c3 100644
--- a/xmake/modules/package/manager/install_package.lua
+++ b/xmake/modules/package/manager/install_package.lua
@@ -31,7 +31,7 @@ function _install_package(manager_name, package_name, opt)
end
-- get suitable package managers
- local managers = {"clib"}
+ local managers = {}
if is_host("windows") then
table.insert(managers, "pacman") -- msys/mingw
elseif is_host("linux") then
@@ -43,6 +43,7 @@ function _install_package(manager_name, package_name, opt)
table.insert(managers, "vcpkg")
table.insert(managers, "brew")
end
+ table.insert(managers, "clib")
assert(#managers > 0, "no suitable package manager!")
-- install package from the given package managers