diff options
| author | ruki <[email protected]> | 2025-06-12 09:05:02 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-12 09:05:02 +0800 |
| commit | aa951bad4efc83de89bdf82ee9430a89e951fe37 (patch) | |
| tree | 0ba82c107972174568df774c356fd8881b2e3052 | |
| parent | 773407f7df280a5fc50d2aa6419875297e711bb2 (diff) | |
| parent | c02d24431fd3392a19064760f7627738d72b3ef6 (diff) | |
Merge pull request #6538 from xmake-io/vsxmake
Improve vsxmake generator with namespaces
6 files changed, 22 insertions, 18 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vsutils.lua b/xmake/plugins/project/vstudio/impl/vsutils.lua index 9abf7a7b9..265a7c7aa 100644 --- a/xmake/plugins/project/vstudio/impl/vsutils.lua +++ b/xmake/plugins/project/vstudio/impl/vsutils.lua @@ -52,3 +52,7 @@ function vsarch(arch) return arch end +-- translate file path (with namespace characters '::', it's invalid path characters on windows) +function translate_path(filepath) + return (filepath:gsub("::", "#")) +end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index d9c4b4b6b..670f5d994 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -495,9 +495,10 @@ function main(outputdir, vsinfo) local _target = targets[targetname] -- init target info - _target.target = targetname + _target.targetname = targetname + _target.targetname_inpath = vsutils.translate_path(targetname) _target.vcxprojdir = path.join(vsinfo.vcxproj_rootdir, targetname) - _target.vcxprojdir_relative_sln = path.relative(_target.vcxprojdir, vsinfo.solution_dir) + _target.vcxprojdir_relative_sln = vsutils.translate_path(path.relative(_target.vcxprojdir, vsinfo.solution_dir)) _target.target_id = hash.uuid4(targetname) _target.kind = target:kind() _target.absscriptdir = target:scriptdir() diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index d5cd5e078..6477e9982 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -26,6 +26,7 @@ import("render") import("getinfo") import("core.project.config") import("core.cache.localcache") +import("vstudio.impl.vsutils", {rootdir = path.join(os.programdir(), "plugins", "project")}) local template_root = path.join(os.programdir(), "scripts", "vsxmake", "vsproj", "templates") local template_sln = path.join(template_root, "sln", "vsxmake.sln") @@ -166,6 +167,7 @@ end function _trycp(file, target, targetname) targetname = targetname or path.filename(file) local targetfile = path.join(target, targetname) + targetfile = vsutils.translate_path(targetfile) if os.isfile(targetfile) then dprint("skipped file %s since the file already exists", path.relative(targetfile)) return @@ -174,6 +176,7 @@ function _trycp(file, target, targetname) end function _writefileifneeded(file, content) + file = vsutils.translate_path(file) if os.isfile(file) and io.readfile(file) == content then dprint("skipped file %s since the file has the same content", path.relative(file)) return @@ -219,11 +222,7 @@ function make(version) end return function(outputdir) - - -- trace vprint("using project kind vs%d", version) - - -- check assert(version >= 2010, "vsxmake does not support vs version lower than 2010") -- get info and params @@ -240,20 +239,20 @@ function make(version) for _, target in ipairs(info.targets) do local paramsprovidertarget = _buildparams(info, target, "<!-- nil -->") - local proj_dir = info._targets[target].vcxprojdir + local vcxproj_dir = info._targets[target].vcxprojdir -- write project file - local proj = path.join(proj_dir, target .. ".vcxproj") - _writefileifneeded(proj, render(template_vcx, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) + local vcxproj_file = path.join(vcxproj_dir, target .. ".vcxproj") + _writefileifneeded(vcxproj_file, render(template_vcx, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) - local projfil = path.join(proj_dir, target .. ".vcxproj.filters") - _writefileifneeded(projfil, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) + local vcxproj_filters = path.join(vcxproj_dir, target .. ".vcxproj.filters") + _writefileifneeded(vcxproj_filters, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) -- add project custom file - _trycp(template_props, proj_dir) - _trycp(template_targets, proj_dir) - _trycp(template_items, proj_dir) - _trycp(template_itemfil, proj_dir) + _trycp(template_props, vcxproj_dir) + _trycp(template_targets, vcxproj_dir) + _trycp(template_items, vcxproj_dir) + _trycp(template_itemfil, vcxproj_dir) end -- clear config and local cache diff --git a/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) b/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) index 87d435af2..e53697651 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) +++ b/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) @@ -1,2 +1,2 @@ -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "#target#", "#vcxprojdir_relative_sln#\#target#.vcxproj", "{#target_id#}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "#targetname#", "#vcxprojdir_relative_sln#\#targetname_inpath#.vcxproj", "{#target_id#}" EndProject diff --git a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj index 44af5ac40..21a7eb99a 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj +++ b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj @@ -21,7 +21,7 @@ <XmakeScriptDir>#scriptdir#</XmakeScriptDir> <XmakeProjectDir>#projectdir#</XmakeProjectDir> <XmakeProjectFile>#projectfile#</XmakeProjectFile> - <XmakeTarget>#target#</XmakeTarget> + <XmakeTarget>#targetname#</XmakeTarget> </PropertyGroup> <PropertyGroup Label="XmakeProgram"> <XmakeProgramDir Condition="'$(XmakeProgramDir)' == ''">$(XMAKE_PROGRAM_DIR)</XmakeProgramDir> diff --git a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) index 33434eca3..13ef4b251 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) +++ b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) @@ -1,3 +1,3 @@ - <ProjectReference Include="..\#target#\#target#.vcxproj"> + <ProjectReference Include="..\#targetname_inpath#\#targetname_inpath#.vcxproj"> <Project>{#target_id#}</Project> </ProjectReference> |
