summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-20 14:01:06 +0800
committerruki <[email protected]>2017-07-20 14:01:06 +0800
commita9a33cca711e2bc6d88594e2ab6b99921d5992f2 (patch)
treed44c4e9b9afb04d3aa0baa5da98b8e66f428d59d
parente5d685f1fdba2977986950b13dc851682d3f7bcc (diff)
seperate task api from project and remove package module
-rw-r--r--xmake/core/main.lua4
-rw-r--r--xmake/core/project/package.lua44
-rw-r--r--xmake/core/project/project.lua59
-rw-r--r--xmake/core/project/task.lua36
-rw-r--r--xmake/core/sandbox/modules/import/core/project/package.lua40
5 files changed, 75 insertions, 108 deletions
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 87a4a7a87..2e860269a 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -34,6 +34,7 @@ local profiler = require("base/profiler")
local deprecated = require("base/deprecated")
local privilege = require("base/privilege")
local task = require("project/task")
+local project = require("project/project")
local history = require("project/history")
-- init the option menu
@@ -155,6 +156,9 @@ function main._init()
else
os.addenv("PATH", os.programdir())
end
+
+ -- define task and package apis first before loading project's xmake.lua - calling option.init()
+ project.define_apis(task.apis())
end
-- the main function
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
deleted file mode 100644
index dab0d9ec6..000000000
--- a/xmake/core/project/package.lua
+++ /dev/null
@@ -1,44 +0,0 @@
---!The Make-like Build Utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2017, TBOOX Open Source Group.
---
--- @author ruki
--- @file package.lua
---
-
--- define module: package
-local package = package or {}
-
--- load modules
-local os = require("base/os")
-local io = require("base/io")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
-local string = require("base/string")
-
--- the package directory
-function package.directory()
-
- -- the global directory
- return path.translate("~/.xmake/packages")
-end
-
--- return module: package
-return package
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 31c19ee86..d2d467d88 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -31,14 +31,13 @@ local io = require("base/io")
local path = require("base/path")
local utils = require("base/utils")
local table = require("base/table")
+local global = require("base/global")
local process = require("base/process")
local deprecated = require("base/deprecated")
local interpreter = require("base/interpreter")
local target = require("project/target")
local config = require("project/config")
-local global = require("base/global")
local option = require("project/option")
-local package = require("project/package")
local deprecated_project = require("project/deprecated/project")
local platform = require("platform/platform")
local environment = require("platform/environment")
@@ -201,7 +200,7 @@ function project._interpreter()
-- define apis for language
interp:api_define(language.apis())
- -- define apis for target, option and task
+ -- define apis for target, option
interp:api_define
{
values =
@@ -238,9 +237,6 @@ function project._interpreter()
, "option.add_vectorexts"
, "option.add_bindings" -- deprecated
, "option.add_rbindings" -- deprecated
- -- task.set_xxx
- , "task.set_category"
- , "task.set_menu"
}
, pathes =
{
@@ -300,6 +296,12 @@ function project._interpreter()
}
}
+ -- define registered apis
+ for _, apis in ipairs(project._APIS or {}) do
+ interp:api_define(apis)
+ end
+
+ -- TODO
-- register api: add_packages() to target
interp:api_register_builtin("add_packages", interp:_api_within_scope("target", "add_options"))
@@ -333,7 +335,6 @@ function project._interpreter()
, globaldir = global.directory()
, configdir = config.directory()
, projectdir = project.directory()
- , packagedir = package.directory()
, programdir = os.programdir()
}
@@ -355,6 +356,48 @@ function project._interpreter()
return interp
end
+-- define apis
+function project.define_apis(apis)
+
+ -- init apis
+ project._APIS = project._APIS or {}
+
+ -- define these apis
+ table.insert(project._APIS, apis)
+end
+
+-- get the project file
+function project.file()
+ return os.projectfile()
+end
+
+-- get the project directory
+function project.directory()
+ return os.projectdir()
+end
+
+-- get the project info from the given name
+function project.get(name)
+
+ -- load the global project infos
+ local infos = project._INFOS
+ if not infos then
+
+ -- get interpreter
+ local interp = project._interpreter()
+ assert(interp)
+
+ -- load infos
+ infos = interp:load(project.file(), nil, true, true)
+ project._INFOS = infos
+ end
+
+ -- get it
+ if infos then
+ return infos[name]
+ end
+end
+
-- load targets
function project._load_targets()
@@ -657,7 +700,7 @@ function project.menu()
first = false
end
- -- deprecated, make bindings
+ -- deprecated: make bindings
local bindings = nil
if opt:get("bindings") then
bindings = string.join(table.wrap(opt:get("bindings")), ',')
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index b32352b7e..6da3c26ee 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -35,7 +35,6 @@ local interpreter = require("base/interpreter")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local project = require("project/project")
-local package = require("project/package")
local sandbox_os = require("sandbox/modules/os")
-- the directories of tasks
@@ -167,20 +166,7 @@ function task._interpreter()
assert(interp)
-- define apis
- interp:api_define
- {
- values =
- {
- -- task.set_xxx
- "task.set_category" -- main, action, plugin, task (default)
- , "task.set_menu"
- }
- , script =
- {
- -- task.on_xxx
- "task.on_run"
- }
- }
+ interp:api_define(task.apis())
-- set filter
interp:filter():register("task", function (variable)
@@ -202,7 +188,6 @@ function task._interpreter()
, globaldir = global.directory()
, configdir = config.directory()
, projectdir = os.projectdir()
- , packagedir = package.directory()
, programdir = os.programdir()
}
@@ -328,6 +313,25 @@ function task._load(filepath)
-- ok?
return tasks
end
+
+-- get task apis
+function task.apis()
+
+ return
+ {
+ values =
+ {
+ -- task.set_xxx
+ "task.set_category" -- main, action, plugin, task (default)
+ , "task.set_menu"
+ }
+ , script =
+ {
+ -- task.on_xxx
+ "task.on_run"
+ }
+ }
+end
-- get all tasks
function task.tasks()
diff --git a/xmake/core/sandbox/modules/import/core/project/package.lua b/xmake/core/sandbox/modules/import/core/project/package.lua
deleted file mode 100644
index 174c8cb4d..000000000
--- a/xmake/core/sandbox/modules/import/core/project/package.lua
+++ /dev/null
@@ -1,40 +0,0 @@
---!The Make-like Build Utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you 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 - 2017, TBOOX Open Source Group.
---
--- @author ruki
--- @file package.lua
---
-
--- define module
-local sandbox_core_project_package = sandbox_core_project_package or {}
-
--- load modules
-local package = require("project/package")
-local raise = require("sandbox/modules/raise")
-
--- run the given package
-function sandbox_core_project_package.directory()
-
- -- get it
- return package.directory()
-end
-
--- return module
-return sandbox_core_project_package