Skip to content

Commit

Permalink
Cleanup build project
Browse files Browse the repository at this point in the history
  • Loading branch information
Romfos committed Dec 4, 2024
1 parent 4437c2b commit 334894f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 52 deletions.
78 changes: 27 additions & 51 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ open Fake.IO.FileSystemOperators

open ExtractDocs

let target = Target.create
let description = Target.description

module FileReaderWriter =
let Read file = File.ReadAllText(file)
let Write file (text: string) = File.WriteAllText(file, text)
Expand All @@ -36,60 +33,39 @@ module ExamplesToCode =
for file in files do
ConvertFile file targetDir

type BuildVersion = { assembly: string; file: string; info: string; package: string }

let root = __SOURCE_DIRECTORY__ </> ".." |> Path.getFullName

let configuration = Environment.environVarOrDefault "configuration" "Debug"

let output = root </> "bin" </> configuration
let solution = (root </> "NSubstitute.sln")

let initTargets() =
Target.description("Extract, build and test code from documentation.")
Target.create "TestCodeFromDocs" <| fun _ ->
let outputCodePath = output </> "CodeFromDocs"
Directory.create outputCodePath
// generate samples from docs
ExamplesToCode.Convert [ root </> "docs/"; root </> "docs/docs"; root ] outputCodePath
// compile code samples
let csproj = """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\NSubstitute\NSubstitute.csproj" />
</ItemGroup>
</Project>
"""
let projPath = outputCodePath </> "Docs.csproj"
FileReaderWriter.Write projPath csproj
DotNet.restore (fun p -> p) projPath
DotNet.build (fun p -> p) projPath
DotNet.test (fun p -> p) projPath

Target.description("List targets, similar to `rake -T`. For more details, run `--listTargets` instead.")
Target.create "-T" <| fun _ ->
printfn "Optional config options:"
printfn " configuration=Debug|Release"
printfn " benchmark=*|<benchmark name> (only for Benchmarks target in Release mode)"
printfn ""
Target.listAvailable()

[<EntryPoint>]
let main argv =
argv
|> Array.toList
|> Context.FakeExecutionContext.Create false "build.fsx"
|> Context.RuntimeContext.Fake
|> Context.setExecutionContext
initTargets()
Target.runOrDefaultWithArguments "TestCodeFromDocs"
0
let outputCodePath = output </> "CodeFromDocs"
Directory.create outputCodePath
// generate samples from docs
ExamplesToCode.Convert [ root </> "docs/"; root </> "docs/docs"; root ] outputCodePath
// compile code samples
let csproj = """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\NSubstitute\NSubstitute.csproj" />
</ItemGroup>
</Project>
"""
let projPath = outputCodePath </> "Docs.csproj"
FileReaderWriter.Write projPath csproj
DotNet.restore (fun p -> p) projPath
DotNet.build (fun p -> p) projPath
DotNet.test (fun p -> p) projPath
0
1 change: 0 additions & 1 deletion build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.12.6" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.386" />
<PackageReference Include="Fake.DotNet.Cli" Version="6.1.3" />
<PackageReference Include="Fake.Core.Target" Version="6.1.3" />
</ItemGroup>

</Project>

0 comments on commit 334894f

Please sign in to comment.