-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.Build.props
More file actions
114 lines (101 loc) · 5.48 KB
/
Copy pathDirectory.Build.props
File metadata and controls
114 lines (101 loc) · 5.48 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<Project>
<PropertyGroup>
<!--
⚠ netstandard2.0 is a floor, not a preference. The mod runs on Unity's Mono and on IL2CPP,
which is the narrower of the two runtimes this library serves; the installer's .NET consumes
it without trouble. Written the other way round it could not be shared at all, which is how
a shared file quietly becomes two files again.
-->
<TargetFramework>netstandard2.0</TargetFramework>
<!--
Modern syntax is welcome; modern RUNTIME is not. The compiler happily targets an old
framework with a recent language, so pattern matching and the like are available — but
anything needing a newer base library (GetValueOrDefault, ranges, index-from-end) will not
compile here, and that is the guard rail working rather than getting in the way.
-->
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<!--
⚠ Symbols go INSIDE the assembly. One of the consumers publishes as a single file and
asserts, at packaging time, that nothing else was produced beside the executable — a stray
UnityGameTranslator.Common.pdb fails that check. It has to be set here rather than there:
a project's own props decide how it emits, and this one is referenced across repositories.
-->
<DebugType>embedded</DebugType>
<!-- Nothing here is allowed to need a package. See CONTRIBUTING.md and THIRD_PARTY_LICENSES.md. -->
<NoWarn>$(NoWarn)</NoWarn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<!--
⚠ THE LANGUAGE TABLES ARE GENERATED from catalogs/languages.json, by
generate-common-languages.py at the project root, and committed. This target does not generate
them — it REFUSES TO BUILD when they no longer match the catalogue they came from.
Why not generate here: MSBuild cannot parse JSON without an assembly reference that resolves
on one machine and not the next (System.Text.Json is not resolvable by name in an inline task,
and is not in the SDK folder either). Hashing needs nothing.
The effect is the one that matters: a release cannot ship a language list the catalogue no
longer says. It fails loudly at build instead of quietly at upload.
-->
<PropertyGroup>
<LanguageCatalogue>$(MSBuildThisFileDirectory)catalogs/languages.json</LanguageCatalogue>
<LanguageTables>$(MSBuildThisFileDirectory)src/UnityGameTranslator.Common/Languages.Tables.g.cs</LanguageTables>
<!--
The flags follow the same regime, and the check below is the same task run twice: a table
generated from a catalogue must never outlive it. ⚠ Both are needed — the language tables
also carry which flag each language points at, so a flag renamed in one file and not the
other has to fail here rather than render the wrong picture in a game.
-->
<FlagCatalogue>$(MSBuildThisFileDirectory)catalogs/flags.json</FlagCatalogue>
<FlagTables>$(MSBuildThisFileDirectory)src/UnityGameTranslator.Common/Flags.Tables.g.cs</FlagTables>
</PropertyGroup>
<UsingTask TaskName="CheckLanguageTables" TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Catalogue ParameterType="System.String" Required="true" />
<Tables ParameterType="System.String" Required="true" />
<Stale ParameterType="System.Boolean" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Security.Cryptography" />
<Using Namespace="System.Text" />
<Code Type="Fragment" Language="cs">
<![CDATA[
using (var sha = SHA256.Create())
{
var hash = sha.ComputeHash(File.ReadAllBytes(Catalogue));
var builder = new StringBuilder();
foreach (var b in hash) builder.Append(b.ToString("x2"));
var recorded = "";
foreach (var line in File.ReadAllLines(Tables))
{
var at = line.IndexOf("catalogue-sha256:");
if (at < 0) continue;
recorded = line.Substring(at + "catalogue-sha256:".Length).Trim();
break;
}
Stale = recorded != builder.ToString();
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name="VerifyLanguageTables" BeforeTargets="CoreCompile"
Condition="'$(MSBuildProjectName)' == 'UnityGameTranslator.Common' AND Exists('$(LanguageCatalogue)')">
<CheckLanguageTables Catalogue="$(LanguageCatalogue)" Tables="$(LanguageTables)">
<Output TaskParameter="Stale" PropertyName="LanguageTablesStale" />
</CheckLanguageTables>
<Error Condition="'$(LanguageTablesStale)' == 'true'"
Text="The language tables no longer match catalogs/languages.json. Run: python generate-common-languages.py" />
</Target>
<Target Name="VerifyFlagTables" BeforeTargets="CoreCompile"
Condition="'$(MSBuildProjectName)' == 'UnityGameTranslator.Common' AND Exists('$(FlagCatalogue)')">
<CheckLanguageTables Catalogue="$(FlagCatalogue)" Tables="$(FlagTables)">
<Output TaskParameter="Stale" PropertyName="FlagTablesStale" />
</CheckLanguageTables>
<Error Condition="'$(FlagTablesStale)' == 'true'"
Text="The flag tables no longer match catalogs/flags.json. Run: python generate-common-languages.py" />
</Target>
</Project>