Skip to content

Commit

Permalink
fixes issue dotnet#6832
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Jul 20, 2019
1 parent 3e7b66d commit cdbfbdc
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 21 deletions.
3 changes: 2 additions & 1 deletion FSharpBuild.Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<RepositoryUrl Condition="'$(RepositoryUrl)' == ''">https://github.com/Microsoft/visualfsharp</RepositoryUrl>
<RepositoryType Condition="'$(RepositoryType)' == ''">git</RepositoryType>
</PropertyGroup>

<PropertyGroup Condition="'$(FSharpSourceBuild)' == 'true' AND '$(RepositoryCommit)' == ''">
<_DotGitDir>$(RepoRoot).git</_DotGitDir>
<_HeadFileContent Condition="Exists('$(_DotGitDir)/HEAD')">$([System.IO.File]::ReadAllText('$(_DotGitDir)/HEAD').Trim())</_HeadFileContent>
Expand All @@ -87,7 +88,7 @@
<PropertyGroup>
<NoWarn Condition="'$(Language)' == 'F#'">$(NoWarn);FS2003</NoWarn><!-- warning when AssemblyInformationalVersion looks like '1.2.3-dev' -->
<NoCompilerStandardLib>true</NoCompilerStandardLib><!-- necessary for resource generation using csc.exe -->
<DebugType>portable</DebugType>
<DebugType>embedded</DebugType>
<MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
<UseStandardResourceNames>false</UseStandardResourceNames>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
11 changes: 6 additions & 5 deletions eng/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,14 @@ function UpdatePath() {
TestAndAddToPath "$ArtifactsDir\bin\fsiAnyCpu\$configuration\net472"
}

function VerifyAssemblyVersions() {
$fsiPath = Join-Path $ArtifactsDir "bin\fsi\Proto\net472\publish\fsi.exe"
function VerifyAssemblyVersionsAndSymbols() {
$assemblyVerCheckPath = Join-Path $ArtifactsDir "Bootstrap\AssemblyCheck\AssemblyCheck.dll"

# Only verify versions on CI or official build
if ($ci -or $official) {
$asmVerCheckPath = "$RepoRoot\scripts"
Exec-Console $fsiPath """$asmVerCheckPath\AssemblyVersionCheck.fsx"" -- ""$ArtifactsDir"""
$dotnetPath = InitializeDotNetCli
$dotnetExe = Join-Path $dotnetPath "dotnet.exe"
Exec-Console $dotnetExe """$assemblyVerCheckPath"" ""$ArtifactsDir"""
}
}

Expand Down Expand Up @@ -307,7 +308,7 @@ try {
}

if ($build) {
VerifyAssemblyVersions
VerifyAssemblyVersionsAndSymbols
}

$desktopTargetFramework = "net472"
Expand Down
3 changes: 2 additions & 1 deletion eng/build-utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ function Make-BootstrapBuild() {
Remove-Item -re $dir -ErrorAction SilentlyContinue
Create-Directory $dir

# prepare FsLex and Fsyacc
# prepare FsLex and Fsyacc and AssemblyCheck
Run-MSBuild "$RepoRoot\src\buildtools\buildtools.proj" "/restore /t:Publish" -logFileName "BuildTools" -configuration $bootstrapConfiguration
Copy-Item "$ArtifactsDir\bin\fslex\$bootstrapConfiguration\netcoreapp2.1\publish" -Destination "$dir\fslex" -Force -Recurse
Copy-Item "$ArtifactsDir\bin\fsyacc\$bootstrapConfiguration\netcoreapp2.1\publish" -Destination "$dir\fsyacc" -Force -Recurse
Copy-Item "$ArtifactsDir\bin\AssemblyCheck\$bootstrapConfiguration\netcoreapp2.1\publish" -Destination "$dir\AssemblyCheck" -Force -Recurse

# prepare compiler
$projectPath = "$RepoRoot\proto.proj"
Expand Down
2 changes: 1 addition & 1 deletion src/absil/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ let pdbGetEmbeddedPdbDebugInfo (embeddedPdbChunk: BinaryChunk) (uncompressedLeng
Buffer.BlockCopy(stream.ToArray(), 0, buffer, offset, size)
buffer
{ iddCharacteristics = 0 // Reserved
iddMajorVersion = 0 // VersionMajor should be 0
iddMajorVersion = 0x0100 // VersionMajor should be 0
iddMinorVersion = 0x0100 // VersionMinor should be 0x0100
iddType = 17 // IMAGE_DEBUG_TYPE_EMBEDDEDPDB
iddTimestamp = 0
Expand Down
17 changes: 17 additions & 0 deletions src/buildtools/AssemblyCheck/AssemblyCheck.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\fsharp\FSharp.Core\FSharp.Core.fsproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

open System
open System.Diagnostics
open System.IO
open System.Reflection
open System.Reflection.PortableExecutable
open System.Text.RegularExpressions

module AssemblyVersionCheck =
Expand All @@ -13,10 +14,37 @@ module AssemblyVersionCheck =
let private commitHashPattern = new Regex(@"Commit Hash: (<developer build>)|([0-9a-fA-F]{40})", RegexOptions.Compiled)
let private devVersionPattern = new Regex(@"-(ci|dev)", RegexOptions.Compiled)

let verifyAssemblyVersions (binariesPath:string) =
let verifyEmbeddedPdb (filename:string) =
use fileStream = File.OpenRead(filename)
let reader = new PEReader(fileStream)
let mutable hasEmbeddedPdb = false

try
for entry in reader.ReadDebugDirectory() do
match entry.Type with
| DebugDirectoryEntryType.CodeView ->
let _ = reader.ReadCodeViewDebugDirectoryData(entry)
()

| DebugDirectoryEntryType.EmbeddedPortablePdb ->
let _ = reader.ReadEmbeddedPortablePdbDebugDirectoryData(entry)
hasEmbeddedPdb <- true
()

| DebugDirectoryEntryType.PdbChecksum ->
let _ = reader.ReadPdbChecksumDebugDirectoryData(entry)
()

| _ -> ()
with | e -> printfn "Error validating assembly %s\nMessage: %s" filename (e.ToString())
hasEmbeddedPdb

let verifyAssemblies (binariesPath:string) =

let excludedAssemblies =
[ "FSharp.Data.TypeProviders.dll" ]
|> Set.ofList

let fsharpAssemblies =
[ "FSharp*.dll"
"fsc.exe"
Expand All @@ -27,13 +55,19 @@ module AssemblyVersionCheck =
|> Seq.concat
|> List.ofSeq
|> List.filter (fun p -> (Set.contains (Path.GetFileName(p)) excludedAssemblies) |> not)
|> List.filter (fun p -> not (p.Contains(@"\Proto\") || p.Contains(@"\Bootstrap\") || p.Contains(@".resources.")))

let fsharpExecutingWithEmbeddedPdbs =
fsharpAssemblies
|> List.filter (fun p -> not (p.Contains(@"\Proto\") || p.Contains(@"\Bootstrap\") || p.Contains(@".resources.")))

// verify that all assemblies have a version number other than 0.0.0.0 or 1.0.0.0
let failedVersionCheck =
fsharpAssemblies
|> List.filter (fun a ->
let assemblyVersion = AssemblyName.GetAssemblyName(a).Version
assemblyVersion = versionZero || assemblyVersion = versionOne)

if failedVersionCheck.Length > 0 then
printfn "The following assemblies had a version of %A or %A" versionZero versionOne
printfn "%s\r\n" <| String.Join("\r\n", failedVersionCheck)
Expand All @@ -46,24 +80,32 @@ module AssemblyVersionCheck =
|> List.filter (fun a ->
let fileProductVersion = FileVersionInfo.GetVersionInfo(a).ProductVersion
not (commitHashPattern.IsMatch(fileProductVersion) || devVersionPattern.IsMatch(fileProductVersion)))

if failedCommitHash.Length > 0 then
printfn "The following assemblies don't have a commit hash set"
printfn "%s\r\n" <| String.Join("\r\n", failedCommitHash)
else
printfn "All shipping assemblies had an appropriate commit hash."

// verify that all assemblies have a commit hash
let failedVerifyEmbeddedPdb =
fsharpExecutingWithEmbeddedPdbs
|> List.filter (fun a -> not (verifyEmbeddedPdb a))

if failedVerifyEmbeddedPdb.Length > 0 then
printfn "The following assemblies don't have an embedded pdb"
printfn "%s\r\n" <| String.Join("\r\n", failedVerifyEmbeddedPdb)
else
printfn "All shipping assemblies had an embedded PDB."

// return code is the number of failures
failedVersionCheck.Length + failedCommitHash.Length
failedVersionCheck.Length + failedCommitHash.Length + failedVerifyEmbeddedPdb.Length


[<EntryPoint>]
let main (argv:string array) =
if argv.Length <> 1 then
printfn "Usage: fsi.exe AssemblyVersionCheck.fsx -- path/to/binaries"
printfn "Usage: dotnet AssemblyVersionCheck.dll -- path/to/binaries"
1
else
AssemblyVersionCheck.verifyAssemblyVersions argv.[0]

Environment.GetCommandLineArgs()
|> Seq.skipWhile ((<>) "--")
|> Seq.skip 1
|> Array.ofSeq
|> main
AssemblyVersionCheck.verifyAssemblies argv.[0]
1 change: 1 addition & 0 deletions src/buildtools/buildtools.proj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<Projects Include="fslex\fslex.fsproj" />
<Projects Include="fsyacc\fsyacc.fsproj" />
<Projects Include="AssemblyCheck\AssemblyCheck.fsproj" />
</ItemGroup>

<Target Name="Build">
Expand Down
2 changes: 0 additions & 2 deletions src/fsharp/FSharp.Core.nuget/FSharp.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@
</metadata>
<files>
<file src="FSharp.Core\$Configuration$\netstandard1.6\FSharp.Core.dll" target="lib\netstandard1.6" />
<file src="FSharp.Core\$Configuration$\netstandard1.6\FSharp.Core.pdb" target="lib\netstandard1.6" />
<file src="FSharp.Core\$Configuration$\netstandard1.6\FSharp.Core.sigdata" target="lib\netstandard1.6" />
<file src="FSharp.Core\$Configuration$\netstandard1.6\FSharp.Core.optdata" target="lib\netstandard1.6" />
<file src="FSharp.Core\$Configuration$\netstandard1.6\FSharp.Core.xml" target="lib\netstandard1.6" />

<file src="FSharp.Core\$Configuration$\net45\FSharp.Core.dll" target="lib\net45" />
<file src="FSharp.Core\$Configuration$\net45\FSharp.Core.pdb" target="lib\net45" />
<file src="FSharp.Core\$Configuration$\net45\FSharp.Core.sigdata" target="lib\net45" />
<file src="FSharp.Core\$Configuration$\net45\FSharp.Core.optdata" target="lib\net45" />
<file src="FSharp.Core\$Configuration$\net45\FSharp.Core.xml" target="lib\net45" />
Expand Down

0 comments on commit cdbfbdc

Please sign in to comment.