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

Implement support for specifying per-template versions in paket pack #1314

Merged
merged 3 commits into from
Dec 19, 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: 6 additions & 8 deletions src/Paket.Core/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let private merge buildConfig buildPlatform versionFromAssembly projectFile temp
let withVersion =
match versionFromAssembly with
| None -> templateFile
| Some v -> templateFile |> TemplateFile.setVersion v
| Some v -> templateFile |> TemplateFile.setVersion (Some v) Map.empty

match withVersion with
| { Contents = ProjectInfo(md, opt) } ->
Expand Down Expand Up @@ -81,7 +81,7 @@ let private convertToSymbols (projectFile : ProjectFile) templateFile =
let augmentedFiles = optional.Files |> List.append sourceFiles
{ templateFile with Contents = ProjectInfo({ core with Symbols = true }, { optional with Files = augmentedFiles }) }

let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols) =
let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols) =
let buildConfig = defaultArg buildConfig "Release"
let buildPlatform = defaultArg buildPlatform ""
let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath)
Expand All @@ -92,6 +92,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
LockFile.LoadFrom(lockFileName.FullName)

let version = version |> Option.map SemVer.Parse
let specificVersions = specificVersions |> Seq.map (fun (id : string,v) -> id, SemVer.Parse v) |> Map.ofSeq

let allTemplateFiles =
let hashSet = new HashSet<_>()
Expand All @@ -114,7 +115,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
|> Array.choose (fun projectFile ->
match ProjectFile.FindTemplatesFile(FileInfo(projectFile.FileName)) with
| None -> None
| Some fileName -> Some(projectFile,TemplateFile.Load(fileName,lockFile,version)))
| Some fileName -> Some(projectFile,TemplateFile.Load(fileName,lockFile,version,specificVersions)))
|> Array.filter (fun (_,templateFile) ->
match templateFile with
| CompleteTemplate _ -> false
Expand All @@ -132,7 +133,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
seq { yield templateFile; if symbols then yield templateFile |> convertToSymbols projectFile }

let convertRemainingTemplate fileName =
let templateFile = TemplateFile.Load(fileName,lockFile,version)
let templateFile = TemplateFile.Load(fileName,lockFile,version,specificVersions)
match templateFile with
| { Contents = ProjectInfo(_) } ->
let fi = FileInfo(fileName)
Expand Down Expand Up @@ -161,10 +162,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
allTemplates |> List.filter (fun t -> match t with CompleteTemplate(c,_) -> not (excluded.Contains c.Id) | _ -> true)

// set version
let templatesWithVersion =
match version with
| None -> excludedTemplates
| Some v -> excludedTemplates |> List.map (TemplateFile.setVersion v)
let templatesWithVersion = excludedTemplates |> List.map (TemplateFile.setVersion version specificVersions)

// set release notes
let processedTemplates =
Expand Down
7 changes: 4 additions & 3 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,13 @@ type Dependencies(dependenciesFileName: string) =
FindReferences.FindReferencesForPackage (GroupName group) (PackageName package) |> this.Process

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

/// Pushes a nupkg file.
static member Push(packageFileName, ?url, ?apiKey, (?endPoint: string), ?maxTrials) =
Expand All @@ -479,7 +480,7 @@ type Dependencies(dependenciesFileName: string) =
|> Array.choose (fun proj -> ProjectFile.FindTemplatesFile(FileInfo(proj.FileName)))
|> Array.choose (fun path ->
try
Some(TemplateFile.Load(path, lockFile, None))
Some(TemplateFile.Load(path, lockFile, None, Map.empty))
with
| _ -> None)
|> Array.toList
69 changes: 45 additions & 24 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,25 @@ type TemplateFile =
module internal TemplateFile =
open Logging

let setVersion version templateFile =
let contents =
match templateFile.Contents with
| CompleteInfo(core, optional) -> CompleteInfo({ core with Version = Some version }, optional)
| ProjectInfo(core, optional) -> ProjectInfo({ core with Version = Some version }, optional)
{ templateFile with Contents = contents }
let tryGetId (templateFile : TemplateFile) =
match templateFile.Contents with
| CompleteInfo(core,_) -> Some(core.Id)
| ProjectInfo(core,_) -> core.Id

let setVersion version specificVersions templateFile =
let version =
match tryGetId templateFile |> Option.bind (fun id -> Map.tryFind id specificVersions) with
| Some _ as specificVersion -> specificVersion
| None -> version

match version with
| None -> templateFile
| Some version ->
let contents =
match templateFile.Contents with
| CompleteInfo(core, optional) -> CompleteInfo({ core with Version = Some version }, optional)
| ProjectInfo(core, optional) -> ProjectInfo({ core with Version = Some version }, optional)
{ templateFile with Contents = contents }

let setReleaseNotes releaseNotes templateFile =
let contents =
Expand Down Expand Up @@ -219,7 +232,7 @@ module internal TemplateFile =
| Some m -> ok m
| None -> failP file "No description line in paket.template file."

let private getDependencies (fileName, lockFile:LockFile, info : Map<string, string>,currentVersion:SemVerInfo option) =
let private getDependencies (fileName, lockFile:LockFile, info : Map<string, string>,currentVersion:SemVerInfo option, specificVersions:Map<string, SemVerInfo>) =
Map.tryFind "dependencies" info
|> Option.map (fun d -> d.Split '\n')
|> Option.map (Array.map (fun d ->
Expand All @@ -229,9 +242,13 @@ module internal TemplateFile =
let versionString =
let s = reg.Groups.["version"].Value.Trim()
if s.Contains("CURRENTVERSION") then
match currentVersion with
| Some v -> s.Replace("CURRENTVERSION",v.ToString())
| None -> failwithf "The template file %s contains the placeholder CURRENTVERSION, but no version was given." fileName
match specificVersions.TryFind (string id') with
| Some v -> s.Replace("CURRENTVERSION", v.ToString())
| None ->
match currentVersion with
| Some v -> s.Replace("CURRENTVERSION",v.ToString())
| None -> failwithf "The template file %s contains the placeholder CURRENTVERSION, but no version was given." fileName

elif s.Contains("LOCKEDVERSION") then
match lockFile.Groups.[Constants.MainDependencyGroup].Resolution |> Map.tryFind id' with
| Some p -> s.Replace("LOCKEDVERSION",p.Version.ToString())
Expand Down Expand Up @@ -296,7 +313,7 @@ module internal TemplateFile =
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

let private getOptionalInfo (fileName,lockFile:LockFile, map : Map<string, string>, currentVersion) =
let private getOptionalInfo (fileName,lockFile:LockFile, map : Map<string, string>, currentVersion, specificVersions) =
let get (n : string) = Map.tryFind (n.ToLowerInvariant()) map

let title = get "title"
Expand Down Expand Up @@ -334,7 +351,7 @@ module internal TemplateFile =
| Some x when x.ToLower() = "true" -> true
| _ -> false

let dependencies = getDependencies(fileName,lockFile,map,currentVersion)
let dependencies = getDependencies(fileName,lockFile,map,currentVersion,specificVersions)
let excludedDependencies = getExcludedDependencies(fileName,lockFile,map,currentVersion)

{ Title = title
Expand All @@ -356,7 +373,7 @@ module internal TemplateFile =
Files = getFiles map
FilesExcluded = getFileExcludes map }

let Parse(file,lockFile,currentVersion,contentStream : Stream) =
let Parse(file,lockFile,currentVersion,specificVersions,contentStream : Stream) =
trial {
use sr = new StreamReader(contentStream)
let! map =
Expand All @@ -366,16 +383,20 @@ module internal TemplateFile =
sr.Dispose()
let! type' = parsePackageConfigType file map

let currentVersion =
match currentVersion with
| None -> Map.tryFind "version" map |> Option.map SemVer.Parse
| _ -> currentVersion
let resolveCurrentVersion id =
match id |> Option.bind (fun id -> Map.tryFind id specificVersions) with
| Some _ as specificVersion -> specificVersion
| None ->
match currentVersion with
| None -> Map.tryFind "version" map |> Option.map SemVer.Parse
| _ -> currentVersion

match type' with
| ProjectType ->
let id = Map.tryFind "id" map
let core : ProjectCoreInfo =
{ Id = Map.tryFind "id" map
Version = Map.tryFind "version" map |> Option.map SemVer.Parse
{ Id = id
Version = resolveCurrentVersion id
Authors =
Map.tryFind "authors" map
|> Option.map (fun s ->
Expand All @@ -385,27 +406,27 @@ module internal TemplateFile =
Description = Map.tryFind "description" map
Symbols = false }

let optionalInfo = getOptionalInfo(file,lockFile,map,currentVersion)
let optionalInfo = getOptionalInfo(file,lockFile,map,currentVersion,specificVersions)
return ProjectInfo(core, optionalInfo)
| FileType ->
let! id' = getId file map
let! authors = getAuthors file map
let! description = getDescription file map
let core : CompleteCoreInfo =
{ Id = id'
Version = Map.tryFind "version" map |> Option.map SemVer.Parse
Version = resolveCurrentVersion (Some id')
Authors = authors
Description = description
Symbols = false }

let optionalInfo = getOptionalInfo(file,lockFile,map,currentVersion)
let optionalInfo = getOptionalInfo(file,lockFile,map,currentVersion,specificVersions)
return CompleteInfo(core, optionalInfo)
}

let Load(fileName,lockFile,currentVersion) =
let Load(fileName,lockFile,currentVersion,specificVersions) =
let fi = FileInfo fileName
let root = fi.Directory.FullName
let contents = Parse(fi.FullName,lockFile,currentVersion, File.OpenRead fileName) |> returnOrFail
let contents = Parse(fi.FullName,lockFile,currentVersion,specificVersions, File.OpenRead fileName) |> returnOrFail
let getFiles files =
[ for source, target in files do
match Fake.Globbing.search root source with
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type PackArgs =
| [<CustomCommandLine("version")>] Version of string
| [<CustomCommandLine("templatefile")>] TemplateFile of string
| [<CustomCommandLine("exclude")>] ExcludedTemplate of string
| [<CustomCommandLine("specific-version")>] SpecificVersion of templateId:string * version:string
| [<CustomCommandLine("releaseNotes")>] ReleaseNotes of string
| [<CustomCommandLine("lock-dependencies")>] LockDependencies
| [<CustomCommandLine("symbols")>] Symbols
Expand All @@ -309,6 +310,7 @@ with
| Version(_) -> "Specify version of the package."
| TemplateFile(_) -> "Allows to specify a single template file."
| ExcludedTemplate(_) -> "Exclude template file by id."
| SpecificVersion(_) -> "Specifies a version number for template with given id."
| ReleaseNotes(_) -> "Specify relase notes for the package."
| LockDependencies -> "Get the version requirements from paket.lock instead of paket.dependencies."
| Symbols -> "Build symbol/source packages in addition to library/content packages."
Expand Down
1 change: 1 addition & 0 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ let pack (results : ParseResults<_>) =
?buildConfig = results.TryGetResult <@ PackArgs.BuildConfig @>,
?buildPlatform = results.TryGetResult <@ PackArgs.BuildPlatform @>,
?version = results.TryGetResult <@ PackArgs.Version @>,
specificVersions = results.GetResults <@ PackArgs.SpecificVersion @>,
?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>,
?templateFile = results.TryGetResult <@ PackArgs.TemplateFile @>,
excludedTemplates = results.GetResults <@ PackArgs.ExcludedTemplate @>,
Expand Down
Loading