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

Handle different platforms in ProjectFile.GetOutputPath #1269

Merged
merged 4 commits into from
Dec 1, 2015
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
14 changes: 7 additions & 7 deletions src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ let getDescription attributes =
| Description d -> Some d
| _ -> None)

let loadAssemblyId buildConfig (projectFile : ProjectFile) =
let loadAssemblyId buildConfig buildPlatform (projectFile : ProjectFile) =
let fileName =
Path.Combine
(Path.GetDirectoryName projectFile.FileName, projectFile.GetOutputDirectory buildConfig,
(Path.GetDirectoryName projectFile.FileName, projectFile.GetOutputDirectory buildConfig buildPlatform,
projectFile.GetAssemblyName()) |> normalizePath

traceVerbose <| sprintf "Loading assembly metadata for %s" fileName
Expand Down Expand Up @@ -129,8 +129,8 @@ let addDependency (templateFile : TemplateFile) (dependency : PackageName * Vers
| IncompleteTemplate ->
failwith "You should only try and add dependencies to template files with complete metadata."

let toFile config (p : ProjectFile) =
Path.Combine(Path.GetDirectoryName p.FileName, p.GetOutputDirectory(config), p.GetAssemblyName())
let toFile config platform (p : ProjectFile) =
Path.Combine(Path.GetDirectoryName p.FileName, p.GetOutputDirectory config platform, p.GetAssemblyName())

let addFile (source : string) (target : string) (templateFile : TemplateFile) =
match templateFile with
Expand All @@ -140,7 +140,7 @@ let addFile (source : string) (target : string) (templateFile : TemplateFile) =
| IncompleteTemplate ->
failwith "You should only try and add files to template files with complete metadata."

let findDependencies (dependencies : DependenciesFile) config (template : TemplateFile) (project : ProjectFile) lockDependencies (map : Map<string, TemplateFile * ProjectFile>) =
let findDependencies (dependencies : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies (map : Map<string, TemplateFile * ProjectFile>) =
let targetDir =
match project.OutputType with
| ProjectOutputType.Exe -> "tools/"
Expand All @@ -163,7 +163,7 @@ let findDependencies (dependencies : DependenciesFile) config (template : Templa

// Add the assembly + pdb + dll from this project
let templateWithOutput =
let assemblyFileName = toFile config project
let assemblyFileName = toFile config platform project
let fi = FileInfo(assemblyFileName)
let name = Path.GetFileNameWithoutExtension fi.Name

Expand Down Expand Up @@ -199,7 +199,7 @@ let findDependencies (dependencies : DependenciesFile) config (template : Templa
// If project refs will not be packaged, add the assembly to the package
let withDepsAndIncluded =
files
|> List.fold (fun templatefile file -> addFile (toFile config file) targetDir templatefile) withDeps
|> List.fold (fun templatefile file -> addFile (toFile config platform file) targetDir templatefile) withDeps

let lockFile =
dependencies.FindLockfile().FullName
Expand Down
13 changes: 7 additions & 6 deletions src/Paket.Core/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open System.Collections.Generic
open Paket.PackageMetaData
open Chessie.ErrorHandling

let private merge buildConfig version projectFile templateFile =
let private merge buildConfig buildPlatform version projectFile templateFile =
let withVersion =
match version with
| None -> templateFile
Expand All @@ -21,7 +21,7 @@ let private merge buildConfig version projectFile templateFile =
match md with
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ ->
let assembly,id,assemblyFileName = loadAssemblyId buildConfig projectFile
let assembly,id,assemblyFileName = loadAssemblyId buildConfig buildPlatform projectFile
let md = { md with Id = md.Id ++ Some id }

match md with
Expand Down Expand Up @@ -53,8 +53,9 @@ let private merge buildConfig version projectFile templateFile =
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) }
| _ -> templateFile

let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies) =
let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, releaseNotes, templateFile, lockDependencies) =
let buildConfig = defaultArg buildConfig "Release"
let buildPlatform = defaultArg buildPlatform ""
let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath)
Utils.createDir packageOutputPath |> returnOrFail

Expand Down Expand Up @@ -93,14 +94,14 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
|> Array.map (fun (projectFile,templateFile) ->
allTemplateFiles.Remove(templateFile.FileName) |> ignore

let merged = merge buildConfig version projectFile templateFile
let merged = merge buildConfig buildPlatform version projectFile templateFile
Path.GetFullPath projectFile.FileName |> normalizePath,(merged,projectFile))
|> Map.ofArray

// add dependencies
let allTemplates =
projectTemplates
|> Map.map (fun _ (t, p) -> p,findDependencies dependencies buildConfig t p lockDependencies projectTemplates)
|> Map.map (fun _ (t, p) -> p,findDependencies dependencies buildConfig buildPlatform t p lockDependencies projectTemplates)
|> Map.toList
|> List.map (fun (_,(_,x)) -> x)
|> List.append [for fileName in allTemplateFiles ->
Expand All @@ -111,7 +112,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
let allProjectFiles = ProjectFile.FindAllProjects(fi.Directory.FullName) |> Array.toList

match allProjectFiles with
| [ projectFile ] -> merge buildConfig version projectFile templateFile
| [ projectFile ] -> merge buildConfig buildPlatform version projectFile templateFile
| [] -> failwithf "There was no project file found for template file %s" fileName
| _ -> failwithf "There was more than one project file found for template file %s" fileName
| _ -> templateFile ]
Expand Down
39 changes: 33 additions & 6 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,40 @@ type ProjectFile =
then "Compile"
else "Content"

member this.GetOutputDirectory buildConfiguration =
let startingData = Map.empty<string,string>.Add("Configuration", buildConfiguration)
member this.GetOutputDirectory buildConfiguration buildPlatform =
let platforms =
if not <| String.IsNullOrWhiteSpace(buildPlatform)
then [buildPlatform]
else
[
"AnyCPU";
"AnyCPU32BitPreferred";
"x86";
"x64";
"ARM";
"Itanium";
]

let rec tryNextPlat platforms attempted =
match platforms with
| [] ->
if String.IsNullOrWhiteSpace(buildPlatform)
then
failwithf "Unable to find %s output path node in file %s for any known platforms" buildConfiguration this.FileName
else
failwithf "Unable to find %s output path node in file %s targeting the %s platform" buildConfiguration this.FileName buildPlatform
| x::xs ->
let startingData = Map.ofList [("Configuration", buildConfiguration); ("Platform", x)]
this.GetPropertyWithDefaults "OutputPath" startingData
|> function
| None -> tryNextPlat xs (x::attempted)
| Some s ->
if String.IsNullOrWhiteSpace(buildPlatform) then
let tested = String.Join(", ", Array.ofList attempted)
traceWarnfn "No platform specified; found output path node for the %s platform after failing to find one for the following: %s" x tested
s.TrimEnd [|'\\'|] |> normalizePath

this.GetPropertyWithDefaults "OutputPath" startingData
|> function
| None -> failwithf "Unable to find %s output path node in file %s" buildConfiguration this.FileName
| Some s -> s.TrimEnd [|'\\'|] |> normalizePath
tryNextPlat platforms []

member this.GetAssemblyName () =
let assemblyName =
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ type Dependencies(dependenciesFileName: string) =
FindReferences.FindReferencesForPackage (GroupName group) (PackageName package) |> this.Process

// Packs all paket.template files.
member this.Pack(outputPath, ?buildConfig, ?version, ?releaseNotes, ?templateFile, ?workingDir, ?lockDependencies) =
member this.Pack(outputPath, ?buildConfig, ?buildPlatform, ?version, ?releaseNotes, ?templateFile, ?workingDir, ?lockDependencies) =
let dependenciesFile = DependenciesFile.ReadFromFile dependenciesFileName
let workingDir = defaultArg workingDir (dependenciesFile.FileName |> Path.GetDirectoryName)
let lockDependencies = defaultArg lockDependencies false
PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies)
PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, buildPlatform, version, releaseNotes, templateFile, lockDependencies)

/// Pushes a nupkg file.
static member Push(packageFileName, ?url, ?apiKey, (?endPoint: string), ?maxTrials) =
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ with
type PackArgs =
| [<CustomCommandLine("output")>][<Mandatory>] Output of string
| [<CustomCommandLine("buildconfig")>] BuildConfig of string
| [<CustomCommandLine("buildplatform")>] BuildPlatform of string
| [<CustomCommandLine("version")>] Version of string
| [<CustomCommandLine("templatefile")>] TemplateFile of string
| [<CustomCommandLine("releaseNotes")>] ReleaseNotes of string
Expand All @@ -302,6 +303,7 @@ with
match this with
| Output(_) -> "Output directory to put .nupkg files."
| BuildConfig(_) -> "Optionally specify build configuration that should be packaged (defaults to Release)."
| BuildPlatform(_) -> "Optionally specify build platform that should be packaged (if not provided or empty, checks all known platform targets)."
| Version(_) -> "Specify version of the package."
| TemplateFile(_) -> "Allows to specify a single template file."
| ReleaseNotes(_) -> "Specify relase notes for the package."
Expand Down
1 change: 1 addition & 0 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ let pack (results : ParseResults<_>) =
Dependencies.Locate()
.Pack(outputPath,
?buildConfig = results.TryGetResult <@ PackArgs.BuildConfig @>,
?buildPlatform = results.TryGetResult <@ PackArgs.BuildPlatform @>,
?version = results.TryGetResult <@ PackArgs.Version @>,
?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>,
?templateFile = results.TryGetResult <@ PackArgs.TemplateFile @>,
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/PackageProcessSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let ``Loading assembly metadata works``() =
if workingDir.Contains "Debug" then "Debug"
else "Release"

let assembly,id,fileName = PackageMetaData.loadAssemblyId config projFile
let assembly,id,fileName = PackageMetaData.loadAssemblyId config "" projFile
id |> shouldEqual "Paket.Tests"

let attribs = PackageMetaData.loadAssemblyAttributes fileName assembly
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/ProjectFile/OutputSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let ``should detect target framework for Project2 proj file``() =
let ``should detect output path for proj file``
([<Values("Project1", "Project2", "Project3", "ProjectWithConditions")>] project)
([<Values("Debug", "Release")>] configuration) =
ProjectFile.TryLoad(sprintf "./ProjectFile/TestData/%s.fsprojtest" project).Value.GetOutputDirectory configuration
ProjectFile.TryLoad(sprintf "./ProjectFile/TestData/%s.fsprojtest" project).Value.GetOutputDirectory configuration ""
|> shouldEqual (System.IO.Path.Combine(@"bin", configuration) |> normalizePath)

[<Test>]
Expand Down