Skip to content

Commit 7a68049

Browse files
A generated file is checked against its generator, and two had stopped matching (#1124)
Nothing rebuilt the checked-in generated files and compared, so a template could stop matching its output and the build stayed green -- the file only being discovered to be unregenerable the next time somebody actually tried. That had already happened once, to `EquationSystemFunctionPattern.txt`, repaired by #1029. It had happened twice. `TupleToIntervalTest.txt` still named `MathS.Matrices.Interval`, which does not exist, so regenerating `TupleToIntervalTest.cs` produced eighteen CS0117 errors -- measured, not inferred. The generator had also drifted on the namespace, writing `UnitTest.Extensions` where the test project uses `AngouriMath.Tests.Extensions`, and had lost the `Area` trait every test class here carries so that `dotnet test --filter` can select by area. All three are repaired. **And two of the three T4 templates did not emit the copyright header**, which is worse than cosmetic: IDE0073 is an error in this repository, so regenerating either of them produced a file that failed the build outright. The issue proposed excluding the header block when diffing; emitting it is better, because then the generated file is the committed file and there is no exclusion that could quietly grow to hide a real difference. `MathAllMethods.tt` already emitted it and already reproduced exactly, so this makes the other two match the one that worked -- BOM included, which that file does not have either and which no `.editorconfig` rule asks for. `Sources/Utils/regenerate_all.sh` regenerates everything in place. The three T4 templates are read out of `AngouriMath.csproj` rather than listed in the script, because a list written twice is a list that drifts, and this one would drift in the direction of covering less. It resolves paths from its own location rather than from the working directory, and it looks `t4` up rather than assuming it is on PATH -- `dotnet tool install -g dotnet-t4` installs a binary called `t4`, so `dotnet t4` fails with a message that reads as a typo. `GeneratedFilesUpToDate.yml` runs it and fails on any difference, printing the diff rather than "files differ". Demonstrated by breaking a template without regenerating its output: the job's diff step exits 1 and names `TupleToIntervalTest.cs`. The ANTLR parser keeps its own job, `GrammarUpToDate.yml`, because it needs a Java runtime where this needs a dotnet tool -- so neither goes red for the other's reason. Part of #1034.
1 parent 82c40ca commit 7a68049

9 files changed

Lines changed: 151 additions & 21 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: 'Generated Files Up To Date'
2+
3+
# Several files in this repository are generated and checked in, and nothing rebuilt them and
4+
# compared -- so a template could stop matching its output and the build stayed green. The file was
5+
# then only discovered to be unregenerable the next time somebody actually tried.
6+
#
7+
# That had happened twice by the time this was written. `EquationSystemFunctionPattern.txt` still
8+
# said `Tensor?` long after the type was renamed to `Matrix?` (repaired by #1029), and
9+
# `TupleToIntervalTest.txt` still said `MathS.Matrices.Interval`, which does not exist -- so
10+
# regenerating that test file produced eighteen CS0117 errors. Both were found by hand, years apart,
11+
# which is the argument for this job.
12+
#
13+
# The ANTLR parser has its own job, GrammarUpToDate.yml, because it needs a Java runtime where this
14+
# needs a dotnet tool. Keeping them apart means neither goes red for the other's reason.
15+
# https://github.com/asc-community/AngouriMath/issues/1034
16+
17+
on:
18+
push:
19+
branches:
20+
- master
21+
paths:
22+
- "Sources/AngouriMath/**/*.tt"
23+
- "Sources/AngouriMath/Convenience/CompilationExtensions.cs"
24+
- "Sources/AngouriMath/Functions/Compilation/**"
25+
- "Sources/Utils/**"
26+
- "Sources/Tests/UnitTests/Convenience/TupleToIntervalTest.cs"
27+
- "Sources/AngouriMath/AngouriMath.csproj"
28+
- ".github/workflows/GeneratedFilesUpToDate.yml"
29+
pull_request:
30+
branches:
31+
- '*'
32+
paths:
33+
- "Sources/AngouriMath/**/*.tt"
34+
- "Sources/AngouriMath/Convenience/CompilationExtensions.cs"
35+
- "Sources/AngouriMath/Functions/Compilation/**"
36+
- "Sources/Utils/**"
37+
- "Sources/Tests/UnitTests/Convenience/TupleToIntervalTest.cs"
38+
- "Sources/AngouriMath/AngouriMath.csproj"
39+
- ".github/workflows/GeneratedFilesUpToDate.yml"
40+
41+
jobs:
42+
Regenerate:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v6
47+
48+
- name: Setup .NET 10
49+
uses: actions/setup-dotnet@v5
50+
with:
51+
dotnet-version: '10.x'
52+
dotnet-quality: 'preview'
53+
54+
# The one tool this needs beyond the SDK the other jobs already install.
55+
- name: 'Install the T4 processor'
56+
run: dotnet tool install -g dotnet-t4
57+
58+
- name: 'Regenerate every generated file'
59+
run: bash Sources/Utils/regenerate_all.sh
60+
61+
# No exclusions. The templates emit the copyright header themselves, so the generated file is
62+
# the committed file byte for byte and there is nothing here that could quietly grow to hide a
63+
# real difference. Two of the three T4 templates did not emit it until this issue, which meant
64+
# regenerating them produced files that failed the build outright -- IDE0073 is an error here.
65+
- name: 'Fail if a committed generated file is not what its generator produces'
66+
run: |
67+
if ! git diff --exit-code --stat; then
68+
echo "::error::A checked-in generated file does not match its generator."
69+
echo "::error::Run Sources/Utils/regenerate_all.sh and commit the result."
70+
echo "--- the difference ---"
71+
git --no-pager diff
72+
exit 1
73+
fi

‎Sources/AngouriMath/Convenience/CompilationExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) 2019-2022 Angouri.
33
// AngouriMath is licensed under MIT.
44
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.

‎Sources/AngouriMath/Convenience/CompilationExtensions.tt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-

1+
//
2+
// Copyright (c) 2019-2022 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
28
using static AngouriMath.Entity;
39
using AngouriMath.Core.Compilation.IntoLinq;
410
using System.Collections.Generic;

‎Sources/AngouriMath/Functions/Compilation/Compile.Linq.Definition.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) 2019-2022 Angouri.
33
// AngouriMath is licensed under MIT.
44
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.

‎Sources/AngouriMath/Functions/Compilation/Compile.Linq.Definition.tt‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
using System;
1+
//
2+
// Copyright (c) 2019-2022 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
29
using System.Collections;
310
using System.Collections.Generic;
411
using System.Linq;

‎Sources/Tests/UnitTests/Convenience/TupleToIntervalTest.cs‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55
// Website: https://am.angouri.org.
66
//
77

8-
/* Copyright (c) 2019-2020 Angourisoft
9-
*
10-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
11-
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
12-
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
13-
* is furnished to do so, subject to the following conditions:
14-
*
15-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17-
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20-
*/
21-
228
// This file is auto-generated. Use generate_additional_extensions_tests.bat to re-generate it, do not edit the file itself.
239

2410
using Xunit;

‎Sources/Utils/Utils/AdditionalExtensionsTestGenerator.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public static void Do()
3737

3838
var com = new SourceGenerator(commonTemplate, "%bat%", "%usings%", "%namespace%", "%classheader%", "%content%");
3939

40-
var fullText = com.Generate("generate_additional_extensions_tests.bat", "using Xunit;\nusing AngouriMath;\nusing AngouriMath.Extensions;", "UnitTest.Extensions", "public class IntervalExtensionTest", GenerateTupleToInterval());
40+
// The namespace and the trait are the committed file's, not this generator's older
41+
// guesses at them: `UnitTest.Extensions` is a namespace the test project does not use,
42+
// and every test class here carries an Area trait so that `dotnet test --filter` can
43+
// select by area. Both had drifted, as had `MathS.Matrices.Interval` in the content
44+
// template -- which does not exist, so the file could not be regenerated at all.
45+
// https://github.com/asc-community/AngouriMath/issues/1034
46+
var fullText = com.Generate("generate_additional_extensions_tests.bat", "using Xunit;\nusing AngouriMath;\nusing AngouriMath.Extensions;", "AngouriMath.Tests.Extensions", "[Trait(\"Area\", \"Convenience\")]\n public class IntervalExtensionTest", GenerateTupleToInterval());
4147

4248
File.WriteAllText("../Tests/UnitTests/Convenience/TupleToIntervalTest.cs", fullText);
4349
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[Fact] public void Test%testid%()
22
=> Assert.Equal(
3-
MathS.Matrices.Interval(%arg1%, %arg2%),
3+
MathS.Interval(%arg1%, %arg2%),
44
(%arg1%, %arg2%).ToInterval()
55
);
66

77
[Fact] public void Test%testid%_custom()
88
=> Assert.Equal(
9-
MathS.Matrices.Interval(%arg1%, true, %arg2%, false),
9+
MathS.Interval(%arg1%, true, %arg2%, false),
1010
(%arg1%, true, %arg2%, false).ToInterval()
1111
);
1212

‎Sources/Utils/regenerate_all.sh‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Regenerates every checked-in generated file that is not the ANTLR parser, in place.
4+
#
5+
# The parser has its own job, GrammarUpToDate.yml, because regenerating it needs a Java runtime
6+
# and this needs a dotnet tool -- keeping them apart means neither is red for the other's reason.
7+
#
8+
# Run from anywhere; paths are resolved from this script's own location, not from the working
9+
# directory, because a report that writes where you are not reading goes stale invisibly.
10+
#
11+
# https://github.com/asc-community/AngouriMath/issues/1034
12+
13+
set -euo pipefail
14+
15+
sources="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
16+
kernel="$sources/AngouriMath"
17+
18+
# The three T4 templates, read out of the project file rather than listed here -- a list written
19+
# twice is a list that drifts, and this one would drift silently in the direction of covering
20+
# less. `None Update="a\b.tt"` is MSBuild's Windows separator, so it is translated on the way out.
21+
templates=$(
22+
grep -o 'None Update="[^"]*\.tt"' "$kernel/AngouriMath.csproj" \
23+
| sed 's/None Update="//; s/"$//; s|\\|/|g'
24+
)
25+
26+
if [ -z "$templates" ]; then
27+
echo "no .tt templates found in AngouriMath.csproj -- has the declaration shape changed?" >&2
28+
exit 1
29+
fi
30+
31+
# `dotnet tool install -g dotnet-t4` installs a binary called `t4`, not `dotnet-t4`, so it is not
32+
# reachable as `dotnet t4` and is only on PATH if the tools directory is. Looked up rather than
33+
# assumed, because the failure otherwise reads as "you misspelled a built-in dotnet command".
34+
t4=$(command -v t4 || true)
35+
if [ -z "$t4" ] && [ -x "$HOME/.dotnet/tools/t4" ]; then
36+
t4="$HOME/.dotnet/tools/t4"
37+
fi
38+
if [ -z "$t4" ]; then
39+
echo "t4 not found. Install it with: dotnet tool install -g dotnet-t4" >&2
40+
exit 1
41+
fi
42+
43+
for template in $templates; do
44+
echo "t4: $template"
45+
"$t4" "$kernel/$template" -o "$kernel/${template%.tt}.cs"
46+
done
47+
48+
# And the two hand-written generators, which write their own destinations.
49+
echo "utils: ExtensionGenerator"
50+
(cd "$sources/Utils" && dotnet run --project Utils -c Release ExtensionGenerator)
51+
echo "utils: AdditionalExtensionsTestGenerator"
52+
(cd "$sources/Utils" && dotnet run --project Utils -c Release AdditionalExtensionsTestGenerator)

0 commit comments

Comments
 (0)