Simplify target path discovery
This commit is contained in:
parent
28ae18b480
commit
678deb8fd9
1 changed files with 12 additions and 42 deletions
|
|
@ -2,7 +2,6 @@ open System
|
||||||
open System.IO
|
open System.IO
|
||||||
open System.Reflection
|
open System.Reflection
|
||||||
open System.Diagnostics
|
open System.Diagnostics
|
||||||
open System.Xml.Linq
|
|
||||||
|
|
||||||
type MutationCase =
|
type MutationCase =
|
||||||
{ Id: string
|
{ Id: string
|
||||||
|
|
@ -31,10 +30,7 @@ type Options =
|
||||||
|
|
||||||
type ProjectInfo =
|
type ProjectInfo =
|
||||||
{ RelativeProjectPath: string
|
{ RelativeProjectPath: string
|
||||||
AbsoluteProjectPath: string
|
AbsoluteProjectPath: string }
|
||||||
ProjectDirectory: string
|
|
||||||
AssemblyName: string
|
|
||||||
TargetFramework: string }
|
|
||||||
|
|
||||||
let fail message =
|
let fail message =
|
||||||
eprintfn "%s" message
|
eprintfn "%s" message
|
||||||
|
|
@ -80,9 +76,6 @@ let repoRoot =
|
||||||
if exitCode <> 0 then fail stderr
|
if exitCode <> 0 then fail stderr
|
||||||
stdout.Trim()
|
stdout.Trim()
|
||||||
|
|
||||||
let makeRelativePath (path: string) =
|
|
||||||
if Path.IsPathRooted path then Path.GetRelativePath(repoRoot, path) else path
|
|
||||||
|
|
||||||
let parseArgs (args: string list) =
|
let parseArgs (args: string list) =
|
||||||
let rec loop configuration projectPath noBuild remaining =
|
let rec loop configuration projectPath noBuild remaining =
|
||||||
match remaining with
|
match remaining with
|
||||||
|
|
@ -114,47 +107,24 @@ let loadProjectInfo (projectPath: string) =
|
||||||
fail $"Project file not found: {absoluteProjectPath}"
|
fail $"Project file not found: {absoluteProjectPath}"
|
||||||
|
|
||||||
let relativeProjectPath = ensureWithinRepo absoluteProjectPath
|
let relativeProjectPath = ensureWithinRepo absoluteProjectPath
|
||||||
let projectDirectory = Path.GetDirectoryName relativeProjectPath
|
|
||||||
let document = XDocument.Load absoluteProjectPath
|
|
||||||
|
|
||||||
let tryGetProperty name =
|
|
||||||
document.Descendants()
|
|
||||||
|> Seq.tryPick (fun element ->
|
|
||||||
if element.Name.LocalName = name then
|
|
||||||
let value = element.Value.Trim()
|
|
||||||
if String.IsNullOrWhiteSpace value then None else Some value
|
|
||||||
else
|
|
||||||
None)
|
|
||||||
|
|
||||||
let targetFramework =
|
|
||||||
match tryGetProperty "TargetFramework" with
|
|
||||||
| Some value -> value
|
|
||||||
| None ->
|
|
||||||
match tryGetProperty "TargetFrameworks" with
|
|
||||||
| Some value ->
|
|
||||||
value.Split(';', StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
|> Array.tryHead
|
|
||||||
|> Option.map _.Trim()
|
|
||||||
|> Option.defaultWith (fun () -> fail $"Could not determine TargetFramework from {relativeProjectPath}")
|
|
||||||
| None -> fail $"Could not determine TargetFramework from {relativeProjectPath}"
|
|
||||||
|
|
||||||
let assemblyName =
|
|
||||||
tryGetProperty "AssemblyName"
|
|
||||||
|> Option.defaultValue (Path.GetFileNameWithoutExtension absoluteProjectPath)
|
|
||||||
|
|
||||||
{ RelativeProjectPath = relativeProjectPath
|
{ RelativeProjectPath = relativeProjectPath
|
||||||
AbsoluteProjectPath = absoluteProjectPath
|
AbsoluteProjectPath = absoluteProjectPath }
|
||||||
ProjectDirectory = projectDirectory
|
|
||||||
AssemblyName = assemblyName
|
|
||||||
TargetFramework = targetFramework }
|
|
||||||
|
|
||||||
let project =
|
let project =
|
||||||
match options.ProjectPath with
|
match options.ProjectPath with
|
||||||
| Some projectPath -> loadProjectInfo projectPath
|
| Some projectPath -> loadProjectInfo projectPath
|
||||||
| None -> fail "Missing required --project <path/to/project.fsproj>."
|
| None -> fail "Missing required --project <path/to/project.fsproj>."
|
||||||
|
|
||||||
let assemblyPath =
|
let targetPathForProject (workingDirectory: string) (projectPath: string) =
|
||||||
Path.Combine(repoRoot, project.ProjectDirectory, "bin", options.Configuration, project.TargetFramework, project.AssemblyName + ".dll")
|
let exitCode, stdout, stderr =
|
||||||
|
captureProcess workingDirectory "dotnet" [ "msbuild"; projectPath; "--getProperty:TargetPath"; $"-property:Configuration={options.Configuration}" ]
|
||||||
|
if exitCode <> 0 then fail stderr
|
||||||
|
let targetPath = stdout.Trim()
|
||||||
|
if String.IsNullOrWhiteSpace targetPath then
|
||||||
|
fail $"MSBuild did not return a TargetPath for {projectPath}."
|
||||||
|
targetPath
|
||||||
|
|
||||||
|
let assemblyPath = targetPathForProject repoRoot project.AbsoluteProjectPath
|
||||||
|
|
||||||
let ensureBuilt () =
|
let ensureBuilt () =
|
||||||
if not options.NoBuild then
|
if not options.NoBuild then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue