Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcelink #1609

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ tests/fsharp/core/array/dont.run.peverify
tests/fsharp/core/innerpoly/dont.run.peverify
tests/fsharp/typecheck/sigs/neg94-pre.dll
times
source_link.json
14 changes: 6 additions & 8 deletions src/FSharpSource.Settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<BuildToolsTaskDir>$(ToolsDir)net45\</BuildToolsTaskDir>
<WarningsAsErrors />
<FX_NO_LOADER Condition=" '$(FX_NO_LOADER)'==''">false</FX_NO_LOADER>

<!-- Always qualify the IntermediateOutputPath by the TargetFramework if any exists -->
<IntermediateOutputPath>obj\$(Configuration)\$(TargetFramework)\</IntermediateOutputPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(ProjectLanguage)' == 'FSharp' ">
Expand All @@ -26,11 +29,11 @@
<!-- Standard interpretations of Debug and Release configurations -->
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType Condition=" '$(DebugType)' == '' and '$(TargetFramework)' != 'coreclr' ">full</DebugType>
<DebugType Condition=" '$(DebugType)' == '' and '$(TargetFramework)' == 'coreclr' ">embedded</DebugType>
<DebugType Condition=" '$(DebugType)' == '' and '$(TargetFramework)' == 'coreclr' ">portable</DebugType>
<Optimize Condition=" '$(Optimize)' == '' ">false</Optimize>
<ErrorReport Condition=" '$(ErrorReport)' == '' ">prompt</ErrorReport>
<OtherFlags Condition=" '$(DebugType)' == '' and '$(TargetFramework)' != 'coreclr' ">$(OtherFlags) --no-jit-optimize</OtherFlags>
<OtherFlags Condition=" '$(DebugType)' == '' and '$(TargetFramework)' == 'coreclr' ">$(OtherFlags) --no-jit-optimize --embed</OtherFlags>
<OtherFlags>$(OtherFlags) --no-jit-optimize</OtherFlags>
<OtherFlags Condition=" '$(DebugType)' == 'portable' or '$(DebugType)' == 'embedded' ">$(OtherFlags) --embed --sourcelink:$(IntermediateOutputPath)source_link.json</OtherFlags>
<DefineConstants Condition=" '$(ProjectLanguage)' != 'VisualBasic' ">DEBUG;TRACE;CODE_ANALYSIS;$(DefineConstants)</DefineConstants>
<DefineConstants Condition=" '$(ProjectLanguage)' == 'VisualBasic' ">DEBUG=True,TRACE=True,CODE_ANALYSIS=True,$(DefineConstants)</DefineConstants>
<SIGN_WITH_MSFT_KEY Condition=" '$(SIGN_WITH_MSFT_KEY)' == '' ">false</SIGN_WITH_MSFT_KEY>
Expand All @@ -57,11 +60,6 @@
<WarningLevel Condition=" '$(WarningLevel)' == '' ">3</WarningLevel>
</PropertyGroup>

<!-- Always qualify the IntermediateOutputPath by the TargetFramework if any exists -->
<PropertyGroup>
<IntermediateOutputPath>obj\$(Configuration)\$(TargetFramework)\</IntermediateOutputPath>
</PropertyGroup>

<PropertyGroup>
<DefineConstants Condition="'$(VisualStudioVersion)'=='12.0' AND '$(ProjectLanguage)' == 'VisualBasic'">$(DefineConstants),VS_VERSION_DEV12=True</DefineConstants>
<DefineConstants Condition="'$(VisualStudioVersion)'=='12.0' AND '$(ProjectLanguage)' != 'VisualBasic'">$(DefineConstants);VS_VERSION_DEV12</DefineConstants>
Expand Down
17 changes: 17 additions & 0 deletions src/FSharpSource.targets
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,25 @@
<CompileBefore Remove="@(CompileBefore)"/>
</ItemGroup>
</Target>

<Target Name="BeforeBuild" BeforeTargets="Build" Condition="'$(RestorePackages)' == ''">
<Exec Command=".\.nuget\NuGet.exe restore packages.config -PackagesDirectory packages -ConfigFile .\.nuget\NuGet.Config" WorkingDirectory="$(FSharpSourcesRoot)\.."/>
<Exec Command=".\.nuget\NuGet.exe restore .\tests\fsharp\project.json -PackagesDirectory packages -ConfigFile .\.nuget\NuGet.Config" WorkingDirectory="$(FSharpSourcesRoot)\.." Condition="'$(TargetFramework)' == 'coreclr'"/>
</Target>

<Target Name="GenerateSourceLink" BeforeTargets="CoreCompile">
<PropertyGroup>
<SrcRootDirectory>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory.TrimEnd("\"))))</SrcRootDirectory>
</PropertyGroup>
<Exec Command="git config --get remote.origin.url" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="RemoteUri" />
</Exec>

<!-- https://raw.githubusercontent.com/KevinRansom/visualfsharp/98e8c9a2ca09a36ebd024eb424fc050a831053cd/build.cmd -->
<Exec Command="git rev-parse HEAD" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="LatestCommit" />
</Exec>
<WriteLinesToFile File="$(IntermediateOutputPath)source_link.json" Overwrite="true" Lines='{"documents": { "$(SrcRootDirectory)/*" : "$(RemoteUri.Replace(".git", "").Replace("github.com", "raw.githubusercontent.com"))/$(LatestCommit)/*" }}' />
</Target>

</Project>
7 changes: 4 additions & 3 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3537,7 +3537,7 @@ let writeDirectory os dict =
let writeBytes (os: BinaryWriter) (chunk:byte[]) = os.Write(chunk,0,chunk.Length)

let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer: ILStrongNameSigner option, portablePDB, embeddedPDB, embedAllSource, embedSourceList,
fixupOverlappingSequencePoints, emitTailcalls, showTimes, dumpDebugInfo) modul noDebugData =
sourceLink, fixupOverlappingSequencePoints, emitTailcalls, showTimes, dumpDebugInfo) modul noDebugData =
// Store the public key from the signer into the manifest. This means it will be written
// to the binary and also acts as an indicator to leave space for delay sign

Expand Down Expand Up @@ -3690,7 +3690,7 @@ let writeBinaryAndReportMappings (outfile, ilg, pdbfile: string option, signer:
let pdbOpt =
match portablePDB with
| true ->
let struct (uncompressedLength, contentId, stream) as pdbStream = generatePortablePdb fixupOverlappingSequencePoints embedAllSource embedSourceList showTimes pdbData
let struct (uncompressedLength, contentId, stream) as pdbStream = generatePortablePdb fixupOverlappingSequencePoints embedAllSource embedSourceList sourceLink showTimes pdbData
if embeddedPDB then Some (compressPortablePdbStream uncompressedLength contentId stream)
else Some (pdbStream)
| _ -> None
Expand Down Expand Up @@ -4262,6 +4262,7 @@ type options =
embeddedPDB: bool
embedAllSource: bool
embedSourceList: string list
sourceLink: string
signer: ILStrongNameSigner option
fixupOverlappingSequencePoints: bool
emitTailcalls : bool
Expand All @@ -4270,5 +4271,5 @@ type options =

let WriteILBinary (outfile, (args: options), modul, noDebugData) =
ignore (writeBinaryAndReportMappings (outfile, args.ilg, args.pdbfile, args.signer, args.portablePDB, args.embeddedPDB,
args.embedAllSource, args.embedSourceList, args.fixupOverlappingSequencePoints,
args.embedAllSource, args.embedSourceList, args.sourceLink, args.fixupOverlappingSequencePoints,
args.emitTailcalls, args.showTimes, args.dumpDebugInfo) modul noDebugData)
1 change: 1 addition & 0 deletions src/absil/ilwrite.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type options =
embeddedPDB: bool
embedAllSource: bool
embedSourceList: string list
sourceLink: string
signer : ILStrongNameSigner option
fixupOverlappingSequencePoints : bool
emitTailcalls: bool
Expand Down
25 changes: 18 additions & 7 deletions src/absil/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ let fixupOverlappingSequencePoints fixupSPs showTimes methods =
Array.sortInPlaceBy fst allSps
spCounts, allSps

let generatePortablePdb fixupSPs (embedAllSource:bool) (embedSourceList:string list) showTimes (info:PdbData) =
let generatePortablePdb fixupSPs (embedAllSource:bool) (embedSourceList:string list) (sourceLink:string) showTimes (info:PdbData) =
sortMethods showTimes info
let _spCounts, _allSps = fixupOverlappingSequencePoints fixupSPs showTimes info.Methods
let externalRowCounts = getRowCounts info.TableRowCounts
Expand All @@ -277,8 +277,9 @@ let generatePortablePdb fixupSPs (embedAllSource:bool) (embedSourceList:string l

metadata.GetOrAddBlob(writer)

let corSymLanguageTypeFSharp = System.Guid(0xAB4F38C9u, 0xB6E6us, 0x43baus, 0xBEuy, 0x3Buy, 0x58uy, 0x08uy, 0x0Buy, 0x2Cuy, 0xCCuy, 0xE3uy)
let embeddedSource = System.Guid(0x0e8a571bu, 0x6926us, 0x466eus, 0xb4uy, 0xaduy, 0x8auy, 0xb0uy, 0x46uy, 0x11uy, 0xf5uy, 0xfeuy)
let corSymLanguageTypeId = System.Guid(0xAB4F38C9u, 0xB6E6us, 0x43baus, 0xBEuy, 0x3Buy, 0x58uy, 0x08uy, 0x0Buy, 0x2Cuy, 0xCCuy, 0xE3uy)
let embeddedSourceId = System.Guid(0x0e8a571bu, 0x6926us, 0x466eus, 0xb4uy, 0xaduy, 0x8auy, 0xb0uy, 0x46uy, 0x11uy, 0xf5uy, 0xfeuy)
let sourceLinkId = System.Guid(0xcc110556u, 0xa091us, 0x4d38us, 0x9fuy, 0xecuy, 0x25uy, 0xabuy, 0x9auy, 0x35uy, 0x1auy, 0x6auy)

/// <summary>
/// The maximum number of bytes in to write out uncompressed.
Expand Down Expand Up @@ -317,7 +318,8 @@ let generatePortablePdb fixupSPs (embedAllSource:bool) (embedSourceList:string l
Some (builder.ToImmutableArray())

let mutable index = new Dictionary<string, DocumentHandle>(docs.Length)
metadata.SetCapacity(TableIndex.Document, docs.Length)
let docLength = docs.Length + if String.IsNullOrEmpty(sourceLink) then 1 else 0
metadata.SetCapacity(TableIndex.Document, docLength)
for doc in docs do
let handle =
match checkSum doc.File with
Expand All @@ -326,22 +328,31 @@ let generatePortablePdb fixupSPs (embedAllSource:bool) (embedSourceList:string l
(serializeDocumentName doc.File,
metadata.GetOrAddGuid(hashAlg),
metadata.GetOrAddBlob(checkSum.ToImmutableArray()),
metadata.GetOrAddGuid(corSymLanguageTypeFSharp)) |> metadata.AddDocument
metadata.GetOrAddGuid(corSymLanguageTypeId)) |> metadata.AddDocument
match includeSource doc.File with
| None -> ()
| Some blob ->
metadata.AddCustomDebugInformation(DocumentHandle.op_Implicit(dbgInfo),
metadata.GetOrAddGuid(embeddedSource),
metadata.GetOrAddGuid(embeddedSourceId),
metadata.GetOrAddBlob(blob)) |> ignore
dbgInfo
| None ->
let dbgInfo =
(serializeDocumentName doc.File,
metadata.GetOrAddGuid(System.Guid.Empty),
metadata.GetOrAddBlob(ImmutableArray<byte>.Empty),
metadata.GetOrAddGuid(corSymLanguageTypeFSharp)) |> metadata.AddDocument
metadata.GetOrAddGuid(corSymLanguageTypeId)) |> metadata.AddDocument
dbgInfo
index.Add(doc.File, handle)

if not (String.IsNullOrEmpty(sourceLink)) then
let fs = File.OpenRead(sourceLink)
let ms = new MemoryStream()
fs.CopyTo(ms)
metadata.AddCustomDebugInformation(
ModuleDefinitionHandle.op_Implicit(EntityHandle.ModuleDefinition),
metadata.GetOrAddGuid(sourceLinkId),
metadata.GetOrAddBlob(ms.ToArray())) |> ignore
index

let mutable lastLocalVariableHandle = Unchecked.defaultof<LocalVariableHandle>
Expand Down
2 changes: 1 addition & 1 deletion src/absil/ilwritepdb.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type idd =
iddData: byte[];
iddChunk: BinaryChunk }

val generatePortablePdb : fixupSPs:bool -> embedAllSource:bool -> embedSourceList:string list -> showTimes:bool -> info:PdbData -> struct (int64 * BlobContentId * MemoryStream)
val generatePortablePdb : fixupSPs:bool -> embedAllSource:bool -> embedSourceList:string list -> sourceLink: string -> showTimes:bool -> info:PdbData -> struct (int64 * BlobContentId * MemoryStream)
val compressPortablePdbStream : uncompressedLength:int64 -> contentId:BlobContentId -> stream:MemoryStream -> struct (int64 * BlobContentId * MemoryStream)
val embedPortablePdbInfo : uncompressedLength:int64 -> contentId:BlobContentId -> stream:MemoryStream -> showTimes:bool -> fpdb:string -> cvChunk:BinaryChunk -> pdbChunk:BinaryChunk -> idd[]
val writePortablePdbInfo : contentId:BlobContentId -> stream:MemoryStream -> showTimes:bool -> fpdb:string -> cvChunk:BinaryChunk -> idd[]
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ type TcConfigBuilder =
mutable embeddedPDB : bool
mutable embedAllSource : bool
mutable embedSourceList : string list
mutable sourceLink : string

mutable ignoreSymbolStoreSequencePoints : bool
mutable internConstantStrings : bool
Expand Down Expand Up @@ -2243,6 +2244,7 @@ type TcConfigBuilder =
embeddedPDB = false
embedAllSource = false
embedSourceList = []
sourceLink = ""
ignoreSymbolStoreSequencePoints = false
internConstantStrings = true
extraOptimizationIterations = 0
Expand Down Expand Up @@ -2732,6 +2734,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
member x.embeddedPDB = data.embeddedPDB
member x.embedAllSource = data.embedAllSource
member x.embedSourceList = data.embedSourceList
member x.sourceLink = data.sourceLink
member x.ignoreSymbolStoreSequencePoints = data.ignoreSymbolStoreSequencePoints
member x.internConstantStrings = data.internConstantStrings
member x.extraOptimizationIterations = data.extraOptimizationIterations
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/CompileOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ type TcConfigBuilder =
mutable embeddedPDB : bool
mutable embedAllSource : bool
mutable embedSourceList : string list
mutable sourceLink : string
mutable ignoreSymbolStoreSequencePoints : bool
mutable internConstantStrings : bool
mutable extraOptimizationIterations : int
Expand Down Expand Up @@ -458,6 +459,7 @@ type TcConfig =
member embeddedPDB : bool
member embedAllSource : bool
member embedSourceList : string list
member sourceLink : string
member ignoreSymbolStoreSequencePoints : bool
member internConstantStrings : bool
member extraOptimizationIterations : int
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/CompileOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ let PrintOptionInfo (tcConfigB:TcConfigBuilder) =
printfn " embeddedPDB. . . . . . : %+A" tcConfigB.embeddedPDB
printfn " embedAllSource . . . . : %+A" tcConfigB.embedAllSource
printfn " embedSourceList. . . . : %+A" tcConfigB.embedSourceList
printfn " sourceLink . . . . . . : %+A" tcConfigB.sourceLink
printfn " debuginfo . . . . . . : %+A" tcConfigB.debuginfo
printfn " resolutionEnvironment : %+A" tcConfigB.resolutionEnvironment
printfn " product . . . . . . . : %+A" tcConfigB.productNameForBannerText
Expand Down Expand Up @@ -672,6 +673,8 @@ let codeGenerationFlags isFsi (tcConfigB : TcConfigBuilder) =
Some (FSComp.SR.optsEmbedAllSource()))
CompilerOption("embed", tagFileList, OptionStringList (fun f -> tcConfigB.AddEmbeddedSourceFile f), None,
Some ( FSComp.SR.optsEmbedSource()));
CompilerOption("sourcelink", tagFile, OptionString (fun f -> tcConfigB.sourceLink <- f), None,
Some ( FSComp.SR.optsSourceLink()));
]
let codegen =
[CompilerOption("optimize", tagNone, OptionSwitch (SetOptimizeSwitch tcConfigB) , None,
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,10 @@ optsWin32manifest,"Specify a Win32 manifest file"
optsNowin32manifest,"Do not include the default Win32 manifest"
optsEmbedAllSource,"Embed all source files in the portable PDB file"
optsEmbedSource,"Embed specific source files in the portable PDB file"
optsSourceLink,"Source link information file to embed in the portable PDB file"
1501,optsEmbeddedSourceRequirePortablePDBs,"--embed switch only supported when emitting a Portable PDB (--debug:portable or --debug:embedded)"
1502,optsSourceLinkRequirePortablePDBs,"--sourcelink switch only supported when emitting a Portable PDB (--debug:portable or --debug:embedded)"
srcFileTooLarge,"Source file is too large to embed in a portable PDB"
optsResource,"Embed the specified managed resource"
optsLinkresource,"Link the specified resource to this assembly where the resinfo format is <file>[,<string name>[,public|private]]"
optsDebugPM,"Emit debug information (Short form: -g)"
Expand Down
2 changes: 0 additions & 2 deletions src/fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>$(DefineConstants);DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>3</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down
9 changes: 7 additions & 2 deletions src/fsharp/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ let ProcessCommandLineFlags (tcConfigB: TcConfigBuilder,setProcessThreadLocals,a

// This is where flags are interpreted by the command line fsc.exe.
ParseCompilerOptions (collect, GetCoreFscCompilerOptions tcConfigB, List.tail (PostProcessCompilerArgs abbrevArgs argv))
if (tcConfigB.embedAllSource || tcConfigB.embedSourceList |> List.length <> 0) && (not (tcConfigB.portablePDB || tcConfigB.embeddedPDB)) then
error(Error(FSComp.SR.optsEmbeddedSourceRequirePortablePDBs(),rangeCmdArgs))

if not (tcConfigB.portablePDB || tcConfigB.embeddedPDB) then
if tcConfigB.embedAllSource || (tcConfigB.embedSourceList |> List.length <> 0) then
error(Error(FSComp.SR.optsEmbeddedSourceRequirePortablePDBs(), rangeCmdArgs))
if not (String.IsNullOrEmpty(tcConfigB.sourceLink)) then
error(Error(FSComp.SR.optsSourceLinkRequirePortablePDBs(),rangeCmdArgs))

let inputFiles = List.rev !inputFilesRef

Expand Down Expand Up @@ -1749,6 +1753,7 @@ module FileWriter =
embeddedPDB = tcConfig.embeddedPDB
embedAllSource = tcConfig.embedAllSource
embedSourceList = tcConfig.embedSourceList
sourceLink = tcConfig.sourceLink
signer = GetSigner signingInfo
fixupOverlappingSequencePoints = false
dumpDebugInfo = tcConfig.dumpDebugInfo },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Copyright (c) Microsoft Corporation. All Rights Reserved.
--embed[+|-] Embed all source files in the portable PDB file
--embed:<file;...> Embed specific source files in the portable PDB
file
--sourcelink:<file> Source link information file to embed in the
portable PDB file
--optimize[+|-] Enable optimizations (Short form: -O)
--tailcalls[+|-] Enable or disable tailcalls
--crossoptimize[+|-] Enable or disable cross-module optimizations
Expand Down
4 changes: 4 additions & 0 deletions tests/fsharpqa/Source/CompilerOptions/fsc/pdb/pdb06.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// #Regression #NoMT #CompilerOptions #NoMono
//<Expects id="FS1502" status="error">.+sourcelink switch only supported when emitting a Portable PDB .+</Expects>

exit 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"documents": { "/*" : "ffffffffffffffffffffffffffffffffffffffff/*" }}