summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-04-16 07:33:40 +0800
committerGitHub <[email protected]>2019-04-16 07:33:40 +0800
commitd7d6f53f8467b67ae64f4c4ceb483907be0c537f (patch)
tree19b569318babcf941c4bba0cbf1026a6a888e3b4
parentdf6f2a231410fde1240170e45ea657a239409450 (diff)
parent0e3f93ad95a57e2dbc3360c26292dacb767f8f54 (diff)
Merge pull request #398 from RaZeR-RBI/feature/clib-integration
Clib integration (xmake-io/xmake#397)
-rw-r--r--xmake/modules/detect/tools/find_clib.lua54
-rw-r--r--xmake/modules/package/manager/clib/find_package.lua39
-rw-r--r--xmake/modules/package/manager/clib/install_package.lua81
3 files changed, 174 insertions, 0 deletions
diff --git a/xmake/modules/detect/tools/find_clib.lua b/xmake/modules/detect/tools/find_clib.lua
new file mode 100644
index 000000000..2464ec248
--- /dev/null
+++ b/xmake/modules/detect/tools/find_clib.lua
@@ -0,0 +1,54 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- 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)
+-- @file find_clib.lua
+--
+
+-- imports
+import("lib.detect.find_program")
+import("lib.detect.find_programver")
+
+-- find clib
+--
+-- @param opt the argument options, .e.g {version = true}
+--
+-- @return program, version
+--
+-- @code
+--
+-- local clib = find_clib()
+-- local clib, version = find_clib({version = true})
+--
+-- @endcode
+--
+function main(opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- find program
+ local program = find_program(opt.program or "clib", opt)
+
+ -- find program version
+ local version = nil
+ if program and opt and opt.version then
+ version = find_programver(program, opt)
+ end
+
+ -- ok?
+ return program, version
+end
diff --git a/xmake/modules/package/manager/clib/find_package.lua b/xmake/modules/package/manager/clib/find_package.lua
new file mode 100644
index 000000000..ae8f55edc
--- /dev/null
+++ b/xmake/modules/package/manager/clib/find_package.lua
@@ -0,0 +1,39 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- 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)
+-- @file find_package.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.config")
+
+function main(name, opt)
+ -- check if a package marker file with install directory exists
+ 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 os.isfile(marker_path) then
+ dprint("no marker file found for %s", name)
+ return
+ end
+
+ dprint("found marker file for %s", name)
+ return io.load(marker_path)
+end
diff --git a/xmake/modules/package/manager/clib/install_package.lua b/xmake/modules/package/manager/clib/install_package.lua
new file mode 100644
index 000000000..0fb057183
--- /dev/null
+++ b/xmake/modules/package/manager/clib/install_package.lua
@@ -0,0 +1,81 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- 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)
+-- @file install_package.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.config")
+import("lib.detect.find_tool")
+
+-- get configurations
+function configurations()
+ return
+ {
+ save = {description = "save dependency in project's package.json", default = false, type = "boolean"},
+ save_dev = {description = "save as development dependency in project's package.json", default = false, type = "boolean"},
+ outputdir = {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,
+-- settings = {outputdir = "clib", save = false, save_dev = false}}
+--
+-- @return true or false
+--
+function main(name, opt)
+ -- find clib
+ local clib = find_tool("clib")
+ if not clib then
+ raise("clib not found!")
+ end
+
+ local argv = {"install", name}
+ local abs_out = path.join(os.projectdir(), opt.outputdir)
+ dprint("installing %s to %s", name, abs_out)
+ table.insert(argv, "-o " .. abs_out)
+
+ if not option.get("verbose") then
+ table.insert(argv, "-q")
+ end
+ if opt.save then
+ table.insert(argv, "--save")
+ end
+ if opt.save_dev 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(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_path)
+ io.save(marker_path, {includedirs = { abs_out }})
+end