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

Fix .net sdk 5.0.200 and up cracking error #100

Merged
merged 2 commits into from
Mar 3, 2021
Merged
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.47.0] - 2021-02-10
## [0.49.0] - 2021-03-03

### Changed

- Added debouncing of project-cracking to prevent rework
- Changed the target of the build from "CoreCompile" to "Build" to bring in SDK props

## [0.48.0] - 2021-02-10

### Changed

- Updated to FCS 39.0.0

## [0.46.0] - 2021-01-11

### Added
Expand Down
7 changes: 4 additions & 3 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ let exec cmd args dir =
CreateProcess.fromRawCommandLine cmd args
|> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args)

(if isNullOrWhiteSpace dir
then proc
else proc |> CreateProcess.withWorkingDirectory dir)
(if isNullOrWhiteSpace dir then
proc
else
proc |> CreateProcess.withWorkingDirectory dir)
|> Proc.run
|> ignore

Expand Down
13 changes: 9 additions & 4 deletions src/Ionide.ProjInfo/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ module ProjectLoader =
if path.EndsWith ".csproj" then
"NonExistentFile", Path.Combine("__NonExistentSubDir__", "__NonExistentFile__") ]

match System.Environment.GetEnvironmentVariable "DOTNET_HOST_PATH" with
| null
| "" -> System.Environment.SetEnvironmentVariable("DOTNET_HOST_PATH", Ionide.ProjInfo.Paths.dotnetRoot)
| _alreadySet -> ()

use pc = new ProjectCollection(globalProperties)

let pi = pc.LoadProject(path)
Expand Down Expand Up @@ -345,7 +350,7 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
member __.LoadProjects(projects: string list, customProperties: string list, generateBinlog: bool) =
let cache = Dictionary<string, ProjectOptions>()

let getAllKnonw() =
let getAllKnown () =
cache |> Seq.map (fun n -> n.Value) |> Seq.toList

let rec loadProject p =
Expand Down Expand Up @@ -375,12 +380,12 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
loadingNotification.Trigger(WorkspaceProjectState.Failed(p, GenericError(p, msg)))
[], None

let rec loadProjectList(projectList: string list) =
let rec loadProjectList (projectList: string list) =
for p in projectList do
let newList, toTrigger =
if cache.ContainsKey p then
let project = cache.[p]
loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnonw (), true)) //TODO: Should it even notify here?
loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnown (), true)) //TODO: Should it even notify here?
let lst = project.ReferencedProjects |> Seq.map (fun n -> n.ProjectFileName) |> Seq.toList
lst, None
else
Expand All @@ -391,7 +396,7 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
loadProjectList newList

toTrigger
|> Option.iter (fun project -> loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnonw (), false)))
|> Option.iter (fun project -> loadingNotification.Trigger(WorkspaceProjectState.Loaded(project, getAllKnown (), false)))

loadProjectList projects
cache |> Seq.map (fun n -> n.Value)
Expand Down
67 changes: 43 additions & 24 deletions src/Ionide.ProjInfo/Utils.fs
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
namespace Ionide.ProjInfo

module internal Paths =
/// provides the path to the `dotnet` binary running this library, duplicated from
/// https://github.com/dotnet/sdk/blob/b91b88aec2684e3d2988df8d838d3aa3c6240a35/src/Cli/Microsoft.DotNet.Cli.Utils/Muxer.cs#L39
let dotnetRoot =
System
.Diagnostics
.Process
.GetCurrentProcess()
.MainModule
.FileName
baronfel marked this conversation as resolved.
Show resolved Hide resolved

module internal CommonHelpers =

let chooseByPrefix (prefix: string) (s: string) =
if s.StartsWith(prefix)
then Some(s.Substring(prefix.Length))
else None
if s.StartsWith(prefix) then
Some(s.Substring(prefix.Length))
else
None

let chooseByPrefix2 prefixes (s: string) =
prefixes |> List.tryPick (fun prefix -> chooseByPrefix prefix s)

let splitByPrefix (prefix: string) (s: string) =
if s.StartsWith(prefix)
then Some(prefix, s.Substring(prefix.Length))
else None
if s.StartsWith(prefix) then
Some(prefix, s.Substring(prefix.Length))
else
None

let splitByPrefix2 prefixes (s: string) =
prefixes |> List.tryPick (fun prefix -> splitByPrefix prefix s)
Expand All @@ -34,9 +47,10 @@ module internal FscArguments =
let private outputFileArg = [ "--out:"; "-o:" ]

let private makeAbs (projDir: string) (f: string) =
if Path.IsPathRooted f
then f
else Path.Combine(projDir, f)
if Path.IsPathRooted f then
f
else
Path.Combine(projDir, f)

let outputFile projDir rsp =
rsp |> List.tryPick (chooseByPrefix2 outputFileArg) |> Option.map (makeAbs projDir)
Expand All @@ -53,9 +67,10 @@ module internal FscArguments =
match s |> splitByPrefix2 outputFileArg with
| Some (prefix, v) -> prefix + (v |> makeAbs projDir)
| None ->
if isCompileFile s
then s |> makeAbs projDir |> Path.GetFullPath
else s
if isCompileFile s then
s |> makeAbs projDir |> Path.GetFullPath
else
s

let isTempFile (name: string) =
let tempPath = System.IO.Path.GetTempPath()
Expand All @@ -67,9 +82,10 @@ module internal FscArguments =
(n = "--times") || (n = "--no-jit-optimize")

let isSourceFile (file: string): (string -> bool) =
if System.IO.Path.GetExtension(file) = ".fsproj"
then isCompileFile
else (fun n -> n.EndsWith ".cs")
if System.IO.Path.GetExtension(file) = ".fsproj" then
isCompileFile
else
(fun n -> n.EndsWith ".cs")

module internal CscArguments =
open CommonHelpers
Expand All @@ -79,23 +95,26 @@ module internal CscArguments =
let private outputFileArg = [ "--out:"; "-o:" ]

let private makeAbs (projDir: string) (f: string) =
if Path.IsPathRooted f
then f
else Path.Combine(projDir, f)
if Path.IsPathRooted f then
f
else
Path.Combine(projDir, f)

let isCompileFile (s: string) =
let isArg = s.StartsWith("-") && s.Contains(":")
(not isArg) && s.EndsWith(".cs")

let useFullPaths projDir (s: string) =
if isCompileFile s
then s |> makeAbs projDir |> Path.GetFullPath
else s
if isCompileFile s then
s |> makeAbs projDir |> Path.GetFullPath
else
s

let isSourceFile (file: string): (string -> bool) =
if System.IO.Path.GetExtension(file) = ".csproj"
then isCompileFile
else (fun n -> n.EndsWith ".fs")
if System.IO.Path.GetExtension(file) = ".csproj" then
isCompileFile
else
(fun n -> n.EndsWith ".fs")

let outputFile projDir rsp =
rsp |> List.tryPick (chooseByPrefix2 outputFileArg) |> Option.map (makeAbs projDir)
Expand Down