Merge remote-tracking branch 'github/master' into tizen
[platform/core/csapi/tizenfx.git] / build / profiles.targets
1 <Project>
2
3   <ItemDefinitionGroup>
4     <_ResourceItemsWithTargetPath>
5       <TizenProfile>$(AllTizenProfiles)</TizenProfile>
6       <CopyToOutputDirectory>Never</CopyToOutputDirectory>
7     </_ResourceItemsWithTargetPath>
8   </ItemDefinitionGroup>
9
10   <ItemGroup>
11     <AllTizenProfilesItems Include="$(AllTizenProfiles.Split(';'))" />
12     <SupportedProfilesItems Include="$(SupportedProfiles.Split(';'))" Condition="'$(SupportedProfiles)' != ''" />
13   </ItemGroup>
14
15   <Target Name="GenerateProfileFileList" Outputs="%(AllTizenProfilesItems.Identity)">
16
17     <PropertyGroup>
18       <_TargetProfile>%(AllTizenProfilesItems.Identity)</_TargetProfile>
19       <_IsProfileMatch>false</_IsProfileMatch>
20       <_IsProfileMatch Condition="'%(SupportedProfilesItems.Identity)' == '$(_TargetProfile)'">true</_IsProfileMatch>
21     </PropertyGroup>
22
23     <AssignTargetPath Files="@(None)" RootFolder="$(MSBuildProjectDirectory)">
24       <Output TaskParameter="AssignedFiles" ItemName="_ItemsWithTargetPath" />
25     </AssignTargetPath>
26
27     <ItemGroup>
28       <_ResourceItemsWithTargetPath Include="@(_ItemsWithTargetPath)"
29                                     Condition="$([System.String]::new('%(_ItemsWithTargetPath.TargetPath)').StartsWith('res/', System.StringComparison.OrdinalIgnoreCase))" />
30       <_ResourceItemsWithTargetPath Remove="@(_ResourceItemsWithTargetPath)"
31                                     Condition="'%(CopyToOutputDirectory)' == '' Or '%(CopyToOutputDirectory)' == 'Never'" />
32     </ItemGroup>
33
34     <GetProfileMatchedItems
35       Items="@(_ResourceItemsWithTargetPath)"
36       TargetProfile="$(_TargetProfile)">
37       <Output TaskParameter="MatchedItems" ItemName="_ProfileResourceItemsWithTargetPath" />
38     </GetProfileMatchedItems>
39
40     <ItemGroup>
41       <_ProfilePreloadItems Include="$(OutDir)*.preload" />
42     </ItemGroup>
43
44     <ItemGroup>
45       <_ProfileFiles Include="$(TargetFileName)" Condition="'$(_IsProfileMatch)' == 'true'" />
46       <_ProfileFiles Include="%(_ProfileResourceItemsWithTargetPath.TargetPath)" Condition="'$(_IsProfileMatch)' == 'true'" />
47       <_ProfileFiles Include="@(_ProfilePreloadItems->'%(Filename)%(Extension)')" Condition="'$(_IsProfileMatch)' == 'true'" />
48       <_ProfileFiles Include="ref/$(TargetFileName)" Condition="'$(_IsProfileMatch)' == 'false'" />
49     </ItemGroup>
50
51     <WriteLinesToFile File="$(OutDir)$(TargetName).$(_TargetProfile).filelist"
52                       Overwrite="true"
53                       Lines="@(_ProfileFiles)" />
54
55   </Target>
56
57   <UsingTask
58     TaskName="GetProfileMatchedItems"
59     TaskFactory="RoslynCodeTaskFactory"
60     AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
61     <ParameterGroup>
62       <Items Required="true" ParameterType="Microsoft.Build.Framework.ITaskItem[]" />
63       <TargetProfile Required="true" />
64       <MatchedItems ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
65     </ParameterGroup>
66     <Task>
67       <Using Namespace="System" />
68       <Using Namespace="System.IO" />
69       <Using Namespace="System.Linq" />
70       <Using Namespace="System.Collections.Generic" />
71       <Code Type="Fragment" Language="cs">
72 <![CDATA[
73   var _matchedItems = new List<ITaskItem>();
74   foreach (var item in Items) {
75     string tizenProfile = item.GetMetadata("TizenProfile");
76     if (!string.IsNullOrEmpty(tizenProfile)) {
77       string[] profiles = tizenProfile.Split(';');
78       if (profiles.Any(TargetProfile.Equals)) {
79         _matchedItems.Add(item);
80       }
81     }
82   }
83   MatchedItems = _matchedItems.ToArray();
84 ]]>
85       </Code>
86     </Task>
87   </UsingTask>
88
89 </Project>