From aba70a1655798c7441464fd03fb1867b723974d4 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 11:19:57 +0800 Subject: improve dump --- xmake/core/base/dump.lua | 41 ++++++++++++++++------ xmake/core/base/utils.lua | 8 +++-- .../modules/import/core/sandbox/sandbox.lua | 6 ++-- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua index cfa25918b..42ec2df17 100644 --- a/xmake/core/base/dump.lua +++ b/xmake/core/base/dump.lua @@ -23,7 +23,6 @@ local dump = dump or {} -- load modules local colors = require("base/colors") -local table = require("base/table") -- format string with theme colors function dump._format(fmtkey, fmtdefault, ...) @@ -37,7 +36,12 @@ end -- translate string with theme formats function dump._translate(str) - return colors.translate(str, { patch_reset = false, ignore_unknown = true }) + local theme = colors.theme() + if theme then + return colors.translate(str, { patch_reset = false, ignore_unknown = true }) + else + return colors.ignore(str) + end end -- print string @@ -205,10 +209,26 @@ function dump._print_metatable(value, metatable, inner_indent, printed_set, prin return has_record end +-- returns printed_set, is_first_level +function dump._init_printed_set(printed_set) + local first_level = not printed_set + if type(printed_set) ~= "table" then + printed_set = { len = 0 } + end + return printed_set, first_level +end + -- print udata -function dump._print_udata(value, first_indent, remain_indent) +function dump._print_udata(value, first_indent, remain_indent, printed_set) + local first_level + printed_set, first_level = dump._init_printed_set(printed_set) io.write(first_indent) + + if not first_level then + return dump._print_udata_scalar(value) + end + local metatable = getmetatable(value) local inner_indent = remain_indent .. " " @@ -216,7 +236,7 @@ function dump._print_udata(value, first_indent, remain_indent) io.write(dump._translate("${reset}${color.dump.udata}[${reset}")) -- print metatable - local no_value = not dump._print_metatable(value, metatable, inner_indent, { len = 0 }, false) + local no_value = not dump._print_metatable(value, metatable, inner_indent, printed_set, false) -- print close brackets if no_value then @@ -229,7 +249,8 @@ end -- print table function dump._print_table(value, first_indent, remain_indent, printed_set) - local first_level = not printed_set + local first_level + printed_set, first_level = dump._init_printed_set(printed_set) io.write(first_indent) local metatable = getmetatable(value) local tostringmethod = metatable and rawget(metatable, "__tostring") @@ -239,7 +260,7 @@ function dump._print_table(value, first_indent, remain_indent, printed_set) return dump._print_table_scalar(strrep) end end - printed_set = printed_set or { len = 0 } + local inner_indent = remain_indent .. " " local first_value = true @@ -260,7 +281,7 @@ function dump._print_table(value, first_indent, remain_indent, printed_set) end -- print array items - local is_arr = table.is_array(value) and (table.maxn(value) < 2 * #value) + local is_arr = (value[1] ~= nil) and (table.maxn(value) < 2 * #value) if is_arr then for i = 1,table.maxn(value) do print_newline() @@ -306,12 +327,12 @@ function dump._print_table(value, first_indent, remain_indent, printed_set) end -- print value -function dump._print(value, indent) +function dump._print(value, indent, verbose) indent = tostring(indent or "") if type(value) == "table" then - dump._print_table(value, indent, indent:gsub(".", " "), nil) + dump._print_table(value, indent, indent:gsub(".", " "), not verbose) elseif type(value) == "userdata" then - dump._print_udata(value, indent, indent:gsub(".", " ")) + dump._print_udata(value, indent, indent:gsub(".", " "), not verbose) else io.write(indent) dump._print_scalar(value) diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index d8f1ec7c2..5b0c68a5e 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -35,8 +35,10 @@ function utils.dump(...) return ... end + local diagnosis = option.get("diagnosis") + -- show caller info - if option.get("diagnosis") then + if diagnosis then local info = debug.getinfo(2) local line = info.currentline if not line or line < 0 then line = info.linedefined end @@ -58,11 +60,11 @@ function utils.dump(...) end if values_count == 1 then - dump(values[1], indent or "") + dump(values[1], indent or "", diagnosis) io.write("\n") else for i = 1, values_count do - dump(values[i], indent or string.format("%2d: ", i)) + dump(values[i], indent or string.format("%2d: ", i), diagnosis) io.write("\n") end end diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 5aa55a0c6..a6f19f93d 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -30,14 +30,16 @@ local utils = require("base/utils") local table = require("base/table") local history = require("project/history") local dump = require("base/dump") +local option = require("base/option") -- print variables for interactive mode function sandbox_core_sandbox._interactive_dump(...) + local diagnosis = option.get("diagnosis") local values = table.pack(...) -- do not use #values since nil might be included local n = values.n if n <= 1 then - dump(values[1], "< ") + dump(values[1], "< ", diagnosis) io.write("\n") else local fmt = "< %d: " @@ -50,7 +52,7 @@ function sandbox_core_sandbox._interactive_dump(...) fmt = "< %2d: " end for i = 1, n do - dump(values[i], string.format(fmt, i)) + dump(values[i], string.format(fmt, i), diagnosis) io.write("\n") end end -- cgit v1.3.1 From 22b7f15355725663f2ec4ccd5d2e3699ac8dbb3d Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 11:23:23 +0800 Subject: fix NormalizePath --- xmake/plugins/project/vsxmake/vsproj/Xmake.props | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.props b/xmake/plugins/project/vsxmake/vsproj/Xmake.props index 0198714f3..243a114b2 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.props +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.props @@ -49,14 +49,14 @@ $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeRunDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeProgramDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeProjectDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeScriptDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeBuilDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeTargetDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeConfigDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeConfigFileDir)')) - $([MSBuild]::NormalizeDirectory('$(XmakeRunDir)')) + $([MSBuild]::NormalizePath('$(XmakeProgramDir)/')) + $([MSBuild]::NormalizePath('$(XmakeProjectDir)/')) + $([MSBuild]::NormalizePath('$(XmakeScriptDir)/')) + $([MSBuild]::NormalizePath('$(XmakeBuilDir)/')) + $([MSBuild]::NormalizePath('$(XmakeTargetDir)/')) + $([MSBuild]::NormalizePath('$(XmakeConfigDir)/')) + $([MSBuild]::NormalizePath('$(XmakeConfigFileDir)/')) + $([MSBuild]::NormalizePath('$(XmakeRunDir)/')) -- cgit v1.3.1 From 34f89e4c1240897b9e1020c8e9cd9352044c272e Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 11:28:18 +0800 Subject: add output --- xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index 947251b97..dc9e6922f 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -86,10 +86,12 @@ MSBuild Properties: XmakeDefines: $(XmakeDefines) XmakeLanguages: $(XmakeLanguages) Xmake Path: + XmakeProgramDir: $(XmakeProgramDir) XmakeProjectDir: $(XmakeProjectDir) XmakeScriptDir: $(XmakeScriptDir) XmakeBuilDir: $(XmakeBuilDir) XmakeConfigDir: $(XmakeConfigDir) + XmakeConfigFileDir: $(XmakeConfigFileDir) XmakeIncludeDir: $(XmakeIncludeDir) XmakeLinkDir: $(XmakeLinkDir) Xmake Flags: -- cgit v1.3.1 From 62ad5d370410c48991c3487c13c89c21e7292dc8 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 11:52:55 +0800 Subject: change dump theme --- xmake/core/base/dump.lua | 6 +++--- xmake/themes/dark/xmake.lua | 8 ++++---- xmake/themes/default/xmake.lua | 8 ++++---- xmake/themes/emoji/xmake.lua | 8 ++++---- xmake/themes/plain/xmake.lua | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua index 42ec2df17..dd5492879 100644 --- a/xmake/core/base/dump.lua +++ b/xmake/core/base/dump.lua @@ -86,17 +86,17 @@ end -- print value with default format function dump._print_default(value) - io.write(dump._translate("${reset}${color.dump.default}"), dump._format("text.dump.default_format", "<%s>", value), dump._translate("${reset}")) + io.write(dump._translate("${reset}${color.dump.default}"), dump._format("text.dump.default_format", "%s", value), dump._translate("${reset}")) end -- print udata value with scalar format function dump._print_udata_scalar(value) - io.write(dump._translate("${reset}${color.dump.udata}"), dump._format("text.dump.udata_format", "[%s]", value), dump._translate("${reset}")) + io.write(dump._translate("${reset}${color.dump.udata}"), dump._format("text.dump.udata_format", "%s", value), dump._translate("${reset}")) end -- print table value with scalar format function dump._print_table_scalar(value) - io.write(dump._translate("${reset}${color.dump.table}"), dump._format("text.dump.table_format", "{%s}", value), dump._translate("${reset}")) + io.write(dump._translate("${reset}${color.dump.table}"), dump._format("text.dump.table_format", "%s", value), dump._translate("${reset}")) end -- print scalar value diff --git a/xmake/themes/dark/xmake.lua b/xmake/themes/dark/xmake.lua index cb9c6a093..df6689401 100644 --- a/xmake/themes/dark/xmake.lua +++ b/xmake/themes/dark/xmake.lua @@ -52,14 +52,14 @@ theme("dark") set_color("build.target", "magenta") -- color dump - set_text("dump.default_format", "<%s>") - set_text("dump.udata_format", "[%s]") - set_text("dump.table_format", "{%s}") + set_text("dump.default_format", "%s") + set_text("dump.udata_format", "%s") + set_text("dump.table_format", "%s") set_text("dump.anchor", "&%s") set_text("dump.reference", "*%s") set_color("dump.anchor", "yellow") set_color("dump.reference", "yellow") - set_color("dump.default", "bright") + set_color("dump.default", "red") set_color("dump.udata", "yellow") set_color("dump.table", "bright") set_color("dump.string", "magenta bright") diff --git a/xmake/themes/default/xmake.lua b/xmake/themes/default/xmake.lua index 568e351e2..02acd816e 100644 --- a/xmake/themes/default/xmake.lua +++ b/xmake/themes/default/xmake.lua @@ -52,14 +52,14 @@ theme("default") set_color("build.target", "magenta") -- color dump - set_text("dump.default_format", "<%s>") - set_text("dump.udata_format", "[%s]") - set_text("dump.table_format", "{%s}") + set_text("dump.default_format", "%s") + set_text("dump.udata_format", "%s") + set_text("dump.table_format", "%s") set_text("dump.anchor", "&%s") set_text("dump.reference", "*%s") set_color("dump.anchor", "yellow") set_color("dump.reference", "yellow") - set_color("dump.default", "bright") + set_color("dump.default", "red") set_color("dump.udata", "yellow") set_color("dump.table", "bright") set_color("dump.string", "magenta bright") diff --git a/xmake/themes/emoji/xmake.lua b/xmake/themes/emoji/xmake.lua index da189e23f..8dc5a3ee5 100644 --- a/xmake/themes/emoji/xmake.lua +++ b/xmake/themes/emoji/xmake.lua @@ -52,14 +52,14 @@ theme("emoji") set_color("build.target", "magenta") -- color dump - set_text("dump.default_format", "<%s>") - set_text("dump.udata_format", "[%s]") - set_text("dump.table_format", "{%s}") + set_text("dump.default_format", "%s") + set_text("dump.udata_format", "%s") + set_text("dump.table_format", "%s") set_text("dump.anchor", "${anchor} %s") set_text("dump.reference", "${sailboat} %s") set_color("dump.anchor", "yellow") set_color("dump.reference", "yellow") - set_color("dump.default", "bright") + set_color("dump.default", "red") set_color("dump.udata", "yellow") set_color("dump.table", "bright") set_color("dump.string", "magenta bright") diff --git a/xmake/themes/plain/xmake.lua b/xmake/themes/plain/xmake.lua index 057d2ddf0..85ec56ee6 100644 --- a/xmake/themes/plain/xmake.lua +++ b/xmake/themes/plain/xmake.lua @@ -52,9 +52,9 @@ theme("plain") set_color("build.target", "") -- color dump - set_text("dump.default_format", "<%s>") - set_text("dump.udata_format", "[%s]") - set_text("dump.table_format", "{%s}") + set_text("dump.default_format", "%s") + set_text("dump.udata_format", "%s") + set_text("dump.table_format", "%s") set_text("dump.anchor", "&%s") set_text("dump.reference", "*%s") set_color("dump.anchor", "") -- cgit v1.3.1 From 1ab3e1b602a12a95d91433e8b91c2aec8146940f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 12:00:30 +0800 Subject: fix --- xmake/plugins/project/vsxmake/vsproj/Xmake.props | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.props b/xmake/plugins/project/vsxmake/vsproj/Xmake.props index 243a114b2..20432fec3 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.props +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.props @@ -49,14 +49,14 @@ $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeRunDir)')) - $([MSBuild]::NormalizePath('$(XmakeProgramDir)/')) - $([MSBuild]::NormalizePath('$(XmakeProjectDir)/')) - $([MSBuild]::NormalizePath('$(XmakeScriptDir)/')) - $([MSBuild]::NormalizePath('$(XmakeBuilDir)/')) - $([MSBuild]::NormalizePath('$(XmakeTargetDir)/')) - $([MSBuild]::NormalizePath('$(XmakeConfigDir)/')) - $([MSBuild]::NormalizePath('$(XmakeConfigFileDir)/')) - $([MSBuild]::NormalizePath('$(XmakeRunDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeProgramDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeProjectDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeScriptDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeBuilDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeTargetDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeConfigDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeConfigFileDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeRunDir)/')) -- cgit v1.3.1 From c63d5c42136e92ad16eb81cc1b01db34d29792d1 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 12:36:01 +0800 Subject: add ut --- tests/plugins/project/c/src/main.c | 7 ++++ tests/plugins/project/c/xmake.lua | 77 ++++++++++++++++++++++++++++++++++++++ tests/plugins/project/test.lua | 33 ++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/plugins/project/c/src/main.c create mode 100644 tests/plugins/project/c/xmake.lua create mode 100644 tests/plugins/project/test.lua diff --git a/tests/plugins/project/c/src/main.c b/tests/plugins/project/c/src/main.c new file mode 100644 index 000000000..9ae580511 --- /dev/null +++ b/tests/plugins/project/c/src/main.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char** argv) +{ + printf("hello world!\n"); + return 0; +} diff --git a/tests/plugins/project/c/xmake.lua b/tests/plugins/project/c/xmake.lua new file mode 100644 index 000000000..72c4eb5f7 --- /dev/null +++ b/tests/plugins/project/c/xmake.lua @@ -0,0 +1,77 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +-- add target +target("project") + + -- set kind + set_kind("binary") + + -- add files + add_files("src/*.c") + + +-- +-- FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add macro defination +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "cxx11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox", "z", "pthread") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- +-- 7. If you want to known more usage about xmake, please see http://xmake.io/#/home +-- + diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua new file mode 100644 index 000000000..a9f1fa37e --- /dev/null +++ b/tests/plugins/project/test.lua @@ -0,0 +1,33 @@ +import("detect.sdks.find_vstudio") +import("core.project.config") +import("core.platform.environment") + +function test_vsxmake(t) + + if os.host() ~= "windows" then + return t:skip("wrong host platform") + end + + -- build project + local vs = find_vstudio() + local arch = os.getenv("platform") or "x86" + + os.cd("c") + + for name, data in pairs(vs) do + local vstype = "vsxmake" .. name + local path = os.getenv("path") + os.setenv("path", data.vcvarsall[arch].path) + environment.enter("toolchains") + os.execv("xmake", {"project", "-k", vstype, "-a", arch}) + os.cd(vstype) + os.exec("msbuild /t:show") + os.exec("msbuild") + environment.leave("toolchains") + os.setenv("path", path) + os.cd("..") + os.tryrm(vstype) + end + + os.cd("..") +end -- cgit v1.3.1 From ac06d2aa0eb76a933a843aa37878535a427e8599 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 13:21:15 +0800 Subject: fix env --- tests/plugins/project/test.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index a9f1fa37e..b647d52d9 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -1,5 +1,6 @@ import("detect.sdks.find_vstudio") import("core.project.config") +import("core.platform.platform") import("core.platform.environment") function test_vsxmake(t) @@ -14,17 +15,23 @@ function test_vsxmake(t) os.cd("c") - for name, data in pairs(vs) do - local vstype = "vsxmake" .. name - local path = os.getenv("path") - os.setenv("path", data.vcvarsall[arch].path) + for name, _ in pairs(vs) do + -- set config + config.set("arch", arch) + config.set("vs", name) + config.check() + platform.load(config.plat()) environment.enter("toolchains") + + local vstype = "vsxmake" .. name + -- create sln & vcxproj os.execv("xmake", {"project", "-k", vstype, "-a", arch}) os.cd(vstype) + -- run msbuild os.exec("msbuild /t:show") os.exec("msbuild") environment.leave("toolchains") - os.setenv("path", path) + -- clean up os.cd("..") os.tryrm(vstype) end -- cgit v1.3.1 From 5416165e691abf933a3b045ed53e8592f8a6e836 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 13:29:55 +0800 Subject: print output in ci --- .appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 760cd6834..11d509f0b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -112,6 +112,8 @@ test_script: xmake lua --verbose --diagnosis runner.lua $_.fullname >stdout_file 2>stderr_file $outcome = if ($?) { "Passed" } else { $all_success = $false; "Failed" } } + Get-Content stdout_file | Out-Host + Get-Content stderr_file | Out-Host Update-AppveyorTest -Name $testname -Framework "xmake-test" -FileName $filename -Outcome $outcome -Duration $time.TotalMilliseconds -StdOut (Get-Content -Raw stdout_file) -StdErr (Get-Content -Raw stderr_file) } - ps: Pop-Location -- cgit v1.3.1 From 6147d0287aa0fee9862308512fb39e6f10f0bde8 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 13:50:39 +0800 Subject: fix log --- tests/cli/utils/test.lua | 4 ++-- tests/plugins/project/test.lua | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/cli/utils/test.lua b/tests/cli/utils/test.lua index f06a303a9..e54f5d0e6 100644 --- a/tests/cli/utils/test.lua +++ b/tests/cli/utils/test.lua @@ -6,7 +6,7 @@ end function test_help(t) import("core.base.task") - for _, t in ipairs(task.names()) do - os.execv("xmake", {t, "--help"}) + for _, taskname in ipairs(task.names()) do + os.runv("xmake", {taskname, "--help"}) end end diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index b647d52d9..1df87394e 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -28,8 +28,30 @@ function test_vsxmake(t) os.execv("xmake", {"project", "-k", vstype, "-a", arch}) os.cd(vstype) -- run msbuild - os.exec("msbuild /t:show") - os.exec("msbuild") + try + { + function () + return os.iorun("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") + end, + finally + { + function (ok, stdout, stderr) + if ok then + return + end + print("run msbuild for %s", vstype) + io.write("--- msbuild output ---") + io.write(stdout, "\n", stderr) + io.write("--- sln file ---") + io.write(io.readfile("c_" .. vstype .. ".sln"), "\n") + io.write("--- vcx file ---") + io.write(io.readfile("project/project.vcxproj"), "\n") + io.write("--- filter file ---") + io.write(io.readfile("project/project.vcxprok.filters"), "\n") + raise("msbuild failed") + end + } + } environment.leave("toolchains") -- clean up os.cd("..") -- cgit v1.3.1 From c8b3a2ec036c524dfec06f5e7416a3fd27c6f8a1 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 13:52:19 +0800 Subject: only 2010~ --- tests/plugins/project/test.lua | 74 ++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 1df87394e..9ee9866c8 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -16,46 +16,48 @@ function test_vsxmake(t) os.cd("c") for name, _ in pairs(vs) do - -- set config - config.set("arch", arch) - config.set("vs", name) - config.check() - platform.load(config.plat()) - environment.enter("toolchains") + if tonumber(vs) >= 2010 then + -- set config + config.set("arch", arch) + config.set("vs", name) + config.check() + platform.load(config.plat()) + environment.enter("toolchains") - local vstype = "vsxmake" .. name - -- create sln & vcxproj - os.execv("xmake", {"project", "-k", vstype, "-a", arch}) - os.cd(vstype) - -- run msbuild - try - { - function () - return os.iorun("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") - end, - finally + local vstype = "vsxmake" .. name + -- create sln & vcxproj + os.execv("xmake", {"project", "-k", vstype, "-a", arch}) + os.cd(vstype) + -- run msbuild + try { - function (ok, stdout, stderr) - if ok then - return + function () + return os.iorun("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") + end, + finally + { + function (ok, stdout, stderr) + if ok then + return + end + print("run msbuild for %s", vstype) + io.write("--- msbuild output ---") + io.write(stdout, "\n", stderr) + io.write("--- sln file ---") + io.write(io.readfile("c_" .. vstype .. ".sln"), "\n") + io.write("--- vcx file ---") + io.write(io.readfile("project/project.vcxproj"), "\n") + io.write("--- filter file ---") + io.write(io.readfile("project/project.vcxprok.filters"), "\n") + raise("msbuild failed") end - print("run msbuild for %s", vstype) - io.write("--- msbuild output ---") - io.write(stdout, "\n", stderr) - io.write("--- sln file ---") - io.write(io.readfile("c_" .. vstype .. ".sln"), "\n") - io.write("--- vcx file ---") - io.write(io.readfile("project/project.vcxproj"), "\n") - io.write("--- filter file ---") - io.write(io.readfile("project/project.vcxprok.filters"), "\n") - raise("msbuild failed") - end + } } - } - environment.leave("toolchains") - -- clean up - os.cd("..") - os.tryrm(vstype) + environment.leave("toolchains") + -- clean up + os.cd("..") + os.tryrm(vstype) + end end os.cd("..") -- cgit v1.3.1 From 0566af6ff1659597f1bf597e2762a15dbc680257 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 14:08:54 +0800 Subject: fix project test --- tests/plugins/project/test.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 9ee9866c8..16a27b5f3 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -16,7 +16,7 @@ function test_vsxmake(t) os.cd("c") for name, _ in pairs(vs) do - if tonumber(vs) >= 2010 then + if tonumber(name) >= 2010 then -- set config config.set("arch", arch) config.set("vs", name) @@ -32,23 +32,20 @@ function test_vsxmake(t) try { function () - return os.iorun("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") + os.exec("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") end, finally { - function (ok, stdout, stderr) + function (ok) if ok then return end - print("run msbuild for %s", vstype) - io.write("--- msbuild output ---") - io.write(stdout, "\n", stderr) io.write("--- sln file ---") io.write(io.readfile("c_" .. vstype .. ".sln"), "\n") io.write("--- vcx file ---") io.write(io.readfile("project/project.vcxproj"), "\n") io.write("--- filter file ---") - io.write(io.readfile("project/project.vcxprok.filters"), "\n") + io.write(io.readfile("project/project.vcxproj.filters"), "\n") raise("msbuild failed") end } -- cgit v1.3.1 From 89baf2ecdca1fb8bd25c449b3f3b05b47706377d Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 14:21:09 +0800 Subject: fix sln --- tests/plugins/project/test.lua | 6 +++--- xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 16a27b5f3..32fffd33c 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -40,11 +40,11 @@ function test_vsxmake(t) if ok then return end - io.write("--- sln file ---") + io.write("--- sln file ---\n") io.write(io.readfile("c_" .. vstype .. ".sln"), "\n") - io.write("--- vcx file ---") + io.write("--- vcx file ---\n") io.write(io.readfile("project/project.vcxproj"), "\n") - io.write("--- filter file ---") + io.write("--- filter file ---\n") io.write(io.readfile("project/project.vcxproj.filters"), "\n") raise("msbuild failed") end diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln b/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln index bc2872afe..fa719dfff 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln +++ b/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln @@ -20,11 +20,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Properties", "Properties", EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution -#Import(SlnConfig)# - EndGlobalSection +#Import(SlnConfig)# EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -#Import(ProjConfig)# - EndGlobalSection +#Import(ProjConfig)# EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection -- cgit v1.3.1 From 9a10fde3739ccf1c5ef10657a827fa43076362da Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 14:33:37 +0800 Subject: remove project file; use catch --- tests/plugins/project/c/src/main.c | 7 ---- tests/plugins/project/c/xmake.lua | 77 -------------------------------------- tests/plugins/project/test.lua | 22 ++++++----- 3 files changed, 13 insertions(+), 93 deletions(-) delete mode 100644 tests/plugins/project/c/src/main.c delete mode 100644 tests/plugins/project/c/xmake.lua diff --git a/tests/plugins/project/c/src/main.c b/tests/plugins/project/c/src/main.c deleted file mode 100644 index 9ae580511..000000000 --- a/tests/plugins/project/c/src/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - printf("hello world!\n"); - return 0; -} diff --git a/tests/plugins/project/c/xmake.lua b/tests/plugins/project/c/xmake.lua deleted file mode 100644 index 72c4eb5f7..000000000 --- a/tests/plugins/project/c/xmake.lua +++ /dev/null @@ -1,77 +0,0 @@ - --- add modes: debug and release -add_rules("mode.debug", "mode.release") - --- add target -target("project") - - -- set kind - set_kind("binary") - - -- add files - add_files("src/*.c") - - --- --- FAQ --- --- You can enter the project directory firstly before building project. --- --- $ cd projectdir --- --- 1. How to build project? --- --- $ xmake --- --- 2. How to configure project? --- --- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] --- --- 3. Where is the build output directory? --- --- The default output directory is `./build` and you can configure the output directory. --- --- $ xmake f -o outputdir --- $ xmake --- --- 4. How to run and debug target after building project? --- --- $ xmake run [targetname] --- $ xmake run -d [targetname] --- --- 5. How to install target to the system directory or other output directory? --- --- $ xmake install --- $ xmake install -o installdir --- --- 6. Add some frequently-used compilation flags in xmake.lua --- --- @code --- -- add macro defination --- add_defines("NDEBUG", "_GNU_SOURCE=1") --- --- -- set warning all as error --- set_warnings("all", "error") --- --- -- set language: c99, c++11 --- set_languages("c99", "cxx11") --- --- -- set optimization: none, faster, fastest, smallest --- set_optimize("fastest") --- --- -- add include search directories --- add_includedirs("/usr/include", "/usr/local/include") --- --- -- add link libraries and search directories --- add_links("tbox", "z", "pthread") --- add_linkdirs("/usr/local/lib", "/usr/lib") --- --- -- add compilation and link flags --- add_cxflags("-stdnolib", "-fno-strict-aliasing") --- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) --- --- @endcode --- --- 7. If you want to known more usage about xmake, please see http://xmake.io/#/home --- - diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 32fffd33c..0bf08208c 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -9,11 +9,16 @@ function test_vsxmake(t) return t:skip("wrong host platform") end + local projname = "testproj" + + -- create project + os.runv("xmake", {"create", projname}) + -- build project local vs = find_vstudio() local arch = os.getenv("platform") or "x86" - os.cd("c") + os.cd(projname) for name, _ in pairs(vs) do if tonumber(name) >= 2010 then @@ -34,18 +39,15 @@ function test_vsxmake(t) function () os.exec("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") end, - finally + catch { - function (ok) - if ok then - return - end + function () io.write("--- sln file ---\n") - io.write(io.readfile("c_" .. vstype .. ".sln"), "\n") + io.write(io.readfile(projname .. "_" .. vstype .. ".sln"), "\n") io.write("--- vcx file ---\n") - io.write(io.readfile("project/project.vcxproj"), "\n") + io.write(io.readfile(projname .. "/" .. projname .. ".vcxproj"), "\n") io.write("--- filter file ---\n") - io.write(io.readfile("project/project.vcxproj.filters"), "\n") + io.write(io.readfile(projname .. "/" .. projname .. ".vcxproj.filters"), "\n") raise("msbuild failed") end } @@ -57,5 +59,7 @@ function test_vsxmake(t) end end + -- clean up os.cd("..") + os.tryrm(projname) end -- cgit v1.3.1 From 91debb265e334b111d65d2356e4bc1cca390ed41 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 15:08:10 +0800 Subject: add force --- tests/plugins/project/test.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 0bf08208c..3109f09ca 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -23,8 +23,8 @@ function test_vsxmake(t) for name, _ in pairs(vs) do if tonumber(name) >= 2010 then -- set config - config.set("arch", arch) - config.set("vs", name) + config.set("arch", arch, {readonly = true, force = true}) + config.set("vs", name, {readonly = true, force = true}) config.check() platform.load(config.plat()) environment.enter("toolchains") @@ -43,11 +43,11 @@ function test_vsxmake(t) { function () io.write("--- sln file ---\n") - io.write(io.readfile(projname .. "_" .. vstype .. ".sln"), "\n") + io.cat(projname .. "_" .. vstype .. ".sln") io.write("--- vcx file ---\n") - io.write(io.readfile(projname .. "/" .. projname .. ".vcxproj"), "\n") + io.cat(projname .. "/" .. projname .. ".vcxproj") io.write("--- filter file ---\n") - io.write(io.readfile(projname .. "/" .. projname .. ".vcxproj.filters"), "\n") + io.cat(projname .. "/" .. projname .. ".vcxproj.filters") raise("msbuild failed") end } -- cgit v1.3.1 From bc28d40dc9ac96169b564d747f83f446165fba0f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 15:17:11 +0800 Subject: change flag order --- xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index dc9e6922f..05102ab40 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -19,7 +19,7 @@ <_XmakeBuilDir>$([MSBuild]::MakeRelative('$(XmakeProjectDir)', '$(XmakeBuilDir)').TrimEnd('/\'.ToCharArray())) <_XmakeConfigFlags>$(XmakeConfigFlags.Trim()) - <_XmakeConfigFlags>$(_XmakeConfigFlags) -p $(XmakePlat) -m $(XmakeMode) -a $(XmakeArch) -o "$(_XmakeBuilDir)" + <_XmakeConfigFlags>-p $(XmakePlat) -m $(XmakeMode) -a $(XmakeArch) -o "$(_XmakeBuilDir)" $(_XmakeConfigFlags) <_XmakeBuildFlags>$(XmakeBuildFlags.Trim()) <_XmakeBuildFlags Condition="$(XmakeWarning)">$(_XmakeBuildFlags) -w -- cgit v1.3.1 From bfeab8e24d26c92b8f52cf5aba431920e3bc6f11 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 16:12:42 +0800 Subject: fix test --- tests/plugins/project/test.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 3109f09ca..4f6ec3cc7 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -21,7 +21,7 @@ function test_vsxmake(t) os.cd(projname) for name, _ in pairs(vs) do - if tonumber(name) >= 2010 then + if tonumber(name) > 2010 then -- set config config.set("arch", arch, {readonly = true, force = true}) config.set("vs", name, {readonly = true, force = true}) -- cgit v1.3.1 From a0192acccc14a218b79d73ed6013f5862abefd4f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 16:49:39 +0800 Subject: use tempdir for test --- tests/plugins/project/test.lua | 84 ++++++++++++++++++++---------------------- tests/runner.lua | 2 + 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 4f6ec3cc7..649a2e944 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -11,55 +11,49 @@ function test_vsxmake(t) local projname = "testproj" + local tempdir = os.tmpdir() + os.mkdir(tempdir) + os.cd(tempdir) + -- create project os.runv("xmake", {"create", projname}) - - -- build project - local vs = find_vstudio() - local arch = os.getenv("platform") or "x86" - os.cd(projname) - for name, _ in pairs(vs) do - if tonumber(name) > 2010 then - -- set config - config.set("arch", arch, {readonly = true, force = true}) - config.set("vs", name, {readonly = true, force = true}) - config.check() - platform.load(config.plat()) - environment.enter("toolchains") - - local vstype = "vsxmake" .. name - -- create sln & vcxproj - os.execv("xmake", {"project", "-k", vstype, "-a", arch}) - os.cd(vstype) - -- run msbuild - try - { - function () - os.exec("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") - end, - catch - { - function () - io.write("--- sln file ---\n") - io.cat(projname .. "_" .. vstype .. ".sln") - io.write("--- vcx file ---\n") - io.cat(projname .. "/" .. projname .. ".vcxproj") - io.write("--- filter file ---\n") - io.cat(projname .. "/" .. projname .. ".vcxproj.filters") - raise("msbuild failed") - end - } - } - environment.leave("toolchains") - -- clean up - os.cd("..") - os.tryrm(vstype) - end - end + -- set config + local arch = os.getenv("platform") or "x86" + config.set("arch", arch, {readonly = true, force = true}) + config.check() + platform.load(config.plat()) + local vs = config.get("vs") + environment.enter("toolchains") + + local vstype = "vsxmake" .. vs + -- create sln & vcxproj + os.execv("xmake", {"project", "-k", vstype, "-a", arch}) + os.cd(vstype) + + -- run msbuild + try + { + function () + os.exec("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") + end, + catch + { + function () + io.write("--- sln file ---\n") + io.cat(projname .. "_" .. vstype .. ".sln") + io.write("--- vcx file ---\n") + io.cat(projname .. "/" .. projname .. ".vcxproj") + io.write("--- filter file ---\n") + io.cat(projname .. "/" .. projname .. ".vcxproj.filters") + raise("msbuild failed") + end + } + } + environment.leave("toolchains") -- clean up - os.cd("..") - os.tryrm(projname) + os.cd(os.scriptdir()) + os.tryrm(tempdir) end diff --git a/tests/runner.lua b/tests/runner.lua index 227e66a7f..c99142170 100644 --- a/tests/runner.lua +++ b/tests/runner.lua @@ -44,6 +44,8 @@ function main(script) local result = try { function () + -- set workdir for each test + os.cd(root) return v(context) end, catch -- cgit v1.3.1 From 18714381a6257fd93c93344cb559fc409f6b1017 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 16 Jul 2019 17:08:14 +0800 Subject: [skip ci] fix temp path --- tests/plugins/project/test.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 649a2e944..c6e1069d9 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -11,7 +11,7 @@ function test_vsxmake(t) local projname = "testproj" - local tempdir = os.tmpdir() + local tempdir = os.tmpfile() os.mkdir(tempdir) os.cd(tempdir) -- cgit v1.3.1