1- // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
1+ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22
33open System
44open System.Diagnostics
55open System.IO
66open System.Reflection
7+ open System.Reflection .PortableExecutable
78open System.Text .RegularExpressions
89
9- module AssemblyVersionCheck =
10+ module AssemblyCheck =
1011
1112 let private versionZero = Version( 0 , 0 , 0 , 0 )
1213 let private versionOne = Version( 1 , 0 , 0 , 0 )
1314 let private commitHashPattern = new Regex( @" Commit Hash: (<developer build>)|([0-9a-fA-F]{40})" , RegexOptions.Compiled)
1415 let private devVersionPattern = new Regex( @" -(ci|dev)" , RegexOptions.Compiled)
1516
16- let verifyAssemblyVersions ( binariesPath : string ) =
17+ let verifyEmbeddedPdb ( filename : string ) =
18+ use fileStream = File.OpenRead( filename)
19+ let reader = new PEReader( fileStream)
20+ let mutable hasEmbeddedPdb = false
21+
22+ try
23+ for entry in reader.ReadDebugDirectory() do
24+ match entry.Type with
25+ | DebugDirectoryEntryType.CodeView ->
26+ let _ = reader.ReadCodeViewDebugDirectoryData( entry)
27+ ()
28+
29+ | DebugDirectoryEntryType.EmbeddedPortablePdb ->
30+ let _ = reader.ReadEmbeddedPortablePdbDebugDirectoryData( entry)
31+ hasEmbeddedPdb <- true
32+ ()
33+
34+ | DebugDirectoryEntryType.PdbChecksum ->
35+ let _ = reader.ReadPdbChecksumDebugDirectoryData( entry)
36+ ()
37+
38+ | _ -> ()
39+ with | e -> printfn " Error validating assembly %s \n Message: %s " filename ( e.ToString())
40+ hasEmbeddedPdb
41+
42+ let verifyAssemblies ( binariesPath : string ) =
43+
1744 let excludedAssemblies =
1845 [ " FSharp.Data.TypeProviders.dll" ]
1946 |> Set.ofList
47+
2048 let fsharpAssemblies =
2149 [ " FSharp*.dll"
2250 " fsc.exe"
@@ -28,12 +56,17 @@ module AssemblyVersionCheck =
2856 |> List.ofSeq
2957 |> List.filter ( fun p -> ( Set.contains ( Path.GetFileName( p)) excludedAssemblies) |> not )
3058
59+ let fsharpExecutingWithEmbeddedPdbs =
60+ fsharpAssemblies
61+ |> List.filter ( fun p -> not ( p.Contains( @" \Proto\" ) || p.Contains( @" \Bootstrap\" ) || p.Contains( @" .resources." ) || p.Contains( @" \FSharpSdk\" ) || p.Contains( @" \tmp\" ) || p.Contains( @" \obj\" )))
62+
3163 // verify that all assemblies have a version number other than 0.0.0.0 or 1.0.0.0
3264 let failedVersionCheck =
3365 fsharpAssemblies
3466 |> List.filter ( fun a ->
3567 let assemblyVersion = AssemblyName.GetAssemblyName( a) .Version
3668 assemblyVersion = versionZero || assemblyVersion = versionOne)
69+
3770 if failedVersionCheck.Length > 0 then
3871 printfn " The following assemblies had a version of %A or %A " versionZero versionOne
3972 printfn " %s \r\n " <| String.Join( " \r\n " , failedVersionCheck)
@@ -43,27 +76,36 @@ module AssemblyVersionCheck =
4376 // verify that all assemblies have a commit hash
4477 let failedCommitHash =
4578 fsharpAssemblies
79+ |> List.filter ( fun p -> not ( p.Contains( @" \FSharpSdk\" )))
4680 |> List.filter ( fun a ->
4781 let fileProductVersion = FileVersionInfo.GetVersionInfo( a) .ProductVersion
4882 not ( commitHashPattern.IsMatch( fileProductVersion) || devVersionPattern.IsMatch( fileProductVersion)))
83+
4984 if failedCommitHash.Length > 0 then
5085 printfn " The following assemblies don't have a commit hash set"
5186 printfn " %s \r\n " <| String.Join( " \r\n " , failedCommitHash)
5287 else
5388 printfn " All shipping assemblies had an appropriate commit hash."
5489
90+ // verify that all assemblies have an embedded pdb
91+ let failedVerifyEmbeddedPdb =
92+ fsharpExecutingWithEmbeddedPdbs
93+ |> List.filter ( fun a -> not ( verifyEmbeddedPdb a))
94+
95+ if failedVerifyEmbeddedPdb.Length > 0 then
96+ printfn " The following assemblies don't have an embedded pdb"
97+ printfn " %s \r\n " <| String.Join( " \r\n " , failedVerifyEmbeddedPdb)
98+ else
99+ printfn " All shipping assemblies had an embedded PDB."
100+
55101 // return code is the number of failures
56- failedVersionCheck.Length + failedCommitHash.Length
102+ failedVersionCheck.Length + failedCommitHash.Length + failedVerifyEmbeddedPdb.Length
57103
104+
105+ [<EntryPoint>]
58106let main ( argv : string array ) =
59107 if argv.Length <> 1 then
60- printfn " Usage: fsi.exe AssemblyVersionCheck.fsx -- path/to/binaries"
108+ printfn " Usage: dotnet AssemblyCheck.dll -- path/to/binaries"
61109 1
62110 else
63- AssemblyVersionCheck.verifyAssemblyVersions argv.[ 0 ]
64-
65- Environment.GetCommandLineArgs()
66- |> Seq.skipWhile ((<>) " --" )
67- |> Seq.skip 1
68- |> Array.ofSeq
69- |> main
111+ AssemblyCheck.verifyAssemblies argv.[ 0 ]
0 commit comments