From 550f5225b01a3c3c0c88bc2c702d38c667b28528 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jun 2020 22:31:14 +0800 Subject: improve test --- tests/plugins/project/test.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests/plugins/project/test.lua') diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index e3295d68d..fd16f8645 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -1,7 +1,7 @@ import("detect.sdks.find_vstudio") import("core.project.config") import("core.platform.platform") -import("core.platform.environment") +import("core.tool.toolchain") function test_vsxmake(t) @@ -34,9 +34,7 @@ function test_vsxmake(t) try { function () - environment.enter("toolchains") - os.exec("msbuild /P:XmakeDiagnosis=true /P:XmakeVerbose=true") - environment.leave("toolchains") + os.execv("msbuild", {"/P:XmakeDiagnosis=true", "/P:XmakeVerbose=true"}, {envs = toolchain.load("msvc"):runenvs()}) end, catch { -- cgit v1.3.1 From cbad38152f8b3f27888fe1c5ff9c95acb25dc71e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jun 2020 23:19:31 +0800 Subject: fix test for calling msbuild --- tests/plugins/project/test.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/plugins/project/test.lua') diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index fd16f8645..a518a5aa9 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -34,7 +34,9 @@ function test_vsxmake(t) try { function () - os.execv("msbuild", {"/P:XmakeDiagnosis=true", "/P:XmakeVerbose=true"}, {envs = toolchain.load("msvc"):runenvs()}) + local runenvs = toolchain.load("msvc"):runenvs() + os.addenv("PATH", runenvs.PATH) + os.execv("msbuild", {"/P:XmakeDiagnosis=true", "/P:XmakeVerbose=true"}, {envs = runenvs}) end, catch { -- cgit v1.3.1 From bf2a6694133db7b795b71e06e5a7162b21b5e26f Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Jun 2020 16:32:17 +0800 Subject: improve to call msbuild --- tests/plugins/project/test.lua | 6 +-- xmake/actions/build/main.lua | 2 - xmake/actions/clean/main.lua | 2 - xmake/actions/config/main.lua | 4 +- xmake/modules/detect/tools/find_msbuild.lua | 55 +++++++++++++++++++++++ xmake/modules/package/tools/cmake.lua | 8 +++- xmake/modules/private/action/trybuild/cmake.lua | 11 +++-- xmake/modules/private/action/trybuild/msbuild.lua | 11 ++++- 8 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 xmake/modules/detect/tools/find_msbuild.lua (limited to 'tests/plugins/project/test.lua') diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index a518a5aa9..5cc1e7e0e 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -1,7 +1,7 @@ -import("detect.sdks.find_vstudio") import("core.project.config") import("core.platform.platform") import("core.tool.toolchain") +import("lib.detect.find_tool") function test_vsxmake(t) @@ -35,8 +35,8 @@ function test_vsxmake(t) { function () local runenvs = toolchain.load("msvc"):runenvs() - os.addenv("PATH", runenvs.PATH) - os.execv("msbuild", {"/P:XmakeDiagnosis=true", "/P:XmakeVerbose=true"}, {envs = runenvs}) + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.execv(msbuild.program, {"/P:XmakeDiagnosis=true", "/P:XmakeVerbose=true"}, {envs = runenvs}) end, catch { diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index d1c39911d..2ce139f54 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -73,9 +73,7 @@ function _try_build() if not trybuild then task.run("config", {target = targetname, trybuild = trybuild_detected}) end - environment.enter("toolchains") tool.build() - environment.leave("toolchains") return true end end diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 02f0d804a..359ed0a25 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -226,9 +226,7 @@ function _try_clean() -- try cleaning it if configfile and tool and trybuild then - environment.enter("toolchains") tool.clean() - environment.leave("toolchains") end end diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 627f70853..5af867f5a 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -249,7 +249,9 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) config.check() -- check project options - project.check() + if not trybuild then + project.check() + end end -- load platform diff --git a/xmake/modules/detect/tools/find_msbuild.lua b/xmake/modules/detect/tools/find_msbuild.lua new file mode 100644 index 000000000..38d83c5ab --- /dev/null +++ b/xmake/modules/detect/tools/find_msbuild.lua @@ -0,0 +1,55 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_msbuild.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find msbuild +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local msbuild = find_msbuild() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + opt.check = "/version" + + -- find program + local program = find_program(opt.program or "msbuild.exe", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end + diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 7299f20b4..f35b489b4 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -20,7 +20,9 @@ -- imports import("core.base.option") +import("core.tool.toolchain") import("lib.detect.find_file") +import("lib.detect.find_tool") -- get configs function _get_configs(package, configs) @@ -118,10 +120,12 @@ function install(package, configs, opt) -- do build and install if package:is_plat("windows") then local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") - os.vrun("msbuild \"%s\" -nologo -t:Rebuild -p:Configuration=%s -p:Platform=%s", slnfile, package:debug() and "Debug" or "Release", package:is_arch("x64") and "x64" or "Win32") + local runenvs = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vrunv(msbuild.program, {slnfile, "-nologo", "-t:Rebuild", "-p:Configuration=" .. (package:debug() and "Debug" or "Release"), "-p:Platform=" .. (package:is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" if os.isfile(projfile) then - os.vrun("msbuild \"%s\" /property:configuration=%s", projfile, package:debug() and "Debug" or "Release") + os.vrunv(msbuild.program, {projfile, "/property:configuration=" .. (package:debug() and "Debug" or "Release")}, {envs = runenvs}) os.trycp("install/lib", package:installdir()) -- perhaps only headers library os.cp("install/include", package:installdir()) else diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua index d5e0cbce2..684941c39 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -22,6 +22,7 @@ import("core.base.cli") import("core.base.option") import("core.project.config") +import("core.tool.toolchain") import("lib.detect.find_file") import("lib.detect.find_tool") @@ -76,7 +77,9 @@ function clean() if configfile then local oldir = os.cd(buildir) if is_plat("windows") then - os.vexec("msbuild \"%s\" -nologo -t:Clean -p:Configuration=%s -p:Platform=%s", configfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vexecv(msbuild.program, {configfile, "-nologo", "-t:Clean", "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"), "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) else os.vexec("make clean") end @@ -107,11 +110,13 @@ function build() -- do build if is_plat("windows") then + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") - os.vexec("msbuild \"%s\" -nologo -t:Build -p:Configuration=%s -p:Platform=%s", slnfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") + os.vexecv(msbuild.program, {slnfile, "-nologo", "-t:Build", "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"), "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" if os.isfile(projfile) then - os.vexec("msbuild \"%s\" /property:configuration=%s", projfile, is_mode("debug") and "Debug" or "Release") + os.vexecv(msbuild.program, {projfile, "/property:configuration=" .. (is_mode("debug") and "Debug" or "Release")}, {envs = runenvs}) end else local argv = {"-j" .. option.get("jobs")} diff --git a/xmake/modules/private/action/trybuild/msbuild.lua b/xmake/modules/private/action/trybuild/msbuild.lua index 0cd00fef9..e86830900 100644 --- a/xmake/modules/private/action/trybuild/msbuild.lua +++ b/xmake/modules/private/action/trybuild/msbuild.lua @@ -21,7 +21,9 @@ -- imports import("core.base.option") import("core.project.config") +import("core.tool.toolchain") import("lib.detect.find_file") +import("lib.detect.find_tool") -- detect build-system and configuration file function detect() @@ -32,7 +34,9 @@ end -- do clean function clean() - os.vexec("msbuild \"%s\" -nologo -t:Clean -p:Configuration=Release -p:Platform=%s", configfile, is_arch("x64") and "x64" or "Win32") + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vexecv(msbuild.program, {configfile, "-nologo", "-t:Clean", "-p:Configuration=Release", "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) end -- do build @@ -42,6 +46,9 @@ function build() assert(is_subhost(config.plat()), "msbuild: %s not supported!", config.plat()) -- do build - os.vexec("msbuild \"%s\" -nologo -t:Build -p:Configuration=Release -p:Platform=%s", configfile, is_arch("x64") and "x64" or "Win32") + local configfile = find_file("*.sln", os.curdir()) + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vexecv(msbuild.program, {configfile, "-nologo", "-t:Build", "-p:Configuration=Release", "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) cprint("${color.success}build ok!") end -- cgit v1.3.1