Skip to content

Commit

Permalink
Add useBinaryLogger to the API 🎁 (#75)
Browse files Browse the repository at this point in the history
so we can use it for debugging in FSAC
  • Loading branch information
Krzysztof-Cieslak authored May 4, 2020
1 parent 6f17116 commit 12dce58
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
22 changes: 14 additions & 8 deletions src/Dotnet.ProjInfo.Workspace/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ type Loader private (msbuildHostDotNetSdk, msbuildHostVerboseSdk) =
with get () : Dotnet.ProjInfo.Inspect.MSBuildExePath = msbuildHostDotNetSdk

member this.LoadProjects(projects: string list) =
this.LoadProjects(projects, CrosstargetingStrategies.preferDotnetCore)
this.LoadProjects(projects, CrosstargetingStrategies.preferDotnetCore, false)

member this.LoadProjects(projects: string list, crosstargetingStrategy: CrosstargetingStrategy) =
member this.LoadProjects(projects: string list, useBinaryLogger: bool) =
this.LoadProjects(projects, CrosstargetingStrategies.preferDotnetCore, useBinaryLogger)

member this.LoadProjects(projects: string list, crosstargetingStrategy: CrosstargetingStrategy, useBinaryLogger: bool ) =

let cache = ProjectCrackerDotnetSdk.ParsedProjectCache()

let notify arg =
event1.Trigger(this, arg)

Expand All @@ -84,9 +87,9 @@ type Loader private (msbuildHostDotNetSdk, msbuildHostVerboseSdk) =
if File.Exists project then
match kindOfProjectSdk project with
| Some ProjectSdkKind.DotNetSdk ->
ProjectCrackerDotnetSdk.load crosstargetingStrategy this.MSBuildHostDotNetSdk
ProjectCrackerDotnetSdk.load crosstargetingStrategy this.MSBuildHostDotNetSdk useBinaryLogger
| Some ProjectSdkKind.VerboseSdk ->
ProjectCrackerDotnetSdk.loadVerboseSdk crosstargetingStrategy this.MSBuildHostVerboseSdk
ProjectCrackerDotnetSdk.loadVerboseSdk crosstargetingStrategy this.MSBuildHostVerboseSdk useBinaryLogger
| Some ProjectSdkKind.ProjectJson | None ->
failwithf "unsupported project %s" project
else
Expand Down Expand Up @@ -118,15 +121,18 @@ type Loader private (msbuildHostDotNetSdk, msbuildHostVerboseSdk) =
notify failed

member this.LoadSln(slnPath: string) =
this.LoadSln(slnPath, CrosstargetingStrategies.preferDotnetCore)
this.LoadSln(slnPath, CrosstargetingStrategies.preferDotnetCore, false)

member this.LoadSln(slnPath: string, useBinaryLogger: bool) =
this.LoadSln(slnPath, CrosstargetingStrategies.preferDotnetCore, useBinaryLogger)

member this.LoadSln(slnPath: string, crosstargetingStrategy: CrosstargetingStrategy) =
member this.LoadSln(slnPath: string, crosstargetingStrategy: CrosstargetingStrategy, useBinaryLogger: bool) =

match InspectSln.tryParseSln slnPath with
| Choice1Of2 (_, slnData) ->
let projs = InspectSln.loadingBuildOrder slnData

this.LoadProjects(projs, crosstargetingStrategy)
this.LoadProjects(projs, crosstargetingStrategy, useBinaryLogger)
| Choice2Of2 d ->
failwithf "cannot load the sln: %A" d

Expand Down
23 changes: 13 additions & 10 deletions src/Dotnet.ProjInfo.Workspace/ProjectCrackerDotnetSdk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module internal ProjectCrackerDotnetSdk =
type ParsedProject = string * ProjectOptions * ((string * string) list) * (ProjectOptions list)
type ParsedProjectCache = Collections.Concurrent.ConcurrentDictionary<string, ParsedProject>

let private execProjInfoFromMsbuild msbuildPath notifyState parseAsSdk additionalMSBuildProps (file: string) =
let private execProjInfoFromMsbuild msbuildPath notifyState (useBinaryLogger: bool) parseAsSdk additionalMSBuildProps (file: string) =

let projDir = Path.GetDirectoryName file

Expand Down Expand Up @@ -121,9 +121,12 @@ module internal ProjectCrackerDotnetSdk =
let additionalArgs = additionalMSBuildProps |> List.map (Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Property)

let globalArgs =
match Environment.GetEnvironmentVariable("DOTNET_PROJ_INFO_MSBUILD_BL") with
| "1" -> Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Switch("bl") :: []
| _ -> []
if useBinaryLogger then
[ Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Switch("bl") ]
else
match Environment.GetEnvironmentVariable("DOTNET_PROJ_INFO_MSBUILD_BL") with
| "1" -> [ Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Switch("bl") ]
| _ -> []

let infoResult =
getProjectInfos loggedMessages.Enqueue msbuildExec [getFscArgs; getP2PRefs; gp; getItems] (additionalArgs @ globalArgs) file
Expand Down Expand Up @@ -335,20 +338,20 @@ module internal ProjectCrackerDotnetSdk =
let _, po, log, additionalProjs = projInfoCached (projInfoCrossTargeting crosstargetingChooser projInfoFromMsbuild projInfoCached parseAsSdk) [] rootProjFile
(po, log, additionalProjs)

let private loadBySdk crosstargetingStrategy msbuildPath notifyState (cache: ParsedProjectCache) parseAsSdk file =
let private loadBySdk crosstargetingStrategy msbuildPath notifyState (cache: ParsedProjectCache) parseAsSdk (useBinaryLogger: bool) file =
try
let po, log, additionalProjs = getProjectOptionsFromProjectFile crosstargetingStrategy (execProjInfoFromMsbuild msbuildPath notifyState) (asProjInfoCached cache) parseAsSdk file
let po, log, additionalProjs = getProjectOptionsFromProjectFile crosstargetingStrategy (execProjInfoFromMsbuild msbuildPath notifyState useBinaryLogger) (asProjInfoCached cache) parseAsSdk file

Ok (po, (log |> Map.ofList), additionalProjs)
with
| ProjectInspectException d -> Error d
| e -> Error (GenericError(file, e.Message))

let load crosstargetingStrategy msbuildPath notifyState (cache: ParsedProjectCache) file =
loadBySdk crosstargetingStrategy msbuildPath notifyState cache ProjectParsingSdk.DotnetSdk file
let load crosstargetingStrategy msbuildPath (useBinaryLogger: bool) notifyState (cache: ParsedProjectCache) file =
loadBySdk crosstargetingStrategy msbuildPath notifyState cache ProjectParsingSdk.DotnetSdk useBinaryLogger file

let loadVerboseSdk crosstargetingStrategy msbuildPath notifyState (cache: ParsedProjectCache) file =
loadBySdk crosstargetingStrategy msbuildPath notifyState cache ProjectParsingSdk.VerboseSdk file
let loadVerboseSdk crosstargetingStrategy msbuildPath (useBinaryLogger: bool) notifyState (cache: ParsedProjectCache)file =
loadBySdk crosstargetingStrategy msbuildPath notifyState cache ProjectParsingSdk.VerboseSdk useBinaryLogger file

type CrosstargetingStrategy = string -> (string * string * string list) -> string

Expand Down
2 changes: 1 addition & 1 deletion test/Dotnet.ProjInfo.Workspace.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ let tests (suiteConfig: TestSuiteConfig) =
Expect.equal othersTfms [] "invalid others tfm"
secondTfm

loader.LoadProjects([projPath], strategy)
loader.LoadProjects([projPath], strategy, false)

//the additional loading is the cross targeting
[ loading "m1.fsproj"; loading "m1.fsproj"; loaded "m1.fsproj" ]
Expand Down

0 comments on commit 12dce58

Please sign in to comment.