Skip to content

Commit

Permalink
Enable xml doc file
Browse files Browse the repository at this point in the history
  • Loading branch information
zanaptak committed Sep 29, 2019
1 parent 9576ba4 commit d5cd7c7
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 42 deletions.
106 changes: 66 additions & 40 deletions invoke.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ param (
$LocalPackageDir = ( property LocalPackageDir 'C:\code\LocalPackages' )
)

$basePackageName = 'Zanaptak.PcgRandom'
$baseProjectName = "PcgRandom"
$basePackageName = "Zanaptak.$baseProjectName"

task . Build

Expand All @@ -24,6 +25,25 @@ task Build {
exec { dotnet build .\src -c Release }
}

task TestJs {
Set-Location .\test
if ( -not ( Test-Path node_modules ) ) { exec { npm install } }
remove bld
exec { npm test }
}

task TestNet Clean, Build, {
Set-Location .\test
exec { dotnet run -c Release }
}

task Test TestJs, TestNet

task Benchmark Clean, Build, {
Set-Location .\benchmark
exec { dotnet run -c Release }
}

task Pack Clean, Build, {
exec { dotnet pack .\src -c Release }
}
Expand All @@ -39,60 +59,66 @@ task PackInternal Clean, Build, GetVersion, {
Write-Build Green "Copied $filename to $LocalPackageDir"
}

function UpdateProjectFile(
[ string ] $Filename ,
[ string ] $XPath ,
[ string ] $Value
) {

$xml = New-Object System.Xml.XmlDocument
$xml.PreserveWhitespace = $true
$xml.Load( $Filename )

$node = $xml.SelectSingleNode( $XPath )
if ( -not ( $node ) ) { throw "xpath not found" }
$node.InnerText = $Value

$settings = New-Object System.Xml.XmlWriterSettings
$settings.OmitXmlDeclaration = $true
$settings.Encoding = New-Object System.Text.UTF8Encoding( $true )

$writer = [ System.Xml.XmlWriter ]::Create( $Filename , $settings )
try {
$xml.Save( $writer )
} finally {
$writer.Dispose()
}
}

task IncrementMinor GetVersion, {
if ( $Version -match "^(\d+)\.(\d+)\." ) {
if ( $Version -match "^(\d+)\.(\d+)\.(\d+)$" ) {
$projectFile = "$BuildRoot\src\$baseProjectName.fsproj"
$major = $Matches[ 1 ]
Write-Host "major $major"
$minor = $Matches[ 2 ]
Write-Host "minor $minor"
$patch = $Matches[ 3 ]
$newMinor = ( [ int ] $minor ) + 1
$newVersion = "$major.$newMinor.0"

$xml = New-Object System.Xml.XmlDocument
$xml.PreserveWhitespace = $true
$xml.Load( "$BuildRoot\src\PcgRandom.fsproj" )

$node = $xml.SelectSingleNode( '/Project/PropertyGroup/Version' )
$node.InnerText = $newVersion

$settings = New-Object System.Xml.XmlWriterSettings
$settings.OmitXmlDeclaration = $true
$settings.Encoding = New-Object System.Text.UTF8Encoding( $true )

$writer = [ System.Xml.XmlWriter ]::Create( "$BuildRoot\src\PcgRandom.fsproj" , $settings )
try {
$xml.Save( $writer )
} finally {
$writer.Dispose()
}
UpdateProjectFile $projectFile '/Project/PropertyGroup/Version' $newVersion
Write-Build Green "Updated version to $newVersion"
}
else {
throw "invalid version: $Version"
}
}

task TestJs {
Set-Location .\test
if ( -not ( Test-Path node_modules ) ) { exec { npm install } }
remove bld
exec { npm test }
}

task TestNet Clean, Build, {
Set-Location .\test
exec { dotnet run -c Release }
}

task Test TestJs, TestNet

task Benchmark Clean, Build, {
Set-Location .\benchmark
exec { dotnet run -c Release }
task IncrementPatch GetVersion, {
if ( $Version -match "^(\d+)\.(\d+)\.(\d+)$" ) {
$projectFile = "$BuildRoot\src\$baseProjectName.fsproj"
$major = $Matches[ 1 ]
$minor = $Matches[ 2 ]
$patch = $Matches[ 3 ]
$newPatch = ( [ int ] $patch ) + 1
$newVersion = "$major.$minor.$newPatch"
UpdateProjectFile $projectFile '/Project/PropertyGroup/Version' $newVersion
Write-Build Green "Updated version to $newVersion"
}
else {
throw "invalid version: $Version"
}
}

task GetVersion {
$script:Version = Select-Xml -Path .\src\PcgRandom.fsproj -XPath /Project/PropertyGroup/Version | % { $_.Node.InnerXml.Trim() }
$script:Version = Select-Xml -Path ".\src\$baseProjectName.fsproj" -XPath /Project/PropertyGroup/Version | % { $_.Node.InnerXml.Trim() }
}

task UploadNuGet EnsureCommitted, GetVersion, {
Expand Down
6 changes: 5 additions & 1 deletion src/Pcg.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ open Utils
open System

/// PCG-backed pseudorandom number generator compatible with System.Random.
type Pcg( seed : int ) =
type Pcg private ( dummy : unit , seed : int ) =
// Private primary constructor since it doesn't support xml doc.

#if ! FABLE_COMPILER
inherit Random()
#endif
Expand Down Expand Up @@ -44,6 +46,8 @@ type Pcg( seed : int ) =
for j in 0 .. min 3 ( endIndex - i ) do
bytes.[ i + j ] <- randVal >>> ( j * 8 ) |> byte

/// PCG-backed pseudorandom number generator compatible with System.Random.
new ( seed : int ) = Pcg( () , seed )
/// PCG-backed pseudorandom number generator compatible with System.Random.
new() = Pcg( seed32 () |> int )

Expand Down
6 changes: 5 additions & 1 deletion src/PcgRandom.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
<Version>0.2.0</Version>
<Version>0.2.1</Version>
<Authors>zanaptak</Authors>
<AssemblyName>Zanaptak.PcgRandom</AssemblyName>
<Product>Zanaptak.PcgRandom</Product>
Expand All @@ -17,6 +17,10 @@
<Description>A PCG pseudorandom number generator implementation for .NET and Fable. PCG (http://www.pcg-random.org/) is a family of simple fast space-efficient statistically good algorithms for random number generation.</Description>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="Utils.fs" />
<Compile Include="BigintUtils.fs" />
Expand Down
6 changes: 6 additions & 0 deletions src/PcgRandom.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ VisualStudioVersion = 16.0.29209.62
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "PcgRandom", "PcgRandom.fsproj", "{D205156D-7FDB-43AD-9158-3DC06824FE93}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6734C90D-5B0C-448D-BD3B-8E9427C59762}"
ProjectSection(SolutionItems) = preProject
..\invoke.build.ps1 = ..\invoke.build.ps1
..\README.md = ..\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit d5cd7c7

Please sign in to comment.