diff options
| author | ruki <[email protected]> | 2017-07-18 10:30:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-18 10:30:27 +0800 |
| commit | a4648568818b4b5b3598e6c7d5179b5d720a8c94 (patch) | |
| tree | b9a046c16f5075941763f0c11028d4403bd51fd4 | |
| parent | d0cead611d9f97a678d7c80a9354aee47a89e218 (diff) | |
mark project.load as deprecated and add add_deps api in option
| -rw-r--r-- | xmake/actions/config/main.lua | 3 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 68 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 197 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 80 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 10 |
5 files changed, 206 insertions, 152 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 36a5c50c2..34fe55f76 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -251,9 +251,6 @@ function main() config.set("buildir", path.relative(buildir, project.directory())) end - -- load project - project.load() - -- check target _check_target(targetname) diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index d9d6d87ba..c413640ca 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -63,14 +63,17 @@ function option:_save() self:set("check_after", nil) self:set("check_before", nil) - -- save this option to cache + -- save option option._cache():set(self:name(), self._INFO) - option._cache():flush() end -- clear the option info for cache function option:_clear() option._cache():set(self:name(), nil) +end + +-- flush the option cache to file +function option:_flush() option._cache():flush() end @@ -151,12 +154,7 @@ function option:_check() end -- attempt to check option -function option:check(force) - - -- have been checked? - if self._CHECKED and not force then - return - end +function option:check() -- the option name local name = self:name() @@ -175,7 +173,7 @@ function option:check(force) end -- need check? (only force to check the automatical option without the default value) - if config.get(name) == nil or (default == nil and force) then + if config.get(name) == nil or default == nil then -- use it directly if the default value exists if default ~= nil then @@ -197,12 +195,6 @@ function option:check(force) if check_after then check_after(self) end - - -- flush the option cache - self:_flush() - - -- checked - self._CHECKED = true end -- get the option value @@ -212,8 +204,13 @@ end -- set the option value function option:set_value(value) + + -- set value to option config.set(self:name(), value) + + -- save option and flush cache to file self:_save() + self:_flush() end -- this option is enabled? @@ -221,6 +218,19 @@ function option:is_enabled() return config.get(self:name()) end +-- clear the option status and need recheck it +function option:clear() + + -- enable or disable this option? + config.set(self:name(), nil) + + -- clear this option in cache + self:_clear() + + -- flush cache to file + self:_flush() +end + -- enable or disable this option function option:enable(is_enabled) @@ -233,6 +243,9 @@ function option:enable(is_enabled) else self:_clear() end + + -- flush cache to file + self:_flush() end -- dump this option @@ -274,30 +287,7 @@ end -- get option deps function option:deps() - -- TODO in the future - return {} -end - --- save the option info to the cache -function option:_save() - option._cache():set(self:name(), self._INFO) -end - --- clear the option info for cache -function option:_clear() - option._cache():set(self:name(), nil) -end - --- flush the option cache to file -function option:_flush() - - -- clear scripts for caching to file - self:set("check", nil) - self:set("check_after", nil) - self:set("check_before", nil) - - -- flush cache - option._cache():flush() + return self._DEPS end -- get the option name diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index bc5e7ab25..40663b0d0 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -234,6 +234,7 @@ function project._interpreter() , "option.set_languages" , "option.set_description" -- option.add_xxx + , "option.add_deps" , "option.add_vectorexts" , "option.add_bindings" , "option.add_rbindings" @@ -355,14 +356,14 @@ function project._interpreter() end -- load target deps -function project._load_target_deps(target, targets) +function project._load_deps(target, targets) -- get dep targets local deptargets = {} for _, dep in ipairs(table.wrap(target:get("deps"))) do local deptarget = targets[dep] if deptarget then - table.join2(deptargets, project._load_target_deps(deptarget, targets)) + table.join2(deptargets, project._load_deps(deptarget, targets)) table.insert(deptargets, deptarget) end end @@ -371,40 +372,8 @@ function project._load_target_deps(target, targets) return table.unique(deptargets) 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 the project -function project.load() +-- load targets +function project._load_targets() -- get interpreter local interp = project._interpreter() @@ -413,19 +382,19 @@ function project.load() -- enter the project directory local ok, errors = os.cd(project.directory()) if not ok then - return false, errors + return nil, errors end -- load targets local results, errors = interp:load(project.file(), "target", true, true) if not results then - return false, errors + return nil, errors end -- leave the project directory ok, errors = os.cd("-") if not ok then - return false, errors + return nil, errors end -- make targets @@ -436,12 +405,9 @@ function project.load() -- load and attach target deps for _, target in pairs(targets) do - target._DEPS = project._load_target_deps(target, targets) + target._DEPS = project._load_deps(target, targets) end - -- save targets - project._TARGETS = targets - -- enter toolchains environment environment.enter("toolchains") @@ -459,47 +425,40 @@ function project.load() -- leave toolchains environment environment.leave("toolchains") - -- ok? - return ok, errors -end - --- get the given target -function project.target(targetname) - - -- check - assert(targetname) - - -- the targets - local targets = project.targets() - assert(targets) - - -- get it - return targets[targetname] -end - --- get the current configure for targets -function project.targets() - - -- check - assert(project._TARGETS) + -- on load failed? + if not ok then + return nil, errors + end - -- return it - return project._TARGETS + -- ok + return targets end --- get options -function project.options(enable_filter) +-- load options +function project._load_options(disable_filter) -- get interpreter local interp = project._interpreter() assert(interp) + -- enter the project directory + local ok, errors = os.cd(project.directory()) + if not ok then + return nil, errors + end + -- load the options from the the project file - local results, errors = interp:load(project.file(), "option", true, enable_filter) + local results, errors = interp:load(project.file(), "option", true, not disable_filter) if not results then return nil, errors end + -- leave the project directory + ok, errors = os.cd("-") + if not ok then + return nil, errors + end + -- check options local options = {} for optionname, optioninfo in pairs(results) do @@ -513,7 +472,7 @@ function project.options(enable_filter) instance._INFO = optioninfo -- save it - table.insert(options, instance) + options[optionname] = instance -- mark add_defines_h_if_ok and add_undefines_h_if_ok as deprecated if instance:get("defines_h_if_ok") then @@ -524,10 +483,102 @@ function project.options(enable_filter) end end + -- load and attach options deps + for _, opt in pairs(options) do + opt._DEPS = project._load_deps(opt, options) + end + -- ok? return options 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 + +-- clear project cache to reload targets and options +function project.clear() + + -- clear options status in config file first + for _, opt in ipairs(table.wrap(project._OPTIONS)) do + opt:clear() + end + + -- clear targets and options + project._TARGETS = nil + project._OPTIONS = nil +end + +-- get the given target +function project.target(name) + return project.targets()[name] +end + +-- get the current configure for targets +function project.targets() + + -- load targets + if not project._TARGETS then + local targets, errors = project._load_targets() + if not targets then + os.raise(errors) + end + project._TARGETS = targets + end + + -- ok + return project._TARGETS +end + +-- get the given option +function project.option(name) + return project.options()[name] +end + +-- get options +function project.options() + + -- load options and enable filter + if not project._OPTIONS then + local options, errors = project._load_options() + if not options then + os.raise(errors) + end + project._OPTIONS = options + end + + -- ok + return project._OPTIONS +end + -- get tasks function project.tasks() @@ -568,7 +619,7 @@ function project.menu() local options = nil local errors = nil if os.isfile(project.file()) then - options, errors = project.options(false) + options, errors = project._load_options(true) end -- failed? diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index c78185a5a..4d1b574b3 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -27,6 +27,7 @@ local sandbox_core_project = sandbox_core_project or {} -- load modules local table = require("base/table") +local deprecated = require("base/deprecated") local config = require("project/config") local project = require("project/project") local sandbox = require("sandbox/sandbox") @@ -35,27 +36,22 @@ local environment = require("platform/environment") -- load project function sandbox_core_project.load() + -- deprecated + deprecated.add("project.clear() or only remove it", "project.load()") +end - -- load it - local ok, errors = project.load() - if not ok then - raise(errors) - end +-- clear project +function sandbox_core_project.clear() + project.clear() end -- check project options -function sandbox_core_project.check(force) - - -- enter the project directory - local ok, errors = os.cd(project.directory()) - if not ok then - raise(errors) - end +function sandbox_core_project.check() - -- load the options from the the project file - local options, errors = project.options(true) - if not options then - raise(errors) + -- get project options + local options = {} + for _, opt in pairs(project.options()) do + table.insert(options, opt) end -- get sandbox instance @@ -65,38 +61,58 @@ function sandbox_core_project.check(force) -- enter toolchains environment environment.enter("toolchains") + -- init check task + local checked = {} + local checktask = function (index) + + -- get option + local opt = options[index] + if opt then + + -- check deps of this option first + for _, dep in ipairs(opt:deps()) do + if not checked[dep:name()] then + dep:check() + checked[dep:name()] = true + end + end + + -- check this option + if not checked[opt:name()] then + opt:check() + checked[opt:name()] = true + end + end + end + -- check all options - ok, errors = process.runjobs(instance:fork(function (index) options[index]:check(force) end):script(), #options, 4) + ok, errors = process.runjobs(instance:fork(checktask):script(), #options, 4) if not ok then raise(errors) end -- leave toolchains environment environment.leave("toolchains") - - -- leave the project directory - ok, errors = os.cd("-") - if not ok then - raise(errors) - end end -- get the given target -function sandbox_core_project.target(targetname) - - -- get it - return project.target(targetname) +function sandbox_core_project.target(name) + return project.target(name) end -- get the all targets function sandbox_core_project.targets() + return project.targets() +end - -- get targets - local targets = project.targets() - assert(targets) +-- get the given option +function sandbox_core_project.option(name) + return project.option(name) +end - -- ok - return targets +-- get the all options +function sandbox_core_project.options() + return project.options() end -- get the project file diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 43834fd6f..1807e9845 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -166,15 +166,15 @@ function make(outputdir, vsinfo) config.set("mode", mode) config.set("arch", arch) - -- recheck project options - project.check(true) + -- clear project to reload and recheck it + project.clear() + + -- check project options + project.check() -- reload platform platform.load(config.plat()) - -- reload project - project.load() - -- remake configheader configheader.make() end |
