Skip to content

Commit

Permalink
fixes issue #6832 (#7259)
Browse files Browse the repository at this point in the history
* fixes issue #6832

* Fix comment

* Forgot to remove pdbs from fsharp.compiler.nuget

* Rename Program.fs and exclude FSharpSdk from checks

* Embedded doesn't need to verify tmp or obj directories.

* typo

* typo

* Don't check FSharpSdk for hash

* Make comment match code

* Empty commit to force rebuild
  • Loading branch information
KevinRansom committed Jul 25, 2019
1 parent 0bd851b commit 37970b4
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 33 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 0x0100
iddMinorVersion = 0x0100 // VersionMinor should be 0x0100
iddType = 17 // IMAGE_DEBUG_TYPE_EMBEDDEDPDB
iddTimestamp = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
// 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 =
module AssemblyCheck =

let private versionZero = Version(0, 0, 0, 0)
let private versionOne = Version(1, 0, 0, 0)
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 @@ -28,12 +56,17 @@ module AssemblyVersionCheck =
|> List.ofSeq
|> List.filter (fun p -> (Set.contains (Path.GetFileName(p)) excludedAssemblies) |> not)

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

// 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 @@ -43,27 +76,36 @@ module AssemblyVersionCheck =
// verify that all assemblies have a commit hash
let failedCommitHash =
fsharpAssemblies
|> List.filter (fun p -> not (p.Contains(@"\FSharpSdk\")))
|> 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 an embedded pdb
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 AssemblyCheck.dll -- path/to/binaries"
1
else
AssemblyVersionCheck.verifyAssemblyVersions argv.[0]

Environment.GetCommandLineArgs()
|> Seq.skipWhile ((<>) "--")
|> Seq.skip 1
|> Array.ofSeq
|> main
AssemblyCheck.verifyAssemblies argv.[0]
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="AssemblyCheck.fs" />
</ItemGroup>

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

</Project>
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
14 changes: 3 additions & 11 deletions src/fsharp/FSharp.Compiler.nuget/Microsoft.FSharp.Compiler.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@
<file src="FSharp.Compiler.Private\$Configuration$\netstandard2.0\FSharp.Compiler.Private.dll" target="lib\netcoreapp2.1" />
<file src="FSharp.Build\$Configuration$\netcoreapp2.1\FSharp.Build.dll" target="lib\netcoreapp2.1" />
<file src="FSharp.Compiler.Interactive.Settings\$Configuration$\netstandard2.0\FSharp.Compiler.Interactive.Settings.dll"
target="lib\netcoreapp2.1" />
<!-- symbols -->
<file src="fsc\$Configuration$\netcoreapp2.1\fsc.pdb" target="lib\netcoreapp2.1" />
<file src="fsi\$Configuration$\netcoreapp2.1\fsi.pdb" target="lib\netcoreapp2.1" />
<file src="FSharp.Core\$Configuration$\netstandard1.6\FSharp.Core.pdb" target="lib\netcoreapp2.1" />
<file src="FSharp.Compiler.Private\$Configuration$\netstandard2.0\FSharp.Compiler.Private.pdb" target="lib\netcoreapp2.1" />
<file src="FSharp.Build\$Configuration$\netcoreapp2.1\FSharp.Build.pdb" target="lib\netcoreapp2.1" />
<file src="FSharp.Compiler.Interactive.Settings\$Configuration$\netstandard2.0\FSharp.Compiler.Interactive.Settings.pdb"
target="lib\netcoreapp2.1" />
target="lib\netcoreapp2.1" />
<!-- additional files -->
<file src="fsc\$Configuration$\netcoreapp2.1\default.win32manifest" target="contentFiles\any\any" />
<file src="FSharp.Build\$Configuration$\netcoreapp2.1\Microsoft.FSharp.Targets" target="contentFiles\any\any" />
Expand All @@ -69,9 +61,9 @@
<!-- resources -->
<file src="FSharp.Core\$Configuration$\netstandard1.6\**\FSharp.Core.resources.dll" target="lib\netcoreapp2.1" />
<file src="FSharp.Compiler.Private\$Configuration$\netstandard2.0\**\FSharp.Compiler.Private.resources.dll"
target="lib\netcoreapp2.1" />
target="lib\netcoreapp2.1" />
<file src="FSharp.Compiler.Interactive.Settings\$Configuration$\netstandard2.0\**\FSharp.Compiler.Interactive.Settings.resources.dll"
target="lib\netcoreapp2.1" />
target="lib\netcoreapp2.1" />
<file src="FSharp.Build\$Configuration$\netcoreapp2.1\**\FSharp.Build.resources.dll" target="lib\netcoreapp2.1" />
</files>
</package>
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 37970b4

Please sign in to comment.