diff options
| author | ruki <[email protected]> | 2022-02-17 22:29:37 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-17 22:29:37 +0800 |
| commit | cdf8579ede7256d63f6d9c83d77b44cd9547b964 (patch) | |
| tree | 28d8af75b2cedd0ee5557c7f359e257348c37167 | |
| parent | fe5673d0291653137c3ecc53c2abba5c162a6779 (diff) | |
| parent | bc9295aa19e645432c0edb48b34a66e68a78d96c (diff) | |
Merge pull request #2062 from xmake-io/fixmodules
Fix modules path for msvc
16 files changed, 97 insertions, 30 deletions
diff --git a/.github/workflows/archlinux.yml b/.github/workflows/archlinux.yml index c9fb04cb4..035433687 100644 --- a/.github/workflows/archlinux.yml +++ b/.github/workflows/archlinux.yml @@ -19,9 +19,11 @@ jobs: - name: Prepare build tools run: | pacman -Sy --noconfirm --needed git base-devel perl make unzip + - uses: actions/checkout@v2 with: submodules: true + - name: prepare local xmake run: | cp -rf . ../xmake-source diff --git a/tests/projects/c++/modules/hello with spaces/src/hello.mpp b/tests/projects/c++/modules/hello with spaces/src/hello.mpp new file mode 100644 index 000000000..124bd72bc --- /dev/null +++ b/tests/projects/c++/modules/hello with spaces/src/hello.mpp @@ -0,0 +1,10 @@ +module; +#include <cstdio> + +export module hello; + +export namespace hello { + void say(const char* str) { + printf("%s\n", str); + } +} diff --git a/tests/projects/c++/modules/hello with spaces/src/main.cpp b/tests/projects/c++/modules/hello with spaces/src/main.cpp new file mode 100644 index 000000000..1e5cc698f --- /dev/null +++ b/tests/projects/c++/modules/hello with spaces/src/main.cpp @@ -0,0 +1,6 @@ +import hello; + +int main() { + hello::say("hello module!"); + return 0; +} diff --git a/tests/projects/c++/modules/hello with spaces/xmake.lua b/tests/projects/c++/modules/hello with spaces/xmake.lua new file mode 100644 index 000000000..4f46b699d --- /dev/null +++ b/tests/projects/c++/modules/hello with spaces/xmake.lua @@ -0,0 +1,5 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") +target("A hello") + set_kind("binary") + add_files("src/*.cpp", "src/*.mpp") diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 6f5f0360b..506d8cdad 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1060,7 +1060,9 @@ function interpreter:api_register_set_values(scope_kind, ...) end -- expand values - values = table.join(table.unpack(values)) + if not extra_config or extra_config.expand ~= false then + values = table.join(table.unpack(values)) + end -- save values if #values > 0 then @@ -1100,7 +1102,9 @@ function interpreter:api_register_add_values(scope_kind, ...) end -- expand values - values = table.join(table.unpack(values)) + if not extra_config or extra_config.expand ~= false then + values = table.join(table.unpack(values)) + end -- save values scope[name] = table.join2(scope[name] or {}, values) diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 26be325eb..8a69a9299 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -114,7 +114,9 @@ function _instance:_api_set_values(name, ...) end -- expand values - values = table.join(table.unpack(values)) + if not extra_config or extra_config.expand ~= false then + values = table.join(table.unpack(values)) + end -- handle values local handled_values = self:_api_handle(name, values) @@ -153,7 +155,9 @@ function _instance:_api_add_values(name, ...) end -- expand values - values = table.join(table.unpack(values)) + if not extra_config or extra_config.expand ~= false then + values = table.join(table.unpack(values)) + end -- save values scope[name] = self:_api_handle(name, table.join2(table.wrap(scope[name]), values)) diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 2bf776151..9868c93d5 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -120,6 +120,24 @@ function table.join2(self, ...) return self end +-- shallow join all objects, it will not expand all table values +function table.shallow_join(...) + local result = {} + for _, t in ipairs({...}) do + table.insert(result, t) + end + return result +end + + +-- shallow join all objects, it will not expand all table values +function table.shallow_join2(self, ...) + for _, t in ipairs({...}) do + table.insert(self, t) + end + return self +end + -- swap items in array function table.swap(array, i, j) local val = array[i] diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 343eec0ae..b7ef1fdc0 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -58,11 +58,13 @@ function builder:_mapflag(flag, flagkind, mapflags, auto_ignore_flags) return flag_mapped end - -- find and replace it using pattern - for k, v in pairs(mapflags) do - local flag_mapped, count = flag:gsub("^" .. k .. "$", function (w) return v end) - if flag_mapped and count ~= 0 then - return #flag_mapped ~= 0 and flag_mapped + -- find and replace it using pattern, maybe flag is table, e.g. {"-I", "/xxx"} + if type(flag) == "string" then + for k, v in pairs(mapflags) do + local flag_mapped, count = flag:gsub("^" .. k .. "$", function (w) return v end) + if flag_mapped and count ~= 0 then + return #flag_mapped ~= 0 and flag_mapped + end end end @@ -70,7 +72,7 @@ function builder:_mapflag(flag, flagkind, mapflags, auto_ignore_flags) if auto_ignore_flags == false or self:has_flags(flag, flagkind) then return flag else - utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` or call `set_policy(\"check.auto_ignore_flags\", false)` if you want to set it.", flagkind, flag) + utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` or call `set_policy(\"check.auto_ignore_flags\", false)` if you want to set it.", flagkind, os.args(flag)) end end @@ -132,12 +134,13 @@ function builder:_add_flags_from_flagkind(flags, target, flagkind, opt) local extraconf = target:extraconf(flagkind) if extraconf then for _, flag in ipairs(table.wrap(targetflags)) do - -- force to add flags? + -- @note we need join the single flag with shallow mode, aboid expand table values + -- e.g. add_cflags({"-I", "/tmp/xxx foo"}, {force = true, expand = false}) local flagconf = extraconf[flag] if flagconf and flagconf.force then - table.join2(flags, flag) + table.shallow_join2(flags, flag) else - table.join2(flags, self:_mapflags(flag, flagkind, target)) + table.shallow_join2(flags, self:_mapflag(flag, flagkind, target)) end end else diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index b76061cd7..b499542e3 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -112,11 +112,14 @@ function nf_symbols(self, levels, target) end -- check and add symbol output file - local pdbflags = "-Fd" .. (target:is_static() and symbolfile or path.join(symboldir, "compile." .. path.filename(symbolfile))) + -- + -- @note we need use `{}` to wrap it to avoid expand it + -- https://github.com/xmake-io/xmake/issues/2061#issuecomment-1042590085 + local pdbflags = {"-Fd" .. (target:is_static() and symbolfile or path.join(symboldir, "compile." .. path.filename(symbolfile)))} if self:has_flags({"-FS", "-Fd" .. os.nuldev() .. ".pdb"}, "cxflags", { flagskey = "-FS -Fd" }) then - pdbflags = {"-FS", pdbflags} + table.insert(pdbflags, 1, "-FS") end - table.join2(flags, pdbflags) + table.insert(flags, pdbflags) end end return flags diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index ce78b88e9..e89a40260 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -62,6 +62,7 @@ <_XmakeCleanFlags>$(_XmakeCleanFlags.Trim())</_XmakeCleanFlags> <_XmakeConfigFlags>$(_XmakeConfigFlags.Trim())</_XmakeConfigFlags> <_XmakeCommonFlags>$(_XmakeCommonFlags.Trim())</_XmakeCommonFlags> + <_XmakeTarget>"$(XmakeTarget.Trim())"</_XmakeTarget> <_XmakeExecutable>"$([System.IO.Path]::GetFullPath('$(XmakeProgramDirResolved)xmake.exe'))"</_XmakeExecutable> <_XmakeEnv> @@ -97,14 +98,14 @@ $(_XmakeExecutable) config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="_XmakeBuild" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="_XmakeRebuild" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="_XmakeBuildFile" DependsOnTargets="_XmakeProjCheck"> <ItemGroup> @@ -114,14 +115,14 @@ <PropertyGroup> <FileFlag>--files="@(File)"</FileFlag> </PropertyGroup> - <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(XmakeTarget)" Importance="High" /> + <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(_XmakeTarget)" Importance="High" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(XmakeTarget)" EchoOff="true" /> + $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(_XmakeTarget)" EchoOff="true" /> </Target> <Target Name="_XmakeClean" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(_XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(_XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="Show"> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters index 02ae9b11b..eee3d1a12 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters @@ -38,6 +38,7 @@ <ItemGroup> #Import(File.c)# #Import(File.cxx)# +#Import(File.mpp)# #Import(File.cu)# </ItemGroup> <ItemGroup> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.mpp(filempp) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.mpp(filempp) new file mode 100644 index 000000000..6588bbf15 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.mpp(filempp) @@ -0,0 +1,3 @@ + <None Include="$(XmakeProjectDir)\#path#"> + <Filter>#dir#</Filter> + </None> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj index 3574c7d4d..111dd454b 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj @@ -38,6 +38,7 @@ <ItemGroup> #Import(File.c)# #Import(File.cxx)# +#Import(File.mpp)# #Import(File.cu)# </ItemGroup> <ItemGroup> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.mpp(filempp) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.mpp(filempp) new file mode 100644 index 000000000..3df4626b5 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.mpp(filempp) @@ -0,0 +1 @@ + <None Include="$(XmakeProjectDir)\#path#" /> diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index 469448764..d152cc383 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -123,6 +123,9 @@ function _buildparams(info, target, default) elseif args.filecxx then local files = info._targets[target].sourcefiles table.insert(r, _filter_files(files, {".cpp", ".cc", ".cxx"})) + elseif args.filempp then + local files = info._targets[target].sourcefiles + table.insert(r, _filter_files(files, {".mpp", ".mxx", ".cppm", ".ixx"})) elseif args.filecu then local files = info._targets[target].sourcefiles table.insert(r, _filter_files(files, {".cu"})) diff --git a/xmake/rules/c++/modules/build_modules/msvc.lua b/xmake/rules/c++/modules/build_modules/msvc.lua index 1dc04618f..dfaf56b41 100644 --- a/xmake/rules/c++/modules/build_modules/msvc.lua +++ b/xmake/rules/c++/modules/build_modules/msvc.lua @@ -43,7 +43,7 @@ function load_parent(target, opt) local sourcebatches = dep:sourcebatches() if sourcebatches and sourcebatches["c++.build.modules"] then local cachedir = path.join(dep:autogendir(), "rules", "modules", "cache") - target:add("cxxflags", "/ifcSearchDir " .. os.args(cachedir), {force = true}) + target:add("cxxflags", {"/ifcSearchDir", cachedir}, {force = true, expand = true}) end end end @@ -128,8 +128,10 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) local sourcefile = sourcebatch.sourcefiles[i] local moduledep = assert(moduledeps_files[sourcefile], "moduledep(%s) not found!", sourcefile) moduledep.job = batchjobs:newjob(sourcefile, function (index, total) - local opt2 = table.join(opt, {configs = {force = {cxxflags = {interfaceflag, - outputflag .. " " .. os.args(modulefiles[i]), "/TP"}}}}) + local opt2 = table.join(opt, {configs = {force = {cxxflags = { + interfaceflag, + {outputflag, modulefiles[i]}, + "/TP"}}}}) opt2.progress = (index * 100) / total opt2.objectfile = sourcebatch.objectfiles[i] opt2.dependfile = sourcebatch.dependfiles[i] @@ -140,7 +142,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) count = count + 1 if count == sourcefiles_total and not cachedir then for _, modulefile in ipairs(modulefiles) do - target:add("cxxflags", referenceflag .. " " .. os.args(modulefile)) + target:add("cxxflags", {referenceflag, modulefile}, {force = true, expand = false}) end end end) @@ -149,7 +151,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) -- add module flags target:add("cxxflags", modulesflag) if cachedir then - target:add("cxxflags", "/ifcSearchDir " .. os.args(cachedir)) + target:add("cxxflags", {"/ifcSearchDir", cachedir}, {force = true, expand = false}) end if stdifcdirflag then for _, toolchain_inst in ipairs(target:toolchains()) do @@ -158,7 +160,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) if vcvars.VCInstallDir and vcvars.VCToolsVersion then local stdifcdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "ifc", target:is_arch("x64") and "x64" or "x86") if os.isdir(stdifcdir) then - target:add("cxxflags", stdifcdirflag .. " " .. winos.short_path(stdifcdir)) + target:add("cxxflags", {stdifcdirflag, winos.short_path(stdifcdir)}, {force = true, expand = false}) end end break |
