Skip to content

Commit

Permalink
chore: use simplified artifacts output (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
latonz authored Nov 19, 2023
1 parent 50335d2 commit c5f0c54
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>0.0.1-dev</Version>
Expand Down
13 changes: 5 additions & 8 deletions docs/prebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function emptyDirectory(dir: string): Promise<void> {
async function buildApiDocs(): Promise<void> {
const targetDir = './docs/api';
const dll =
'../src/Riok.Mapperly.Abstractions/bin/Debug/netstandard2.0/Riok.Mapperly.Abstractions.dll';
'../artifacts/bin/Riok.Mapperly.Abstractions/debug/Riok.Mapperly.Abstractions.dll';

// clean target directory
await emptyDirectory(targetDir);
Expand Down Expand Up @@ -91,17 +91,14 @@ async function buildSamples(): Promise<void> {
const targetDir = join(generatedDataDir, 'samples');
await mkdir(targetDir);

const sampleProject = '../samples/Riok.Mapperly.Sample';
const projectFilesToCopy = ['CarMapper.cs', 'Car.cs', 'CarDto.cs'];
const generatedMapperFile = join(
sampleProject,
'obj/Debug/net8.0/generated/Riok.Mapperly/Riok.Mapperly.MapperGenerator/CarMapper.g.cs',
);

// Copy generated mapper to target dir
const generatedMapperFile =
'../artifacts/obj/Riok.Mapperly.Sample/debug/generated/Riok.Mapperly/Riok.Mapperly.MapperGenerator/CarMapper.g.cs';
await copyFile(generatedMapperFile, join(targetDir, 'CarMapper.g.cs'));

// Copy sample project files to target dir
const sampleProject = '../samples/Riok.Mapperly.Sample';
const projectFilesToCopy = ['CarMapper.cs', 'Car.cs', 'CarDto.cs'];
for (const file of projectFilesToCopy) {
await copyFile(join(sampleProject, file), join(targetDir, file));
}
Expand Down
37 changes: 32 additions & 5 deletions test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace Riok.Mapperly.IntegrationTests
{
public abstract class BaseMapperTest
{
private static string SolutionDirectory = GetSolutionDirectory();
private static string ProjectDirectory = GetProjectDirectory();

static BaseMapperTest()
{
#if !NET6_0_OR_GREATER
Expand All @@ -28,21 +31,24 @@ static BaseMapperTest()
VerifierSettings.DontScrubDateTimes();

Verifier.DerivePathInfo(
(file, _, type, method) =>
(_, _, type, method) =>
new PathInfo(
Path.Combine(Path.GetDirectoryName(file)!, "_snapshots"),
Path.Combine(ProjectDirectory, "_snapshots"),
type.Name,
method.Name + GetSnapshotVersionSuffix(type, method)
)
);
}

protected string GetGeneratedMapperFilePath(string name, [CallerFilePath] string filePath = "")
protected string GetGeneratedMapperFilePath(string name)
{
return Path.Combine(
Path.GetDirectoryName(filePath)!,
SolutionDirectory,
"artifacts",
"obj",
"GeneratedFiles",
"Riok.Mapperly.IntegrationTests",
"debug",
"generated",
"Riok.Mapperly",
"Riok.Mapperly.MapperGenerator",
name + ".g.cs"
Expand Down Expand Up @@ -169,5 +175,26 @@ private static Versions GetCurrentVersion()
throw new InvalidOperationException("Target framework is not supported");
#endif
}

private static string GetProjectDirectory() => FindDirectoryOfFile(".csproj");

private static string GetSolutionDirectory() => FindDirectoryOfFile(".sln");

private static string FindDirectoryOfFile(string fileExtension, [CallerFilePath] string baseFilePath = "")
{
var dir =
Path.GetDirectoryName(baseFilePath) ?? throw new InvalidOperationException($"Could not get directory from {baseFilePath}");

while (Directory.GetFiles(dir, "*" + fileExtension, SearchOption.TopDirectoryOnly).Length == 0)
{
dir = Path.GetDirectoryName(dir);
if (dir == null)
{
throw new InvalidOperationException($"Could not find directory from file {baseFilePath}");
}
}

return dir;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
<TargetFramework>$(MapperlyIntegrationTestsTargetFramework)</TargetFramework>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)/GeneratedFiles</CompilerGeneratedFilesOutputPath>

<!-- Not supported in .NET Framework -->
<ImplicitUsings>disable</ImplicitUsings>

<LangVersion>preview</LangVersion>

<!-- .NET Framework 4.8 defaults to lang version 7.3, but we want to test nullable features. These are available in 8.0.
To also use init-only properties, we upgrade to lang version 9.0, which is works, but is not officially supported. -->
<LangVersion Condition="'$(TargetFramework)' == 'net48'">9.0</LangVersion>
Expand Down

0 comments on commit c5f0c54

Please sign in to comment.