diff options
| author | ruki <[email protected]> | 2015-06-09 14:46:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-09 14:47:06 +0800 |
| commit | f6fec59106383347489ed77bb1896a9ccf5bbb2d (patch) | |
| tree | d9465b98ec45ad0e08cc16b7864ea75e8d682214 | |
| parent | 2664a11c5ae2444241aa72346e7574279ac6b0bd (diff) | |
remove preprocessor
| -rwxr-xr-x | core/src/xmake/machine.c | 13 | ||||
| -rwxr-xr-x | core/src/xmake/makefile | 3 | ||||
| -rwxr-xr-x | core/src/xmake/preprocessor/loadx.c | 314 | ||||
| -rw-r--r-- | core/src/xmake/preprocessor/prefix.h | 35 | ||||
| -rw-r--r-- | xmake/scripts/action/_global.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/base/global.lua | 127 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 2 |
7 files changed, 22 insertions, 474 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 1fbfaaca4..6bf2c721f 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -75,9 +75,6 @@ tb_int_t xm_path_is_absolute(lua_State* lua); tb_int_t xm_string_endswith(lua_State* lua); tb_int_t xm_string_startswith(lua_State* lua); -// the preprocessor functions -tb_int_t xm_preprocessor_loadx(lua_State* lua); - /* ////////////////////////////////////////////////////////////////////////////////////// * globals */ @@ -120,13 +117,6 @@ static luaL_Reg const g_string_functions[] = , { tb_null, tb_null } }; -// the preprocessor functions -static luaL_Reg const g_preprocessor_functions[] = -{ - { "loadx", xm_preprocessor_loadx } -, { tb_null, tb_null } -}; - /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ @@ -256,9 +246,6 @@ xm_machine_ref_t xm_machine_init() // bind string functions luaL_register(impl->lua, "string", g_string_functions); - // bind preprocessor functions - luaL_register(impl->lua, "preprocessor", g_preprocessor_functions); - // init host #if defined(TB_CONFIG_OS_WINDOWS) lua_pushstring(impl->lua, "windows"); diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index c61411dd8..932737fe8 100755 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -33,8 +33,7 @@ xmake_C_FILES += \ path/translate \ path/is_absolute \ string/endswith \ - string/startswith \ - preprocessor/loadx + string/startswith # flags diff --git a/core/src/xmake/preprocessor/loadx.c b/core/src/xmake/preprocessor/loadx.c deleted file mode 100755 index a529b97d6..000000000 --- a/core/src/xmake/preprocessor/loadx.c +++ /dev/null @@ -1,314 +0,0 @@ -/*!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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> - * - * Copyright (C) 2009 - 2015, ruki All rights reserved. - * - * @author ruki - * @file loadx.c - * - */ - -/* ////////////////////////////////////////////////////////////////////////////////////// - * trace - */ -#define TB_TRACE_MODULE_NAME "loadx" -#define TB_TRACE_MODULE_DEBUG (0) - -/* ////////////////////////////////////////////////////////////////////////////////////// - * includes - */ -#include "prefix.h" - -/* ////////////////////////////////////////////////////////////////////////////////////// - * private implementation - */ -static tb_char_t const* xm_preprocessor_loadx_to_string(tb_stream_ref_t stream, tb_string_ref_t string) -{ - // check - tb_assert_and_check_return_val(stream && string, tb_null); - - // init value - tb_string_t value; - if (!tb_string_init(&value)) return tb_null; - - // init temporary value - tb_string_t value_temp; - if (!tb_string_init(&value_temp)) return tb_null; - - // done - tb_bool_t is_value = tb_false; - tb_bool_t is_values = tb_false; - tb_size_t is_script = 0; - tb_bool_t is_comment = tb_false; - tb_bool_t is_value_string = tb_false; - tb_size_t is_value_script = 0; - while (!tb_stream_beof(stream)) - { - // read character - tb_char_t ch = (tb_char_t)tb_stream_bread_u8(stream); - if (ch) - { - // is comment? skip it - if (is_comment) - { - // newline? leave comment - if (ch == '\n') is_comment = tb_false; - } - // is script? skip it - else if (is_script) - { - // is ']'? - if (ch == ']') - { - // leave bracket? - is_script--; - - // append it if is script now - if (is_script) tb_string_chrcat(string, ch); - } - else - { - // enter bracket? - if (ch == '[') is_script++; - - // append it - tb_string_chrcat(string, ch); - } - } - // is values? - else if (is_values) - { - // enter or leave string - if (ch == '\"' || ch == '\'') is_value_string = !is_value_string; - - // enter or leave script? - if (ch == '[') is_value_script++; - else if (ch == ']' && is_value_script) is_value_script--; - - // is string or script value? - if (is_value && (is_value_string || is_value_script)) - { - // append to value - tb_string_chrcat(&value, ch); - } - // is value? - else if ( is_value - && ch != ',' - && ch != ':' - && ch != '{' - && ch != '}' - && ch != '\r' - && ch != '\n' - && ch != '#') - { - // append to value - tb_string_chrcat(&value, ch); - } - // ',' or ':' or '{' or '#' or newline? - else if ( ch == ',' - || ch == ':' - || ch == '{' - || ch == '}' - || ch == '\r' - || ch == '\n' - || ch == '#') - { - // has value? - if (is_value) - { - // values end? append ')' and newline first - if (ch == ':') tb_string_cstrcat(string, ")\n"); - else - { - // trim the left spaces - tb_string_ltrim(&value); - - // trim the right spaces - tb_string_rtrim(&value); - - // wrap "xxx" - if (tb_string_size(&value)) - { - // it has been "xxx" or 'xxx'? only copy it - if (tb_string_charat(&value, 0) == '\"' || tb_string_charat(&value, 0) == '\'') - tb_string_strcpy(&value_temp, &value); - // wrap it - else - { - tb_string_clear(&value_temp); - tb_string_chrcat(&value_temp, '\"'); - tb_string_strcat(&value_temp, &value); - tb_string_chrcat(&value_temp, '\"'); - } - - // clear value first - tb_string_clear(&value); - - // copy and replace '\"' to "\\"" - tb_char_t const* s = tb_string_cstr(&value_temp); - tb_size_t n = tb_string_size(&value_temp); - tb_size_t i = 0; - for (i = 0; i < n; i++) - { - // replace '\"' to "\\"" - if (i && i != n - 1 && s[i] == '\"') tb_string_cstrcat(&value, "\\\""); - // only copy iy - else tb_string_chrcat(&value, s[i]); - } - } - } - - // append value to string - if (tb_string_size(&value)) tb_string_strcat(string, &value); - - // clear value - tb_string_clear(&value); - - // not value now - is_value = tb_false; - } - - // continue to enter values? onyl replace ':' to '(' - if (ch == ':') tb_string_chrcat(string, '('); - // '{' ? - else if (ch == '{') - { - // not values now - is_values = tb_false; - - // append ')' and newline - tb_string_cstrcat(string, ")\n"); - } - // '}' ? - else if (ch == '}') - { - // not values now - is_values = tb_false; - - // append ')' and replace '}' to _end - tb_string_cstrcat(string, ")\n_end()"); - } - // skip newline - else if (ch == '\r' || ch == '\n') ; - // enter comment? - else if (ch == '#' && !is_comment) is_comment = tb_true; - // append to string - else tb_string_chrcat(string, ch); - } - else - { - // value now - is_value = tb_true; - - // append to value - tb_string_chrcat(&value, ch); - } - } - // enter values? - else if (ch == ':') - { - // values now - is_values = tb_true; - - // replace ':' to '(' - tb_string_chrcat(string, '('); - } - // replace '}' and newline to _end - else if (ch == '}') tb_string_cstrcat(string, "\n_end()"); - // enter comment? skip it - else if (ch == '#' && !is_comment) is_comment = tb_true; - // enter script? skip it - else if (ch == '[' && !is_script) is_script++; - // append it - else tb_string_chrcat(string, ch); - } - else - { - // end - break; - } - } - - // exit value - tb_string_exit(&value); - - // exit temporary value - tb_string_exit(&value_temp); - - // ok? - return tb_string_size(string)? tb_string_cstr(string) : tb_null; -} - -/* ////////////////////////////////////////////////////////////////////////////////////// - * implementation - */ -tb_int_t xm_preprocessor_loadx(lua_State* lua) -{ - // check - tb_assert_and_check_return_val(lua, 0); - - // get the xmake.xproj path - tb_char_t const* path = luaL_checkstring(lua, 1); - tb_check_return_val(path, 0); - - // done - tb_int_t ok = 0; - tb_stream_ref_t stream = tb_null; - tb_string_t string; - do - { - // init string - if (!tb_string_init(&string)) break; - - // init stream - stream = tb_stream_init_from_file(path, TB_FILE_MODE_RO); - tb_assert_and_check_break(stream); - - // open stream - if (!tb_stream_open(stream)) break; - - // load xmake.xproj to the string and preprocess it - tb_char_t const* xproj = xm_preprocessor_loadx_to_string(stream, &string); - tb_assert_and_check_break(xproj); - - // trace - tb_trace_d("%s", xproj); - - // load xmake.xproj string to script - if (luaL_loadstring(lua, xproj)) - { - // error - tb_printf("error: %s\n", lua_tostring(lua, -1)); - - // failed - break; - } - - // ok - ok = 1; - - } while (0); - - // exit stream - if (stream) tb_stream_exit(stream); - stream = tb_null; - - // exit string - tb_string_exit(&string); - - // ok? - return ok; -} diff --git a/core/src/xmake/preprocessor/prefix.h b/core/src/xmake/preprocessor/prefix.h deleted file mode 100644 index 443833645..000000000 --- a/core/src/xmake/preprocessor/prefix.h +++ /dev/null @@ -1,35 +0,0 @@ -/*!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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> - * - * Copyright (C) 2009 - 2015, ruki All rights reserved. - * - * @author ruki - * @file prefix.h - * - */ -#ifndef XM_PREPROCESSOR_PREFIX_H -#define XM_PREPROCESSOR_PREFIX_H - -/* ////////////////////////////////////////////////////////////////////////////////////// - * includes - */ -#include "../prefix.h" -#include "luajit/luajit.h" - - -#endif - - diff --git a/xmake/scripts/action/_global.lua b/xmake/scripts/action/_global.lua index fc4113aff..5cfaf1bbd 100644 --- a/xmake/scripts/action/_global.lua +++ b/xmake/scripts/action/_global.lua @@ -34,7 +34,7 @@ function _global.done() global.dump() -- save the global configure - if not global.savexconf() then + if not global.save() then -- error utils.error("save configure failed!") return false diff --git a/xmake/scripts/base/global.lua b/xmake/scripts/base/global.lua index 40cb04518..7032ba991 100644 --- a/xmake/scripts/base/global.lua +++ b/xmake/scripts/base/global.lua @@ -28,80 +28,6 @@ local io = require("base/io") local os = require("base/os") local utils = require("base/utils") local option = require("base/option") -local preprocessor = require("base/preprocessor") - --- save object with the level -function global._save_with_level(file, object, level) - - -- check - assert(object) - - -- save string - if type(object) == "string" then - file:write(string.format("%q", object)) - -- save boolean - elseif type(object) == "boolean" then - file:write(tostring(object)) - -- save number - elseif type(object) == "number" then - file:write(object) - -- save table - elseif type(object) == "table" then - - -- save head - file:write(utils.ifelse(level == 0, "global:\n", "\n")) - for l = 1, level do - file:write(" ") - end - file:write("{\n") - - -- save body - for k, v in pairs(object) do - - -- exclude _PARENT - if type(k) ~= "string" or k ~= "_PARENT" then - - -- save spaces - for l = 0, level do - file:write(" ") - end - - -- save key - if type(k) == "string" then - file:write(k, ": ") - end - - -- save value - if not global._save_with_level(file, v, level + 1) then - return false - end - - -- save newline - file:write("\n") - end - end - - -- save tail - for l = 1, level do - file:write(" ") - end - file:write("}\n") - else - -- error - utils.error("invalid object type: %s", type(object)) - return false - end - - -- ok - return true -end - --- save object -function global._save(file, object) - - -- save it - return global._save_with_level(file, object, 0) -end -- make configure function global._make() @@ -130,7 +56,7 @@ end function global._file() -- get it - return global.directory() .. "/xmake.xconf" + return global.directory() .. "/xmake.conf" end -- need configure? @@ -184,39 +110,19 @@ function global.directory() return dir end --- save xmake.xconf -function global.savexconf() +-- save xmake.conf +function global.save() -- the configs local configs = global._CONFIGS assert(configs) - -- open the configure file - local path = global._file() - local file = io.open(path, "w") - if not file then - -- error - utils.error("open %s failed!", path) - return false - end - - -- save configs to file - if not global._save(file, configs) then - -- error - utils.error("save %s failed!", path) - file:close() - return false - end - - -- close file - file:close() - - -- ok - return true + -- save to the configure file + return io.save(global._file(), configs) end --- load xmake.xconf -function global.loadxconf() +-- load xmake.conf +function global.load() -- the options local options = xmake._OPTIONS @@ -240,15 +146,20 @@ function global.loadxconf() -- does not clean the cached configure? if not options.clean then - -- load and execute the xmake.xconf - local path = global._file() - if os.isfile(path) then - local newenv, errors = preprocessor.loadfile(path, "global", configures) - if newenv then - global._CONFIGS = newenv._CONFIGS + -- load and execute the xmake.conf + local filepath = global._file() + if os.isfile(filepath) then + + -- load the configure file + local configs, errors = io.load(filepath) + + -- exists local configures? + if configs then + -- save configs + global._CONFIGS = configs elseif errors then -- error - utils.error(errors); + utils.error(errors) end end end diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 38470a909..d4945fc6a 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -409,7 +409,7 @@ function main._prepare_global() assert(options) -- load global configure - global.loadxconf() + global.load() -- xmake global? if options._ACTION == "global" then |
