Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*
!bin/run.sh
!bin/build-shapes.sh
!shapes

!src/Exercism.TestRunner.VBNet
src/Exercism.TestRunner.VBNet/bin
Expand Down
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ RUN dotnet restore -a $TARGETARCH
COPY src/Exercism.TestRunner.VBNet/ ./
RUN dotnet publish -a $TARGETARCH --output /opt/test-runner --no-restore

# Slim the pre-installed NuGet cache
RUN find /root/.nuget/packages -type f \( -name '*.nupkg' -o -name '*.snupkg' \) -delete
# Slim the pre-installed NuGet cache. The ReadyToRun compiler (crossgen2) and the runtime packs,
# restored for the runner, move to /r2r-packages, so that only the shape build below sees them.
RUN find /root/.nuget/packages -type f \( -name '*.nupkg' -o -name '*.snupkg' \) -delete && \
mkdir /r2r-packages && \
mv /tmp/runner-packages/microsoft.netcore.app.crossgen2.* \
/tmp/runner-packages/microsoft.netcore.app.runtime.* \
/tmp/runner-packages/microsoft.aspnetcore.app.runtime.* /r2r-packages/

# Build runtime image
FROM mcr.microsoft.com/dotnet/sdk:11.0.100-alpine3.24 AS runtime
Expand All @@ -48,4 +53,9 @@ COPY --from=build /root/.nuget/packages/ /root/.nuget/packages/

COPY bin/run.sh bin/

# Build a template project for each known project shape, for the runner's fast path
COPY shapes/ shapes/
COPY bin/build-shapes.sh bin/
RUN --mount=type=bind,from=build,source=/r2r-packages,target=/r2r-packages sh bin/build-shapes.sh

ENTRYPOINT ["sh", "/opt/test-runner/bin/run.sh"]
56 changes: 56 additions & 0 deletions bin/build-shapes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env sh

# Synopsis:
# Build a template project for each project shape in /opt/test-runner/shapes. The Dockerfile runs
# this once, at image build. The runner's fast path (src/Exercism.TestRunner.VBNet/FastPath.vb)
# then reuses what each build leaves behind:
# - vbc.rsp: the exact compiler command line produced by MSBuild for that project file.
# - obj/: the source files generated by the SDK and the packages (assembly attributes, the test
# entry point and so on).
# - publish/: every dependency, precompiled with ReadyToRun, so that the test executable spends
# less time in the JIT compiler on each run.
# - shape.key: the key that identifies the shape (written by the runner's --prepare-shape option).
# If a shape fails to build, this script removes it, and solutions with that shape use MSBuild.

# The Dockerfile mounts the ReadyToRun compiler and the runtime packs at /r2r-packages for this script only.
for package in /r2r-packages/*; do
ln -s "${package}" "/root/.nuget/packages/$(basename "${package}")"
done

for dir in /opt/test-runner/shapes/*/; do
cd "${dir}" || exit 1
# The runner fills in each solution's root namespace, so the template uses the default one (its own name).
sed -i '/<RootNamespace>/d' ExercismShape.vbproj
printf 'Public Module ExercismShapeStub\nEnd Module\n' > ExercismShape.vb
printf 'Imports Xunit\n\nPublic Class ExercismShapeTests\n <Fact>\n Public Sub Passes()\n End Sub\nEnd Class\n' > ExercismShapeTests.vb
# This target writes the compiler arguments to vbc.rsp after MSBuild has compiled the project.
cat > Directory.Build.targets <<'TARGETS'
<Project>
<Target Name="ExercismCaptureCompilerArguments" AfterTargets="CoreCompile" Condition="'$(ExercismCaptureCompilerArguments)' == 'true'">
<WriteLinesToFile File="$(MSBuildProjectDirectory)/vbc.rsp" Lines="@(VbcCommandLineArgs)" Overwrite="true" />
</Target>
</Project>
TARGETS

if dotnet build -c release --source /root/.nuget/packages/ -p:ProvideCommandLineArgs=true -p:ExercismCaptureCompilerArguments=true -nologo -v q &&
dotnet publish -c release --source /root/.nuget/packages/ --use-current-runtime --self-contained false -p:PublishReadyToRun=true -o publish -nologo -v q &&
# MSBuild turns every backslash in an item into a slash on Linux, which breaks the escaped
# quotes in the /define: argument (CONFIG=\"release\"). This puts the backslashes back.
sed -i '/^\/define:/ s|/"|\\"|g' vbc.rsp &&
/opt/test-runner/Exercism.TestRunner.VBNet --prepare-shape "${dir%/}"; then
echo "Built shape ${dir}"
else
echo "Skipping shape ${dir}"
rm -rf "${dir}"
fi
done

# Many shapes share the same dependency files. Hard links keep one copy of each in the image.
find /opt/test-runner/shapes -type f -path '*/publish/*' -exec sha256sum {} + | sort | awk '
$1 == previous { system("ln -f \"" first "\" \"" $2 "\"") ; next }
{ previous = $1; first = $2 }'

# Remove the links again, so that the ReadyToRun compiler and the runtime packs do not stay in the image.
for package in /r2r-packages/*; do
rm "/root/.nuget/packages/$(basename "${package}")"
done
46 changes: 46 additions & 0 deletions bin/generate-shapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""Write the shapes/ folder from the history of the exercism/vbnet track repo.

A shape is a distinct xUnit v3 project file, ignoring the project name and the settings that do not
affect compiling. This script reads every exercise's .vbproj in every commit since the track
switched to xUnit v3, groups them by shape, and writes one representative project file per shape to
<out_dir>/<n>/ExercismShape.vbproj, with net10.0 replaced by net11.0 as the runner does. The Dockerfile
builds each one (bin/build-shapes.sh), so that the fast path can reuse its compiler arguments.

The grouping here is close to ProjectShape.Key in the runner. If the two ever disagree, the worst
case will be a duplicate template, or a project file with no matching template, which uses MSBuild.

usage: generate-shapes.py <out_dir> [path to the exercism/vbnet repo, default ../vbnet]"""
import subprocess, sys, os, shutil, xml.etree.ElementTree as ET
T = sys.argv[2] if len(sys.argv) > 2 else '../vbnet'
out = sys.argv[1]
IGNORED = {'RestorePackagesWithLockFile', 'IsPackable', 'IsTestProject', 'RootNamespace'}

def git(*a):
return subprocess.run(['git', '-C', T, *a], capture_output=True, check=True, text=True).stdout

def key(text):
root = ET.fromstring(text.replace('net10.0', 'net11.0'))
props, items = {}, []
for g in root:
for e in g:
if g.tag == 'PropertyGroup':
if e.tag not in IGNORED: props[e.tag] = (e.text or '').strip()
else:
items.append((e.tag, tuple(sorted(e.attrib.items())) + tuple(sorted((m.tag, (m.text or '').strip()) for m in e))))
return (tuple(sorted(props.items())), tuple(sorted(items)))

commits = git('log', '--format=%H', '--since=2026-07-01', '--', 'exercises').split() + ['HEAD']
shapes = {}
for c in commits:
for path in git('ls-tree', '-r', '--name-only', c, 'exercises').split('\n'):
if not path.endswith('.vbproj'): continue
text = git('show', f'{c}:{path}')
if 'xunit.v3' not in text: continue
k = key(text)
shapes.setdefault(k, (text, set()))[1].add(path.split('/')[2])
shutil.rmtree(out, ignore_errors=True)
for i, (k, (text, exs)) in enumerate(sorted(shapes.items(), key=lambda kv: (-len(kv[1][1]), kv[0]))):
d = os.path.join(out, f'{i:02d}'); os.makedirs(d)
open(os.path.join(d, 'ExercismShape.vbproj'), 'w').write(text.replace('net10.0', 'net11.0'))
print(i, len(exs), sorted(exs)[:3], dict(k[0]).get('TargetFramework'), [x for x in k[1] if x[0] == 'PackageReference'])
20 changes: 20 additions & 0 deletions shapes/00/ExercismShape.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<Import Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Exercism.Tests.xunit.v3" Version="0.1.0-beta1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="xunit.v3.mtp-off" Version="4.0.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions shapes/01/ExercismShape.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<Import Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Exercism.Tests.xunit.v3" Version="0.1.0-beta1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions shapes/02/ExercismShape.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<Import Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions shapes/03/ExercismShape.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions shapes/04/ExercismShape.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<Import Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Exercism.Tests.xunit.v3" Version="0.1.0-beta1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="5.0.0" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net11.0</TargetFramework>
<OutputType>Exe</OutputType>
<OptionStrict>On</OptionStrict>
<!-- Precompiling the runner and Roslyn saves JIT time on every run. -->
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>

<ItemGroup>
Expand Down
39 changes: 39 additions & 0 deletions src/Exercism.TestRunner.VBNet/FastPath.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Imports System.IO

Namespace Global.Exercism.TestRunner.VBNet
''' <summary>
''' The runner's fast path will compile the solution with Roslyn inside this process, using the
''' compiler arguments of a matching project shape. At image build, bin/build-shapes.sh builds each
''' shape's template project with the real SDK, and then calls PrepareShape.
''' </summary>
Friend NotInheritable Class FastPath
' The template project's name.
Private Const Token As String = "ExercismShape"
' The template's ReadyToRun publish folder, which holds every dependency.
Private Const OutputSubdirectory As String = "publish"

''' <summary>
''' Runs at image build, after the real SDK has built the shape's template project in shapeDirectory.
''' Writes the shape's key and removes the template's own compiled files.
''' </summary>
Public Shared Function PrepareShape(shapeDirectory As String) As Integer
Dim projectFile = Path.Combine(shapeDirectory, $"{Token}.vbproj")
Dim key = ProjectShape.Key(File.ReadAllText(projectFile))
If key Is Nothing OrElse Not File.Exists(Path.Combine(shapeDirectory, "vbc.rsp")) Then
Console.Error.WriteLine($"Shape in {shapeDirectory} cannot be used by the fast path")
Return 1
End If

File.WriteAllText(Path.Combine(shapeDirectory, "shape.key"), key)
Directory.Delete(Path.Combine(shapeDirectory, "bin"), recursive:=True)
For Each outputFile In Directory.EnumerateFiles(Path.Combine(shapeDirectory, OutputSubdirectory), $"{Token}*")
Dim name = Path.GetFileName(outputFile)
If Not name.EndsWith(".deps.json", StringComparison.Ordinal) AndAlso Not name.EndsWith(".runtimeconfig.json", StringComparison.Ordinal) Then
File.Delete(outputFile)
End If
Next

Return 0
End Function
End Class
End Namespace
10 changes: 8 additions & 2 deletions src/Exercism.TestRunner.VBNet/Program.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ Imports CommandLine

Namespace Global.Exercism.TestRunner.VBNet
Public Module Program
Public Sub Main(args As String())
Public Function Main(args As String()) As Integer
' bin/build-shapes.sh calls this at image build, after building each shape's template project.
If args.Length = 2 AndAlso args(0) = "--prepare-shape" Then
Return FastPath.PrepareShape(args(1))
End If

Parser.Default.
ParseArguments(Of RunnerOptions)(args).
WithParsed(AddressOf CreateTestResults)
End Sub
Return 0
End Function

Private Sub CreateTestResults(options As RunnerOptions)
Console.WriteLine($"[{DateTimeOffset.UtcNow:u}] Running test runner for '{options.Slug}' solution...")
Expand Down
Loading