diff options
| author | ruki <[email protected]> | 2022-04-20 00:52:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-20 00:52:54 +0800 |
| commit | e71bc3a2e6d2f71784cdbf5463706311cb25efb2 (patch) | |
| tree | da26349c0142fcfdaa4fd608ad5bee64b5f1987b | |
| parent | e807230557aac69e4d583c75626e3a7ebdb922f8 (diff) | |
improve filter and support file group for vsxmake
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 5 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua | 26 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 59 |
3 files changed, 81 insertions, 9 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 52ef5c7f3..29d4b3f53 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -576,13 +576,16 @@ function make(outputdir, vsinfo) _target.kind = target:kind() _target.scriptdir = target:scriptdir() _target.info = _target.info or {} - _target.instance = target table.insert(_target.info, _make_targetinfo(mode, arch, target, _target.project_dir)) -- save all sourcefiles and headerfiles _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles()))) + -- save file groups + _target.filegroups = target:get("filegroups") + _target.filegroups_extraconf = target:extraconf("filegroups") + -- make target headers _make_targetheaders(mode, arch, target, mode_idx == #vsinfo.modes and arch_idx == 2) end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua index a1647093f..b8dc48534 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua @@ -51,24 +51,36 @@ function _make_tailer(filtersfile, vsinfo) filtersfile:leave("</Project>") end +-- strip dot directories, e.g. ..\..\.. => .. +-- @see https://github.com/xmake-io/xmake/issues/2039 +function _strip_dotdirs(dir) + local count + dir, count = dir:gsub("%.%.[\\/]%.%.", "..") + if count > 0 then + dir = _strip_dotdirs(dir) + end + return dir +end + -- make filter function _make_filter(filepath, target, vcxprojdir) local filter - local targetinst = assert(target.instance, "target instance not found!") - local filegroups = targetinst:get("filegroups") + local filegroups = target.filegroups if filegroups then -- @see https://github.com/xmake-io/xmake/issues/2282 filepath = path.absolute(filepath) local scriptdir = target.scriptdir + local filegroups_extraconf = target.filegroups_extraconf or {} for _, filegroup in ipairs(filegroups) do - local rootdir = targetinst:extraconf("filegroups", filegroup, "rootdir") + local extraconf = filegroups_extraconf[filegroup] or {} + local rootdir = extraconf.rootdir assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup) if not path.is_absolute(rootdir) then rootdir = path.absolute(rootdir, scriptdir) end local fileitem = path.relative(filepath, rootdir) - local files = targetinst:extraconf("filegroups", filegroup, "files") or "**" - local mode = targetinst:extraconf("filegroups", filegroup, "mode") + local files = extraconf.files or "**" + local mode = extraconf.mode for _, filepattern in ipairs(files) do filepattern = path.pattern(path.translate(filepattern)) if fileitem:match(filepattern) then @@ -89,6 +101,10 @@ function _make_filter(filepath, target, vcxprojdir) if not filter then -- use the default filter rule filter = path.relative(path.absolute(path.directory(filepath)), target.scriptdir or vcxprojdir) + -- @see https://github.com/xmake-io/xmake/issues/2039 + if filter then + filter = _strip_dotdirs(filter) + end if filter and filter == '.' then filter = nil end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 57a7d9289..a6f5e1aaa 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -340,6 +340,57 @@ function _config_targets() end end +-- make filter +function _make_filter(filepath, target, vcxprojdir) + local filter + local filegroups = target.filegroups + if filegroups then + -- @see https://github.com/xmake-io/xmake/issues/2282 + filepath = path.absolute(filepath) + local scriptdir = target.absscriptdir + local filegroups_extraconf = target.filegroups_extraconf or {} + for _, filegroup in ipairs(filegroups) do + local extraconf = filegroups_extraconf[filegroup] or {} + local rootdir = extraconf.rootdir + assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup) + if not path.is_absolute(rootdir) then + rootdir = path.absolute(rootdir, scriptdir) + end + local fileitem = path.relative(filepath, rootdir) + local files = extraconf.files or "**" + local mode = extraconf.mode + for _, filepattern in ipairs(files) do + filepattern = path.pattern(path.translate(filepattern)) + if fileitem:match(filepattern) then + if mode == "plain" then + filter = path.translate(filegroup) + else + -- file tree mode (default) + filter = path.join(filegroup, path.directory(fileitem)) + end + if filter and filter == '.' then + filter = nil + end + break + end + end + end + end + if not filter then + -- use the default filter rule + filter = path.relative(path.absolute(path.directory(filepath)), vcxprojdir) + -- @see https://github.com/xmake-io/xmake/issues/2039 + if filter then + filter = _strip_dotdirs(filter) + end + if filter and filter == '.' then + filter = nil + end + end + return filter +end + + -- make vstudio project function main(outputdir, vsinfo) @@ -458,6 +509,10 @@ function main(outputdir, vsinfo) _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles()))) + -- save file groups + _target.filegroups = target:get("filegroups") + _target.filegroups_extraconf = target:extraconf("filegroups") + -- save deps _target.deps = table.unique(table.join(_target.deps or {}, table.keys(target:deps()), nil)) end @@ -472,10 +527,8 @@ function main(outputdir, vsinfo) target.sourcefiles = table.imap(target.sourcefiles, function(_, v) return path.relative(v, projectdir) end) target.headerfiles = table.imap(target.headerfiles, function(_, v) return path.relative(v, projectdir) end) for _, f in ipairs(table.join(target.sourcefiles, target.headerfiles)) do - local dir = path.directory(path.relative(f, root)) + local dir = _make_filter(f, target, root) local escaped_f = _escape(f) - -- @see https://github.com/xmake-io/xmake/issues/2039 - dir = _strip_dotdirs(dir) target._paths[f] = { -- @see https://github.com/xmake-io/xmake/issues/2077 |
