1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<%!
import re
import hashlib
def calc_to_filter(path):
return '\\'.join(path.split('/')[:-1])
%>\
<%def name="get_repo_root(proj)">${'..\..\..' + ('\..' if proj.vs_proj_dir != '.' else '')}</%def>\
<%def name="to_windows_path(path)">${path.replace('/','\\')}</%def>\
<%def name="to_filter(path)">${calc_to_filter(path)}</%def>\
<%def name="filter_to_guid(proj, filter)">${re.sub('(........)(....)(....)(....)', r'\1-\2-\3-\4-', hashlib.md5(''.join([filter, proj])).hexdigest())}</%def>\
<%def name="gen_filters(name, collection)">\
% for project in vsprojects:
% if project.name == name:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
% if project.get('src',[]):
<ItemGroup>
% for src_name in project.src:
<ClCompile Include="${get_repo_root(project)}\${to_windows_path(src_name)}">
<Filter>${to_filter(src_name)}</Filter>
</ClCompile>
% endfor
</ItemGroup>
% endif
% if project.get('public_headers',[]):
<ItemGroup>
% for public_header in project.public_headers:
<ClInclude Include="${get_repo_root(project)}\${to_windows_path(public_header)}">
<Filter>${to_filter(public_header)}</Filter>
</ClInclude>
% endfor
</ItemGroup>
% endif
% if project.get('headers',[]):
<ItemGroup>
% for header in project.headers:
<ClInclude Include="${get_repo_root(project)}\${to_windows_path(header)}">
<Filter>${to_filter(header)}</Filter>
</ClInclude>
% endfor
</ItemGroup>
% endif
<%
filters = set()
files = project.get('src', []) + project.get('public_headers', []) + project.get('headers', [])
for file in files:
filter = calc_to_filter(file)
paths = filter.split('\\')
for i in range(len(paths)):
filters.add('\\'.join(paths[:i + 1]))
filters = sorted(filters)
%>
<ItemGroup>
% for filter in filters:
<Filter Include="${filter}">
<UniqueIdentifier>{${filter_to_guid(project.name, filter)}}</UniqueIdentifier>
</Filter>
% endfor
</ItemGroup>
</Project>
% endif
% endfor
</%def>\
|