Skip to content

Commit

Permalink
♻️ 重构Shimakaze.Sdk.RA2使其功能正常
Browse files Browse the repository at this point in the history
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
  • Loading branch information
frg2089 committed Aug 26, 2023
1 parent 793d338 commit 79dd177
Show file tree
Hide file tree
Showing 23 changed files with 388 additions and 214 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"xml.format.maxLineWidth": 0
}
127 changes: 127 additions & 0 deletions sdk/Shimakaze.Sdk.RA2/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,130 @@

适用于RA2的MSBuild Sdk

## 属性
|属性名|作用|
|:-:|:-|
|ShimakazeSdkPath|指定Shimakaze.Sdk的位置|
|UseDefaultItems|是否使用默认的Items|
|Configuration|使用的配置,通常是`Debug``Release`|
|Platform|目标平台,通常是`Vanilla`|
|BaseIntermediateOutputPath|`obj`|
|IntermediateOutputPath|`$(BaseIntermediateOutputPath)\$(Configuration)`|
|BaseOutputPath|`bin`|
|OutputPath|`$(BaseOutputPath)\$(Configuration)`|
|ShimakazeSdkExclude|默认被排除的文件 `$(BaseOutputPath)\**\*;$(BaseIntermediateOutputPath)\**\*`|

##
- `IniFile` 表示一个将要被处理的INI文件
- `Ignore` 表示这个文件不需要被处理
- `TargetFile` 表示最终合并后的文件
- `Intermediate` 表示文件中间产物的位置
- `Pack` 表示文件会被打包到Mix文件中
- `TargetPack` 表示文件会被打包到这个Mix文件中
- `IntermediateIniFile` 表示Ini文件的中间产物
- `TargetFile` 表示最终合并后的文件
- `Pack` 表示文件会被打包到Mix文件中
- `TargetPack` 表示文件会被打包到这个Mix文件中
- `FinalIniFile` 最终合并后的Ini文件
- `Pack` 表示文件会被打包到Mix文件中
- `TargetPack` 表示文件会被打包到这个Mix文件中
- `CsfFile` 表示一个将要被处理的CSF文件
- `Ignore` 表示这个文件不需要被处理
- `TargetFile` 表示最终合并后的文件
- `Intermediate` 表示文件中间产物的位置
- `Pack` 表示文件会被打包到Mix文件中
- `TargetPack` 表示文件会被打包到这个Mix文件中
- `Type` 表示文件的类型
- `IntermediateCsfFile` 表示Csf文件的中间产物
- `TargetFile` 表示最终合并后的文件
- `Pack` 表示文件会被打包到Mix文件中
- `TargetPack` 表示文件会被打包到这个Mix文件中
- `FinalCsfFile` 最终合并后的Csf文件
- `Pack` 表示文件会被打包到Mix文件中
- `TargetPack` 表示文件会被打包到这个Mix文件中
- `MixAssetsFile` 一定会被打包的文件
- `TargetPack` 表示文件会被打包到这个Mix文件中

## 任务
|任务名|描述|
|:-:|:-|
|TaskCsfGenerator|CSF生成器
|TaskCsfMerger|CSF合并器
|TaskIniMerger|INI合并器
|TaskIniPreprocessor|INI预处理器
|TaskMixGenerator|MIX生成器

## 目标

- CoreCompile
- CoreMerger
- Build
- Pack
- Clean

- PreIniPreprocessor
- IniPreprocessor
- PostIniPreprocessor

- PreIniMerger
- IniMerger
- PostIniMerger

- PreCsfGenerator
- CsfGenerator
- PostCsfGenerator

- PreCsfMerger
- CsfMerger
- PostCsfMerger

- PreMixGenerator
- MixGenerator
- PostMixGenerator

## 任务顺序
```mermaid
graph TB;
subgraph Target:IniPreprocessor;
PreIniPreprocessor-->IniPreprocessor-->PostIniPreprocessor;
end;
subgraph Target:IniMerger;
PreIniMerger-->IniMerger-->PostIniMerger;
end;
subgraph Target:CsfGenerator;
PreCsfGenerator-->CsfGenerator-->PostCsfGenerator;
end;
subgraph Target:CsfMerger;
PreCsfMerger-->CsfMerger-->PostCsfMerger;
end;
subgraph Target:MixGenerator;
PreMixGenerator-->MixGenerator-->PostMixGenerator;
end;
subgraph Target:Pack;
Target:MixGenerator;
end;
subgraph Target:CoreCompile;
Target:IniPreprocessor-->Target:CsfGenerator;
end;
subgraph Target:CoreMerger;
Target:IniMerger-->Target:CsfMerger;
end;
subgraph Target:Build;
Target:CoreCompile-->Target:CoreMerger;
end;
subgraph Target:Clean;
RemoveDir:OutputPath/IntermediateOutputPath
end;
subgraph Target:ReBuild;
Target:Clean-->Target:Build;
end;
Target:Build-->Target:Pack;
Target:Clean;
```

## 默认 Defines
通常情况下,我们会默认定义以下Define:
- 完全大写的 Configuration 如 `DEBUG``RELEASE`
- 完全大写的 Platform 如 `VANILLA`
57 changes: 25 additions & 32 deletions sdk/Shimakaze.Sdk.RA2/Sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project
ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="17.6" DefaultTargets="Build">

<PropertyGroup>
<ShimakazeSdkPath Condition=" '$(ShimakazeSdkPath)' == '' ">$(MSBuildThisFileDirectory)..</ShimakazeSdkPath>
<ShimakazeSdkPath Condition=" '$(ShimakazeSdkPath)' == '' ">$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory).."))</ShimakazeSdkPath>

<UseDefaultItems Condition=" '$(UseDefaultItems)' == '' ">True</UseDefaultItems>

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">Vanilla</Platform>
<Defines>$(Configuration.ToUpper());$(Platform.ToUpper());$(Defines)</Defines>

<BaseIntermediateOutputPath Condition=" '$(BaseIntermediateOutputPath)' == '' ">obj</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition=" '$(IntermediateOutputPath)' == '' ">$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)\$(Configuration)</IntermediateOutputPath>
<IntermediateOutputPath Condition=" '$(IntermediateOutputPath)' == '' ">$(BaseIntermediateOutputPath)\$(Configuration)</IntermediateOutputPath>

<BaseOutputPath Condition=" '$(BaseOutputPath)' == '' ">bin</BaseOutputPath>
<OutputPath Condition=" '$(OutputPath)' == '' ">$(MSBuildProjectDirectory)\$(BaseOutputPath)\$(Configuration)</OutputPath>
<OutputPath Condition=" '$(OutputPath)' == '' ">$(BaseOutputPath)\$(Configuration)</OutputPath>

<CsfFileName Condition=" '$(CsfFileName)' == '' ">ra2md.csf</CsfFileName>
<RulesIniFileName Condition=" '$(RulesIniFileName)' == '' ">rulesmd.ini</RulesIniFileName>
<ArtsIniFileName Condition=" '$(ArtsIniFileName)' == '' ">artmd.ini</ArtsIniFileName>
<MixFileName Condition=" '$(MixFileName)' == '' ">expandmd01.mix</MixFileName>
<ShimakazeSdkExclude>$(BaseOutputPath)\**\*;$(BaseIntermediateOutputPath)\**\*</ShimakazeSdkExclude>
</PropertyGroup>

<ItemGroup>
<IniFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.rule" Type="Rule" />
<IniFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.art" Type="Art" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf" Type="Csf" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.json" Type="Json" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.v1.json" Type="JsonV1" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.v2.json" Type="JsonV2" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.xml" Type="Xml" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.v1.xml" Type="XmlV1" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.yaml" Type="Yaml" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.yml" Type="Yaml" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.v1.yaml" Type="YamlV1" />
<CsfFile Exclude="$(OutputPath)\**\*" Include="$(MSBuildProjectDirectory)\**\*.csf.v1.yml" Type="YamlV1" />
<CsfFile Update="$(IntermediateOutputPath)\**\*.csf" Type="Csf" SkipBuild="True" Merge="True" />
<IniFile Update="$(IntermediateOutputPath)\**\*.rule" Type="Rule" SkipPreprocess="True" />
<IniFile Update="$(IntermediateOutputPath)\**\*.art" Type="Art" SkipPreprocess="True" />
<!-- INI 文件 -->
<ItemGroup Condition=" '$(UseDefaultItems)' == 'True' ">
<IniFile Exclude="$(ShimakazeSdkExclude)" Pack="True" TargetPack="expandmd01.mix" Include="**\*.rule" TargetFile="rulesmd.ini" />
<IniFile Exclude="$(ShimakazeSdkExclude)" Pack="True" TargetPack="expandmd01.mix" Include="**\*.art" TargetFile="artmd.ini" />
<IniFile Exclude="$(ShimakazeSdkExclude)" Pack="True" TargetPack="expandmd01.mix" Include="**\*.ai" TargetFile="aimd.ini" />
</ItemGroup>

<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.CsfBuilder" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.CsfMerger" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.IniPreprocessor" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.IniMerger" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.MixPacker" />
<!-- CSF 文件 -->
<ItemGroup Condition=" '$(UseDefaultItems)' == 'True' ">
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf" Type="Csf" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.json" Type="Json" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.v1.json" Type="JsonV1" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.v2.json" Type="JsonV2" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.xml" Type="Xml" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.v1.xml" Type="XmlV1" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.yaml" Type="Yaml" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.yml" Type="Yaml" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.v1.yaml" Type="YamlV1" />
<CsfFile Exclude="$(ShimakazeSdkExclude)" TargetFile="ra2md.csf" Pack="True" TargetPack="expandmd02.mix" Include="**\*.csf.v1.yml" Type="YamlV1" />
</ItemGroup>

</Project>
33 changes: 27 additions & 6 deletions sdk/Shimakaze.Sdk.RA2/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(ShimakazeSdkPath)\targets\Ini.targets" />
<Import Project="$(ShimakazeSdkPath)\Sdk\tasks.props" />

<Import Project="$(ShimakazeSdkPath)\targets\Csf.targets" />
<Import Project="$(ShimakazeSdkPath)\targets\Ini.targets" />
<Import Project="$(ShimakazeSdkPath)\targets\Mix.targets" />

<Target Name="CoreCompile">
<CallTarget Targets="_PreprocessingINI;_MergeIni" />
<CallTarget Targets="_BuildCsf;_MergeCsf" />
<CallTarget Targets="IniPreprocessor" />
<CallTarget Targets="CsfGenerator" />
</Target>

<Target Name="CoreMerger">
<CallTarget Targets="IniMerger" />
<CallTarget Targets="CsfMerger" />
</Target>

<Target Name="Build" BeforeTargets="Pack">
<Target Name="Build">
<CallTarget Targets="CoreCompile" />
<CallTarget Targets="CoreMerger" />
</Target>

<Target Name="Pack">
<CallTarget Targets="PackMix" />
<Target Name="Pack" AfterTargets="Build">
<CallTarget Targets="MixGenerator" />
</Target>

<Target Name="Clean">
<RemoveDir Directories="$(OutputPath);$(IntermediateOutputPath)" />
</Target>

<Target Name="ReBuild">
<CallTarget Targets="Clean" />
<CallTarget Targets="Build" />
</Target>

<Target Name="Publish">
<CallTarget Targets="Pack" />
</Target>

<Target Name="VSTest">
<CallTarget Targets="Pack" />
</Target>

</Project>
10 changes: 10 additions & 0 deletions sdk/Shimakaze.Sdk.RA2/Sdk/tasks.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.TaskCsfGenerator" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.TaskCsfMerger" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.TaskIniMerger" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.TaskIniPreprocessor" />
<UsingTask AssemblyFile="$(ShimakazeSdkPath)\lib\Shimakaze.Sdk.Build.dll" TaskName="Shimakaze.Sdk.Build.TaskMixGenerator" />

</Project>
39 changes: 2 additions & 37 deletions sdk/Shimakaze.Sdk.RA2/targets/Csf.targets
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="_Pre_BuildCsf" BeforeTargets="_BuildCsf">
<ItemGroup>
<_CsfFile
Include="@(CsfFile)"
Destination="$(IntermediateOutputPath)\%(RecursiveDir)%(Filename).g%(Extension).csf"
Merge="True" />
<_CsfFile Remove="@(CsfFile -> WithMetadataValue('SkipBuild', 'True'))" />
<CsfFile Remove="@(_CsfFile)" />
</ItemGroup>
</Target>
<Import Project="$(MSBuildThisFileDirectory)Csf\CsfGenerator.targets" />
<Import Project="$(MSBuildThisFileDirectory)Csf\CsfMerger.targets" />

<Target
Name="_BuildCsf"
Inputs="@(_CsfFile)"
Outputs="%(Destination)"
BeforeTargets="_MergeCsf">
<CsfBuilder SourceFiles="@(_CsfFile)">
<Output TaskParameter="OutputFiles" ItemName="CsfFile" />
</CsfBuilder>
<ItemGroup>
<_CsfFile Remove="@(_CsfFile)" />
</ItemGroup>
</Target>

<Target
Name="_MergeCsf"
Inputs="@(CsfFile -> WithMetadataValue('Merge', 'True'))"
Outputs="$(OutputPath)\$(CsfFileName)">
<CsfMerger
SourceFiles="@(CsfFile -> WithMetadataValue('Merge', 'True'))"
DestinationFile="$(OutputPath)\$(CsfFileName)">
<Output TaskParameter="OutputFile" ItemName="_CsfFile" />
</CsfMerger>
<ItemGroup>
<CsfFile Include="@(_CsfFile)" />
<_CsfFile Remove="@(_CsfFile)" />
</ItemGroup>
</Target>
</Project>
31 changes: 31 additions & 0 deletions sdk/Shimakaze.Sdk.RA2/targets/Csf/CsfGenerator.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="PreCsfGenerator" BeforeTargets="CsfGenerator">
<ItemGroup>
<CsfFile
Update="@(CsfFile)"
Intermediate="$(IntermediateOutputPath)\%(RecursiveDir)%(Filename).g%(Extension).csf"
Pack="%(Pack)"
TargetPack="%(TargetPack)"
/>
<CsfFile Remove="@(CsfFile -> WithMetadataValue('Ignore', 'True'))" />
</ItemGroup>
</Target>

<Target Name="CsfGenerator" Inputs="@(CsfFile)" Outputs="%(Intermediate)">
<TaskCsfGenerator SourceFiles="@(CsfFile)">
<Output TaskParameter="OutputFiles" ItemName="IntermediateCsfFile" />
</TaskCsfGenerator>
</Target>

<Target Name="PostCsfGenerator" AfterTargets="CsfGenerator">
<ItemGroup Condition=" '@(IntermediateCsfFile)' == '' ">
<IntermediateCsfFile Include="%(CsfFile.Intermediate)" TargetFile="%(CsfFile.TargetFile)" Pack="%(CsfFile.Pack)" TargetPack="%(CsfFile.TargetPack)" />
</ItemGroup>
<ItemGroup>
<CsfFile Remove="@(CsfFile)" />
</ItemGroup>
</Target>

</Project>
26 changes: 26 additions & 0 deletions sdk/Shimakaze.Sdk.RA2/targets/Csf/CsfMerger.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="PreCsfMerger" BeforeTargets="CsfMerger">
<ItemGroup>
<IntermediateCsfFile Update="@(IntermediateCsfFile)" Pack="%(Pack)" TargetPack="%(TargetPack)" />
<IntermediateCsfFile Remove="@(IntermediateCsfFile -> WithMetadataValue('Ignore', 'True'))" />
</ItemGroup>
</Target>

<Target Name="CsfMerger" Inputs="@(IntermediateCsfFile)" Outputs="$(OutputPath)\%(TargetFile)">
<TaskCsfMerger SourceFiles="@(IntermediateCsfFile)" DestinationFile="$(OutputPath)\%(TargetFile)">
<Output TaskParameter="OutputFile" ItemName="FinalCsfFile" />
</TaskCsfMerger>
</Target>

<Target Name="PostCsfMerger" AfterTargets="CsfMerger">
<ItemGroup Condition=" '@(FinalCsfFile)' == '' ">
<FinalCsfFile Include="$(OutputPath)\%(IntermediateCsfFile.TargetFile)" Pack="%(IntermediateCsfFile.Pack)" TargetPack="%(IntermediateCsfFile.TargetPack)" />
</ItemGroup>
<ItemGroup>
<IntermediateCsfFile Remove="@(IntermediateCsfFile)" />
</ItemGroup>
</Target>

</Project>
Loading

0 comments on commit 79dd177

Please sign in to comment.