Skip to content

Commit

Permalink
Merge pull request #8498 from KevinRansom/michalmocarski
Browse files Browse the repository at this point in the history
Michal mocarski's fix
  • Loading branch information
KevinRansom authored Feb 8, 2020
2 parents 95d8977 + 54ff908 commit 5d28cc5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ type ILVersionInfo =
new (major, minor, build, revision) =
{ Major = major; Minor = minor; Build = build; Revision = revision }

/// For debugging
override x.ToString() = sprintf "ILVersionInfo: %u %u %u %u" (x.Major) (x.Minor) (x.Build) (x.Revision)


type Locale = string

[<StructuralEquality; StructuralComparison>]
Expand Down
19 changes: 16 additions & 3 deletions src/fsharp/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,24 @@ module MainModuleBuilder =
v

let productVersionToILVersionInfo (version: string) : ILVersionInfo =
let parseOrZero v = match System.UInt16.TryParse v with (true, i) -> i | (false, _) -> 0us
let parseOrZero i (v:string) =
let v =
// When i = 3 then this is the 4th part of the version. The last part of the version can be trailed by any characters so we trim them off
if i <> 3 then
v
else
((false, ""), v)
||> Seq.fold(fun (finished, v) c ->
match finished with
| false when Char.IsDigit(c) -> false, v + c.ToString()
| _ -> true, v)
|> snd
match System.UInt16.TryParse v with
| (true, i) -> i
| (false, _) -> 0us
let validParts =
version.Split('.')
|> Seq.map parseOrZero
|> Seq.takeWhile ((<>) 0us)
|> Array.mapi(fun i v -> parseOrZero i v)
|> Seq.toList
match validParts @ [0us; 0us; 0us; 0us] with
| major :: minor :: build :: rev :: _ -> ILVersionInfo(major, minor, build, rev)
Expand Down
12 changes: 7 additions & 5 deletions tests/FSharp.Compiler.UnitTests/ProductVersion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module ProductVersionTest =
let validValues () =
let max = System.UInt16.MaxValue
[ "1.2.3.4", ILVersionInfo(1us,2us,3us,4us)
"1.0.3.4", ILVersionInfo(1us,0us,3us,4us)
"7.0.0.4-SomeExtraInformation", ILVersionInfo(7us,0us,0us,4us)
"0.0.0.0", ILVersionInfo(0us,0us,0us,0us)
"3213.57843.32382.59493", ILVersionInfo(3213us,57843us,32382us,59493us)
(sprintf "%d.%d.%d.%d" max max max max), ILVersionInfo(max,max,max,max) ]
Expand All @@ -70,10 +72,10 @@ module ProductVersionTest =

let invalidValues () =
[ "1.2.3.4", ILVersionInfo(1us,2us,3us,4us)
"1.2.3.4a", ILVersionInfo(1us,2us,3us,0us)
"1.2.c3.4", ILVersionInfo(1us,2us,0us,0us)
"1.2-d.3.4", ILVersionInfo(1us,0us,0us,0us)
"1dd.2.3.4", ILVersionInfo(0us,0us,0us,0us)
"1.2.3.4a", ILVersionInfo(1us,2us,3us,4us)
"1.2.c3.4", ILVersionInfo(1us,2us,0us,4us)
"1.2-d.3.4", ILVersionInfo(1us,0us,3us,4us)
"1dd.2.3.4", ILVersionInfo(0us,2us,3us,4us)
"1dd.2da.d3hj.dd4ds", ILVersionInfo(0us,0us,0us,0us)
"1.5.6.7.dasd", ILVersionInfo(1us,5us,6us,7us)
"9.3", ILVersionInfo(9us,3us,0us,0us)
Expand All @@ -83,5 +85,5 @@ module ProductVersionTest =

[<Test>]
let ``should zero starting from first invalid version part`` () =
for (v, expected) in invalidValues() do
for (v, expected) in invalidValues() do
v |> productVersionToILVersionInfo |> Assert.areEqual expected
2 changes: 1 addition & 1 deletion tests/fsharp/tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,7 @@ open System.Reflection
fv.ProductVersion |> Assert.areEqual "45.2048.main1.2-hotfix (upgrade Second Chance security)"

(fv.ProductMajorPart, fv.ProductMinorPart, fv.ProductBuildPart, fv.ProductPrivatePart)
|> Assert.areEqual (45,2048,0,0)
|> Assert.areEqual (45, 2048, 0, 2)


[<Test>]
Expand Down

0 comments on commit 5d28cc5

Please sign in to comment.