Repository navigation
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
144 lines (130 loc) · 9.26 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
144 lines (130 loc) · 9.26 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<Project>
<!--
A partial generated SDK surface blocks every publishable package, including Extensions. The
wall reads the marker's pending count, not the marker's existence: the marker outlives a
cleared pending set as the committed record of what the released surface omits by decision
(declined operations and transport-owned doors), and only a pending operation - one nobody has
decided anything about - must never reach a package. The marker must therefore be there to be
read: a missing marker refuses, and so does one whose pending header cannot be read, because a
deleted or reshaped marker is an accident, not a verdict. (The generator deletes the marker only
when nothing at all stands outside the generated surface - unreachable while ADR-0021's two
transport-owned doors exist.) This is the pack-time layer of a two-layer defense: the release
lane additionally runs the generator's verify mode (opencode-tool, generate command, verify
option) before packing, so a stale or hand-edited marker is caught by regeneration as well as
by this wall. Note that an XML comment cannot contain a double hyphen, so the exact command
lines live in the Error texts below rather than here.
-->
<Target Name="RefuseIncompleteGenerationPack"
BeforeTargets="GenerateNuspec"
Condition="'$(IsPackable)' == 'true'">
<PropertyGroup>
<_GenerationMarkerPath>$(MSBuildThisFileDirectory)src/OpenCode.Sdk/.generation-incomplete</_GenerationMarkerPath>
</PropertyGroup>
<ReadLinesFromFile File="$(_GenerationMarkerPath)" Condition="Exists('$(_GenerationMarkerPath)')">
<Output TaskParameter="Lines" ItemName="_GenerationMarkerLine" />
</ReadLinesFromFile>
<ItemGroup>
<_GenerationPendingHeaderLine Include="@(_GenerationMarkerLine)"
Condition="$([System.String]::Copy('%(Identity)').StartsWith('Pending operations:'))" />
</ItemGroup>
<PropertyGroup>
<_GenerationPendingHeader>@(_GenerationPendingHeaderLine)</_GenerationPendingHeader>
<_GenerationPendingCount>$(_GenerationPendingHeader.Replace('Pending operations:', '').Trim())</_GenerationPendingCount>
</PropertyGroup>
<Error Condition="!Exists('$(_GenerationMarkerPath)')"
Text="Packages cannot be created: $(_GenerationMarkerPath) is missing. The marker is required while any operation is declined or transport-owned, and it is the record of what a released package omits - a package built without it makes no statement at all. Run 'dotnet run --file tools/opencode-tool.cs -- generate' to recreate it, and restore it if it was deleted." />
<Error Condition="Exists('$(_GenerationMarkerPath)') And '$(_GenerationPendingCount)' == ''"
Text="Packages cannot be created: $(_GenerationMarkerPath) exists but declares no 'Pending operations: <count>' header, so the pending set cannot be read. Run 'dotnet run --file tools/opencode-tool.cs -- generate' and review the marker." />
<Error Condition="'$(_GenerationPendingCount)' != '' And '$(_GenerationPendingCount)' != '0'"
Text="Packages cannot be created while $(_GenerationPendingCount) operation(s) are pending. $(_GenerationMarkerPath) lists them under 'Pending:'; select each one into tools/generation-profile.txt, or decline it in tools/curation.json with a reason, before packing." />
</Target>
<!--
A package's README links the repository at the commit the package was built from, not at
master, so the files it points to match the package for as long as the package exists. The
release tag is created on that same commit after the publish, so a commit link and a tag link
show the same content, and a nightly package, which gets no tag, links correctly too. The
repository's own README keeps its master links; only the packed copy is rewritten. A pack with
no known commit refuses rather than shipping master links. The copy is written by a small task
of its own, byte for byte apart from the links: WriteLinesToFile would pass the text through an
item list, and on Linux and macOS MSBuild turns every backslash in an item into a slash, which
would break the shell examples' line continuations (PackedReadmeTests compares the copy byte
for byte on all three operating systems).
-->
<UsingTask TaskName="WritePackedReadme"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Source ParameterType="System.String" Required="true" />
<Destination ParameterType="System.String" Required="true" />
<RepositoryUrl ParameterType="System.String" Required="true" />
<Commit ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs"><![CDATA[
var text = System.IO.File.ReadAllText(Source)
.Replace(RepositoryUrl + "/blob/master/", RepositoryUrl + "/blob/" + Commit + "/")
.Replace(RepositoryUrl + "/tree/master/", RepositoryUrl + "/tree/" + Commit + "/");
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Destination));
System.IO.File.WriteAllText(Destination, text, new System.Text.UTF8Encoding(false));
]]></Code>
</Task>
</UsingTask>
<Target Name="PackReadmeLinkedToTheCommit"
BeforeTargets="_GetPackageFiles"
DependsOnTargets="InitializeSourceControlInformation"
Condition="'$(IsPackable)' == 'true'">
<PropertyGroup>
<_PackedReadmeCommit>$(SourceRevisionId)</_PackedReadmeCommit>
<_PackedReadmeCommit Condition="'$(_PackedReadmeCommit)' == ''">$(RepositoryCommit)</_PackedReadmeCommit>
<_PackedReadmeSource>$(MSBuildThisFileDirectory)README.md</_PackedReadmeSource>
<_PackedReadmeFile>$(BaseIntermediateOutputPath)README.md</_PackedReadmeFile>
</PropertyGroup>
<Error Condition="'$(_PackedReadmeCommit)' == ''"
Text="The package README cannot be linked to its commit: neither SourceRevisionId nor RepositoryCommit is set. Pack from a git checkout with source control information enabled." />
<WritePackedReadme Source="$(_PackedReadmeSource)"
Destination="$(_PackedReadmeFile)"
RepositoryUrl="$(RepositoryUrl)"
Commit="$(_PackedReadmeCommit)" />
<ItemGroup>
<FileWrites Include="$(_PackedReadmeFile)" />
<None Remove="$(_PackedReadmeSource)" />
<None Include="$(_PackedReadmeFile)" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>
</Target>
<!--
The packages carry a netstandard2.0 asset as a compatibility bridge, not as a supported runtime
(ADR-0002). A consumer whose target framework resolves to it on a runtime the packages do not
target - .NET Core below the default target, .NET Framework below 4.7.2 - gets a build warning,
the way the runtime's own packages warn (dotnet/runtime eng/packaging.targets,
NETStandardCompatError): a generated buildTransitive target in the netstandard2.0 folder, and
empty placeholders in the folders of every supported target, which NuGet's nearest-match
selects first and which therefore carry nothing. SuppressTfmSupportBuildWarnings silences it.
Each package gets its own target name, so a consumer of both packages sees both warnings.
-->
<Target Name="AddUnsupportedTargetFrameworkWarning"
BeforeTargets="_GetPackageFiles"
Condition="'$(IsPackable)' == 'true'">
<PropertyGroup>
<_UnsupportedTargetFrameworkFile>$(BaseIntermediateOutputPath)buildTransitive/$(PackageId).targets</_UnsupportedTargetFrameworkFile>
<_UnsupportedTargetFrameworkTarget>WarnUnsupportedTargetFramework_$(PackageId.Replace('.', '_'))</_UnsupportedTargetFrameworkTarget>
<_UnsupportedTargetFrameworkContent>
<![CDATA[<Project InitialTargets="$(_UnsupportedTargetFrameworkTarget)">
<Target Name="$(_UnsupportedTargetFrameworkTarget)"
Condition="'%24(SuppressTfmSupportBuildWarnings)' != 'true' And ('%24(TargetFrameworkIdentifier)' == '.NETCoreApp' Or '%24(TargetFrameworkIdentifier)' == '.NETFramework')">
<Warning Text="$(PackageId) $(PackageVersion) does not support %24(TargetFramework) and has not been tested with it. Consider upgrading your TargetFramework to $(DefaultTargetFramework) or later, or to net472 or later on .NET Framework. You may also set <%3BSuppressTfmSupportBuildWarnings>%3Btrue<%3B/SuppressTfmSupportBuildWarnings>%3B in the project file to ignore this warning and attempt to run in this unsupported configuration at your own risk." />
</Target>
</Project>]]>
</_UnsupportedTargetFrameworkContent>
</PropertyGroup>
<WriteLinesToFile File="$(_UnsupportedTargetFrameworkFile)"
Lines="$(_UnsupportedTargetFrameworkContent)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
<ItemGroup>
<FileWrites Include="$(_UnsupportedTargetFrameworkFile)" />
<None Include="$(_UnsupportedTargetFrameworkFile)" Pack="true" PackagePath="buildTransitive/netstandard2.0/" />
<None Include="$(MSBuildThisFileDirectory)assets/_._" Pack="true"
PackagePath="buildTransitive/net472/;buildTransitive/$(DefaultTargetFramework)/;buildTransitive/$(LatestTargetFramework)/" />
</ItemGroup>
</Target>
</Project>