From 566d33d6be83884239cce7df0655e60ec00bd836 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Mar 2016 10:41:57 +0800 Subject: load project --- xmake/actions/config/main.lua | 13 +++++ xmake/core/base/io.lua | 25 +++++++++ xmake/core/platform/compiler.lua | 6 +-- xmake/core/platform/platforms/windows/prober.lua | 2 +- xmake/core/platform/tool.lua | 17 +++--- xmake/core/platform/tools/clang.lua | 2 +- xmake/core/platform/tools/g++.lua | 2 +- xmake/core/project/project.lua | 61 ++++++++-------------- .../modules/import/core/project/project.lua | 59 +++++++++++++++++++++ 9 files changed, 135 insertions(+), 52 deletions(-) create mode 100644 xmake/core/sandbox/modules/import/core/project/project.lua diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 77451f344..89d928a09 100755 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -24,6 +24,7 @@ import("core.base.option") import("core.project.config") import("core.project.global") +import("core.project.project") -- filter option function _option_filter(name) @@ -70,6 +71,18 @@ function main() -- probe the configure with value: "auto" config.probe() + -- translate the build directory + local buildir = option.get("buildir") + if buildir and path.is_absolute(buildir) then + config.set("buildir", path.relative(buildir, project.directory())) + end + + -- probe the project options + project.probe() + + -- load project + project.load() + -- TODO -- dump it diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua index 3b04b9fdd..71c6cc5b8 100644 --- a/xmake/core/base/io.lua +++ b/xmake/core/base/io.lua @@ -27,6 +27,9 @@ local io = io or {} local path = require("base/path") local utils = require("base/utils") +-- save original open +io._open = io._open or io.open + -- save object with the level function io._save_with_level(file, object, level) @@ -137,6 +140,28 @@ function io.writall(filepath, data) return true end +-- replace the original open interface +function io.open(filepath, mode) + + -- check + assert(filepath) + + -- write file? + if mode == "w" then + + -- get the file directory + local dir = path.directory(filepath) + + -- ensure the file directory + if not os.isdir(dir) then + os.mkdir(dir) + end + end + + -- open it + return io._open(filepath, mode) +end + -- save object the the given filepath function io.save(filepath, object) diff --git a/xmake/core/platform/compiler.lua b/xmake/core/platform/compiler.lua index 04932dda2..96171003b 100644 --- a/xmake/core/platform/compiler.lua +++ b/xmake/core/platform/compiler.lua @@ -465,7 +465,7 @@ function compiler.check_include(opt, include, srcpath, objpath) assert(opt and srcpath and objpath) -- open the checking source file - local srcfile = io.openmk(srcpath) + local srcfile = io.open(srcpath, "w") if not srcfile then return end -- make include @@ -497,7 +497,7 @@ function compiler.check_function(opt, interface, srcpath, objpath) assert(opt and interface) -- open the checking source file - local srcfile = io.openmk(srcpath) + local srcfile = io.open(srcpath, "w") if not srcfile then return end -- get the compiler @@ -541,7 +541,7 @@ function compiler.check_typedef(opt, typedef, srcpath, objpath) assert(opt and typedef) -- open the checking source file - local srcfile = io.openmk(srcpath) + local srcfile = io.open(srcpath, "w") if not srcfile then return end -- get the compiler diff --git a/xmake/core/platform/platforms/windows/prober.lua b/xmake/core/platform/platforms/windows/prober.lua index 5ed3c9c50..2c1726ac9 100644 --- a/xmake/core/platform/platforms/windows/prober.lua +++ b/xmake/core/platform/platforms/windows/prober.lua @@ -164,7 +164,7 @@ function prober._probe_vs_path(configs) -- make the call(vcvarsall.bat) file local callpath = tmpdir .. "\\call_vcvarsall.bat" - local callfile = io.openmk(callpath) + local callfile = io.open(callpath, "w") assert(callfile) -- make call scripts diff --git a/xmake/core/platform/tool.lua b/xmake/core/platform/tool.lua index 36047f410..479d7a38e 100644 --- a/xmake/core/platform/tool.lua +++ b/xmake/core/platform/tool.lua @@ -157,19 +157,24 @@ function tool.load(name, root) local script, errors = loadfile(toolpath) if script then - -- load tool - local tool = script() + -- load tool + local ok, result = pcall(script) + if not ok then + utils.error(result) + utils.error("load %s failed!", toolpath) + assert(false) + end -- init tool - if tool and tool.init then - tool:init(name) + if result and result.init then + result:init(name) end -- save tool to the cache - tool._TOOLS[name] = tool + tool._TOOLS[name] = result -- ok? - return tool + return result else utils.error(errors) utils.error("load %s failed!", toolpath) diff --git a/xmake/core/platform/tools/clang.lua b/xmake/core/platform/tools/clang.lua index c4c8586f5..8cff2dab5 100644 --- a/xmake/core/platform/tools/clang.lua +++ b/xmake/core/platform/tools/clang.lua @@ -21,7 +21,7 @@ -- -- load modules -local gcc = require("tools/gcc") +local gcc = require("platform/tools/gcc") -- define module: clang local clang = clang or {} diff --git a/xmake/core/platform/tools/g++.lua b/xmake/core/platform/tools/g++.lua index d61e511eb..82dc7f627 100644 --- a/xmake/core/platform/tools/g++.lua +++ b/xmake/core/platform/tools/g++.lua @@ -21,7 +21,7 @@ -- -- load modules -local gcc = require("tools/gcc") +local gcc = require("platform/tools/gcc") -- define module: gxx local gxx = gxx or {} diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 7124c6a81..d8b19081b 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -499,7 +499,7 @@ function project._makeconf_for_target(target_name, target) local prefix = target.config_h_prefix or (target_name:upper() .. "_CONFIG") -- open the file - local file = project._CONFILES[config_h] or io.openmk(config_h) + local file = project._CONFILES[config_h] or io.open(config_h, "w") assert(file) -- make the head @@ -825,7 +825,7 @@ function project._make_options(options) for k, v in pairs(options) do -- this option need be probed automatically? - if config.auto(k) then + if config.get(name) == nil then -- make option local o = project._make_option(k, v, cfile, cxxfile, objectfile, targetfile) @@ -879,14 +879,23 @@ function project.probe() local interp = project._interpreter() assert(interp) + -- enter the project directory + local ok, errors = os.cd(xmake._PROJECT_DIR) + if not ok then + return failse, errors + end + -- load the options from the the project file local options, errors = interp:load(xmake._PROJECT_FILE, "option", true, true) if not options then - return errors + return false, errors end -- make the options from the the project file project._make_options(options) + + -- ok + return true end -- load the project @@ -896,51 +905,23 @@ function project.load() local interp = project._interpreter() assert(interp) + -- enter the project directory + local ok, errors = os.cd(xmake._PROJECT_DIR) + if not ok then + return failse, errors + end + -- load targets local targets, errors = interp:load(xmake._PROJECT_FILE, "target", true, true) if not targets then - return errors + return false, errors end -- save targets project._TARGETS = targets - -- the mtimes for interpreter - local mtimes = interp:mtimes() - assert(mtimes) - - -- get the mtimes for configure - local mtimes_config = config.get("__mtimes") - if mtimes_config then - - -- check for all project files and we need reconfig and rebuild it if them have been modified - for file, mtime in pairs(mtimes) do - - -- modified? reconfig and rebuild it - local mtime_old = mtimes_config[file] - if not mtime_old or mtime > mtime_old then - config._RECONFIG = true - config.set("__rebuild", true) - break - end - end - end - - -- update mtimes - config.set("__mtimes", mtimes) - - -- reconfig it? we need reprobe it - if config._RECONFIG then - project.probe() - config.clearup() - end -end - --- reload the project -function project.reload() - - -- load it - return project.load() + -- ok + return true end -- dump the current configure diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua new file mode 100644 index 000000000..077d1fc27 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -0,0 +1,59 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file project.lua +-- + +-- define module +local sandbox_core_project_project = sandbox_core_project_project or {} + +-- load modules +local config = require("project/config") +local project = require("project/project") +local raise = require("sandbox/modules/raise") + +-- load project +function sandbox_core_project_project.load() + + -- load it + local ok, errors = project.load() + if not ok then + raise(errors) + end +end + +-- probe project options +function sandbox_core_project_project.probe() + + -- probe it + local ok, errors = project.probe() + if not ok then + raise(errors) + end +end + +-- get the project directory +function sandbox_core_project_project.directory() + + -- get it + return xmake._PROJECT_DIR +end + +-- return module +return sandbox_core_project_project -- cgit v1.3.1