From 2f1114719c770e0adb4d673c7c8324c09e2dcc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 16 Oct 2014 15:00:20 +0200 Subject: [PATCH 01/14] Support for multiple projects with deliverable output Allows for multiple projects in the src folder, each can be released as a nuget package Nuget packaging now automatically infers dependencies based on paket settings. --- build.template | 112 +++++++++++++++--- docs/tools/generate.template | 12 +- nuget/FSharp.ProjectTemplate.nuspec | 7 +- paket.dependencies | 3 +- .../FSharp.ProjectTemplate.fsproj | 10 +- 5 files changed, 113 insertions(+), 31 deletions(-) diff --git a/build.template b/build.template index ea96abc..dcb8da9 100644 --- a/build.template +++ b/build.template @@ -4,10 +4,14 @@ #r @"packages/FAKE/tools/NuGet.Core.dll" #r @"packages/FAKE/tools/FakeLib.dll" +#r @"packages/Paket.Core/lib/Paket.Core.dll" open Fake open Fake.Git open Fake.AssemblyInfoFile open Fake.ReleaseNotesHelper +open Paket +open Paket.PackageResolver +open Paket.Requirements open System #if MONO #else @@ -99,6 +103,16 @@ Target "AssemblyInfo" (fun _ -> csProjs |> Seq.iter genCSAssemblyInfo ) +// Copies binaries from default VS location to exepcted bin folder +// But keeps a subdirectory structure for each project in the +// src folder to support multiple project outputs +Target "CopyBinaries" (fun _ -> + directoryInfo "src" + |> subDirectories + |> Array.map (fun d -> (d.Name, sprintf "%s/Bin/Release" d.FullName)) + |> Array.iter (fun (n, p) -> CopyDir (sprintf "bin/%s" n) p (fun _ -> true)) +) + // -------------------------------------------------------------------------------------- // Clean build results @@ -156,21 +170,88 @@ Target "SourceLink" (fun _ -> // -------------------------------------------------------------------------------------- // Build a NuGet package +let getFilenames (d:IO.DirectoryInfo) = + [d.FullName @@ (sprintf "%s.dll" d.Name) + d.FullName @@ (sprintf "%s.pdb" d.Name)] + |> List.map (fun f -> (f, Some("lib/net40"), None)) + +let getAllPackages () = + let dep = (DependenciesFile.ReadFromFile (__SOURCE_DIRECTORY__ @@ "paket.dependencies")) + let lock = (LockFileParser.Parse (IO.File.ReadAllLines (__SOURCE_DIRECTORY__ @@ "paket.lock"))) + (dep.Packages, lock.Packages) + +let getReferencedPackageNamesFromProject projectRefFile = + IO.File.ReadAllLines projectRefFile + +type RangeRestriction = +| Upper +| Lower + +let getRangeRestrictionNugetDelimiter (r:RangeRestriction) (v:VersionRangeBound) = + match r, v with + | Upper, VersionRangeBound.Including -> "]" + | Upper, VersionRangeBound.Excluding -> ")" + | Lower, VersionRangeBound.Including -> "[" + | Lower, VersionRangeBound.Excluding -> "(" + +let nugetFriendlySemver (s:SemVerInfo) = + match (s.ToString()) with + | "0" -> "" + | ok -> ok + +let convertVersionRangeToNugetVersion (v:VersionRange) = + match v with + | Minimum(semver) -> semver |> nugetFriendlySemver + | GreaterThan(semver) -> sprintf "(%s,)" (semver.ToString ()) + | Maximum(semver) -> sprintf "(,%s]" (semver.ToString ()) + | LessThan(semver) -> sprintf "(,%s)" (semver.ToString ()) + | Specific(semver) -> sprintf "[%s]" (semver.ToString()) + | OverrideAll(semver) -> sprintf "[%s]" (semver.ToString()) + | Range(fromB, from,_to,_toB) -> sprintf "%s%s,%s%s" (getRangeRestrictionNugetDelimiter Lower fromB) (from.ToString ()) (_to.ToString ()) (getRangeRestrictionNugetDelimiter Upper _toB) + +let getCurrentlyInstalledVersion p (resolved:ResolvedPackage List) = + (resolved |> List.find (fun rp -> rp.Name = p)).Version + +let getVersionRequirement (p:PackageRequirement) (resolved:ResolvedPackage List) = + match p.VersionRequirement.Range with + | Minimum(semver) when (semver.ToString()) = "0" -> Minimum(getCurrentlyInstalledVersion p.Name resolved) + | version -> version + +let getReferencedPackagesFromProject projectRefFile = + let referencedPackages = getReferencedPackageNamesFromProject projectRefFile + let (dep, lock) = getAllPackages () + dep + |> List.filter (fun p -> referencedPackages |> Array.exists (fun r -> p.Name = r)) + |> List.map (fun p -> let version = getVersionRequirement p lock |> convertVersionRangeToNugetVersion + (p.Name, version)) + +let getDependencies (d:IO.DirectoryInfo) = + let projectSourceDir = (__SOURCE_DIRECTORY__ @@ "src") @@ d.Name + let referencesFile = projectSourceDir @@ "paket.references" + match fileExists referencesFile with + | false -> [] + | true -> getReferencedPackagesFromProject referencesFile + Target "NuGet" (fun _ -> - NuGet (fun p -> - { p with - Authors = authors - Project = project - Summary = summary - Description = description - Version = release.NugetVersion - ReleaseNotes = String.Join(Environment.NewLine, release.Notes) - Tags = tags - OutputPath = "bin" - AccessKey = getBuildParamOrDefault "nugetkey" "" - Publish = hasBuildParam "nugetkey" - Dependencies = [] }) - ("nuget/" + project + ".nuspec") + directoryInfo "bin" + |> subDirectories + |> Array.iter (fun d -> + NuGet (fun p -> + { p with + Authors = authors + Project = d.Name + Summary = summary + Description = description + Version = release.NugetVersion + ReleaseNotes = String.Join(Environment.NewLine, release.Notes) + Tags = tags + Files = getFilenames d + OutputPath = "bin" @@ d.Name + AccessKey = getBuildParamOrDefault "nugetkey" "" + Publish = hasBuildParam "nugetkey" + Dependencies = getDependencies d }) + ("nuget/" + project + ".nuspec") + ) ) // -------------------------------------------------------------------------------------- @@ -232,6 +313,7 @@ Target "All" DoNothing "Clean" ==> "AssemblyInfo" ==> "Build" + ==> "CopyBinaries" ==> "RunTests" =?> ("GenerateReferenceDocs",isLocalBuild && not isMono) =?> ("GenerateDocs",isLocalBuild && not isMono) @@ -258,4 +340,4 @@ Target "All" DoNothing "BuildPackage" ==> "Release" -RunTargetOrDefault "All" \ No newline at end of file +RunTargetOrDefault "All" diff --git a/docs/tools/generate.template b/docs/tools/generate.template index ac943e4..a224c7a 100644 --- a/docs/tools/generate.template +++ b/docs/tools/generate.template @@ -3,8 +3,6 @@ // (the generated documentation is stored in the 'docs/output' directory) // -------------------------------------------------------------------------------------- -// Binaries that have XML documentation (in a corresponding generated XML file) -let referenceBinaries = [ "##ProjectName##.dll" ] // Web site location for the generated documentation let website = "/##ProjectName##" @@ -67,12 +65,16 @@ let copyFiles () = CopyRecursive (formatting @@ "styles") (output @@ "content") true |> Log "Copying styles and scripts: " +let findBinaries () = + directoryInfo bin + |> subDirectories + |> Array.map (fun d -> d.FullName @@ (sprintf "%s.dll" d.Name)) + |> List.ofArray + // Build API reference from XML comments let buildReference () = CleanDir (output @@ "reference") - let binaries = - referenceBinaries - |> List.map (fun lib-> bin @@ lib) + let binaries = findBinaries () MetadataFormat.Generate ( binaries, output @@ "reference", layoutRoots, parameters = ("root", root)::info, diff --git a/nuget/FSharp.ProjectTemplate.nuspec b/nuget/FSharp.ProjectTemplate.nuspec index ebd2d3a..08a9d80 100644 --- a/nuget/FSharp.ProjectTemplate.nuspec +++ b/nuget/FSharp.ProjectTemplate.nuspec @@ -14,10 +14,7 @@ @releaseNotes@ Copyright 2013 @tags@ - + @dependencies@ - - - - + @files@ diff --git a/paket.dependencies b/paket.dependencies index fa7072a..5830d85 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -6,5 +6,6 @@ nuget NUnit.Runners nuget Nuget.CommandLine nuget FAKE nuget SourceLink.Fake +nuget Paket.Core -github fsharp/FAKE modules/Octokit/Octokit.fsx \ No newline at end of file +github fsharp/FAKE modules/Octokit/Octokit.fsx diff --git a/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj b/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj index 8eb45da..9096782 100644 --- a/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj +++ b/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj @@ -19,19 +19,19 @@ full false false - ..\..\bin + bin\Debug DEBUG;TRACE 3 - ..\..\bin\FSharp.ProjectTemplate.xml + bin\Debug\FSharp.ProjectTemplate.xml pdbonly true true - ..\..\bin + bin\Release TRACE 3 - ..\..\bin\FSharp.ProjectTemplate.xml + \bin\Release\FSharp.ProjectTemplate.xml @@ -70,4 +70,4 @@ --> - \ No newline at end of file + From 0fa87c4ac2e69e2b19506711d8dea230043d7d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 16 Oct 2014 16:05:21 +0200 Subject: [PATCH 02/14] Fixing failed path --- src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj b/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj index 9096782..f0aae4c 100644 --- a/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj +++ b/src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj @@ -19,19 +19,19 @@ full false false - bin\Debug + .\bin\Debug DEBUG;TRACE 3 - bin\Debug\FSharp.ProjectTemplate.xml + .\bin\Debug\FSharp.ProjectTemplate.xml pdbonly true true - bin\Release + .\bin\Release TRACE 3 - \bin\Release\FSharp.ProjectTemplate.xml + .\bin\Release\FSharp.ProjectTemplate.xml From fc90f5320582af179a54dceb0efd1e38b1f735f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Fri, 17 Oct 2014 14:37:41 +0200 Subject: [PATCH 03/14] Added support for interproject dependencies and executables * For dependencies between projects in the same solution, a nuget dependency to the generated package for the projects are added to the nuspec * For projects with Exe output type, All files in the relevant bin folder are added to the nuget package, no dependencies. Cause dealing with dependencies in a deploy situation is not really fun. --- build.template | 80 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/build.template b/build.template index dcb8da9..f50ba75 100644 --- a/build.template +++ b/build.template @@ -170,10 +170,65 @@ Target "SourceLink" (fun _ -> // -------------------------------------------------------------------------------------- // Build a NuGet package -let getFilenames (d:IO.DirectoryInfo) = +type FrameworkVersion (projectFwVersion:string) = + let nugetFwVersion = projectFwVersion.Replace("v","net") + member x.NugetFwVersion = nugetFwVersion + +type Output = +| Exe +| Library + +let dirI = + directoryInfo ((__SOURCE_DIRECTORY__ @@ "bin") @@ "Tu.Tu") + +let getProjectFile (d:IO.DirectoryInfo) = + let dirI = directoryInfo ((__SOURCE_DIRECTORY__ @@ "src") @@ d.Name) + if not dirI.Exists then failwith (sprintf "%s does not exist" dirI.FullName ) + let pfile = match dirI.GetFiles("*.?sproj") with + | [|unique|] -> ProjectFile.Load unique.FullName + | [||] -> failwith (sprintf "No project files found in %s" d.FullName) + | many -> failwith (sprintf "More than one project file was found in %s: %A" d.FullName many) + + match pfile with + | Some(p) -> p + | None -> failwith "Unable to load project file" + +let getNodes (p:ProjectFile) name = + let query = (sprintf "//ns:%s" name) + let nodes = p.Document.SelectNodes((sprintf "//ns:%s" name), p.Namespaces) + match nodes.Count with + | 0 -> None + | _ -> Some(nodes) + +let getNode (p:ProjectFile) name = + match getNodes p name with + | None -> failwith (sprintf "%s Not found in project file %s" name p.FileName) + | Some(n) when n.Count > 1 -> failwith (sprintf "More than one element of %s found in project file %s" name p.FileName) + | Some(n) -> n.[0] + +let getOutputType (d:IO.DirectoryInfo) = + let projFile = getProjectFile d + let output = (getNode projFile "OutputType").InnerText + let fw = (getNode projFile "TargetFrameworkVersion").InnerText + match output with + | "Exe" -> (Exe, (new FrameworkVersion(fw))) + | _ -> (Library, (new FrameworkVersion(fw))) + +let getFilenamesForLibraryOutput (d:IO.DirectoryInfo) = [d.FullName @@ (sprintf "%s.dll" d.Name) d.FullName @@ (sprintf "%s.pdb" d.Name)] - |> List.map (fun f -> (f, Some("lib/net40"), None)) + +let getFilenamesForExeOutput (d:IO.DirectoryInfo) = + d.GetFiles("*", IO.SearchOption.AllDirectories) + |> Array.map (fun f -> f.FullName) + |> Array.toList + +let getFilenames (d:IO.DirectoryInfo) = + let (output, fwVersion) = getOutputType d + let files = match output with + | Exe -> getFilenamesForExeOutput d + | Library -> getFilenamesForLibraryOutput d + files |> List.map(fun f -> (f, Some("lib" @@ fwVersion.NugetFwVersion), None)) let getAllPackages () = let dep = (DependenciesFile.ReadFromFile (__SOURCE_DIRECTORY__ @@ "paket.dependencies")) @@ -225,13 +280,22 @@ let getReferencedPackagesFromProject projectRefFile = |> List.map (fun p -> let version = getVersionRequirement p lock |> convertVersionRangeToNugetVersion (p.Name, version)) -let getDependencies (d:IO.DirectoryInfo) = - let projectSourceDir = (__SOURCE_DIRECTORY__ @@ "src") @@ d.Name - let referencesFile = projectSourceDir @@ "paket.references" - match fileExists referencesFile with - | false -> [] - | true -> getReferencedPackagesFromProject referencesFile +let getInterProjectDependencies (d:IO.DirectoryInfo) = + let projFile = getProjectFile d + match getNodes projFile "ProjectReference" with + | None -> [] + | Some(nodes) -> [for n in nodes -> (n.SelectSingleNode("ns:Name", projFile.Namespaces).InnerText, release.NugetVersion)] +let getDependencies (d:IO.DirectoryInfo) = + match getOutputType d with + | Exe,_ -> [] + | _ ,_ -> let projectSourceDir = (__SOURCE_DIRECTORY__ @@ "src") @@ d.Name + let referencesFile = projectSourceDir @@ "paket.references" + let externalDependencies = match fileExists referencesFile with + | false -> [] + | true -> getReferencedPackagesFromProject referencesFile + (getInterProjectDependencies d) @ externalDependencies + Target "NuGet" (fun _ -> directoryInfo "bin" |> subDirectories From 38477855d98097cdcdce34e94c6b78269c337ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Tue, 21 Oct 2014 11:26:21 +0200 Subject: [PATCH 04/14] Getting the correct libdirs Changed how libdirs are resolved for generating API docs with the new bin folder hierarchy. --- docs/tools/generate.template | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/tools/generate.template b/docs/tools/generate.template index a224c7a..73185e2 100644 --- a/docs/tools/generate.template +++ b/docs/tools/generate.template @@ -71,6 +71,12 @@ let findBinaries () = |> Array.map (fun d -> d.FullName @@ (sprintf "%s.dll" d.Name)) |> List.ofArray +let findLibDirs () = + directoryInfo bin + |> subDirectories + |> Array.map (fun d -> d.FullName) + |> List.ofArray + // Build API reference from XML comments let buildReference () = CleanDir (output @@ "reference") @@ -80,7 +86,7 @@ let buildReference () = parameters = ("root", root)::info, sourceRepo = githubLink @@ "tree/master", sourceFolder = __SOURCE_DIRECTORY__ @@ ".." @@ "..", - publicOnly = true, libDirs = [bin] ) + publicOnly = true,libDirs = (findLibDirs ()) ) // Build documentation from `fsx` and `md` files in `docs/content` let buildDocumentation () = From cf5ce8e33123b3ef987f46cb5d26d2f20f070160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Tue, 28 Oct 2014 08:51:52 +0100 Subject: [PATCH 05/14] Nuget version formatting now in Paket --- build.template | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/build.template b/build.template index 1011327..01b4c2a 100644 --- a/build.template +++ b/build.template @@ -236,32 +236,6 @@ let getAllPackages () = let getReferencedPackageNamesFromProject projectRefFile = IO.File.ReadAllLines projectRefFile -type RangeRestriction = -| Upper -| Lower - -let getRangeRestrictionNugetDelimiter (r:RangeRestriction) (v:VersionRangeBound) = - match r, v with - | Upper, VersionRangeBound.Including -> "]" - | Upper, VersionRangeBound.Excluding -> ")" - | Lower, VersionRangeBound.Including -> "[" - | Lower, VersionRangeBound.Excluding -> "(" - -let nugetFriendlySemver (s:SemVerInfo) = - match (s.ToString()) with - | "0" -> "" - | ok -> ok - -let convertVersionRangeToNugetVersion (v:VersionRange) = - match v with - | Minimum(semver) -> semver |> nugetFriendlySemver - | GreaterThan(semver) -> sprintf "(%s,)" (semver.ToString ()) - | Maximum(semver) -> sprintf "(,%s]" (semver.ToString ()) - | LessThan(semver) -> sprintf "(,%s)" (semver.ToString ()) - | Specific(semver) -> sprintf "[%s]" (semver.ToString()) - | OverrideAll(semver) -> sprintf "[%s]" (semver.ToString()) - | Range(fromB, from,_to,_toB) -> sprintf "%s%s,%s%s" (getRangeRestrictionNugetDelimiter Lower fromB) (from.ToString ()) (_to.ToString ()) (getRangeRestrictionNugetDelimiter Upper _toB) - let getCurrentlyInstalledVersion p (resolved:ResolvedPackage List) = (resolved |> List.find (fun rp -> rp.Name = p)).Version @@ -275,7 +249,7 @@ let getReferencedPackagesFromProject projectRefFile = let (dep, lock) = getAllPackages () dep |> List.filter (fun p -> referencedPackages |> Array.exists (fun r -> p.Name = r)) - |> List.map (fun p -> let version = getVersionRequirement p lock |> convertVersionRangeToNugetVersion + |> List.map (fun p -> let version = getVersionRequirement p lock |> NugetVersionRangeParser.format (p.Name, version)) let getInterProjectDependencies (d:IO.DirectoryInfo) = From ff404adff9400e13ce9e094d7528346094d4cba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 30 Oct 2014 15:34:00 +0100 Subject: [PATCH 06/14] Simplifying with all the latest goodness from paket --- build.template | 150 +++++++++++++++++++------------------------------ 1 file changed, 58 insertions(+), 92 deletions(-) diff --git a/build.template b/build.template index 01b4c2a..7071734 100644 --- a/build.template +++ b/build.template @@ -168,110 +168,76 @@ Target "SourceLink" (fun _ -> // -------------------------------------------------------------------------------------- // Build a NuGet package -type FrameworkVersion (projectFwVersion:string) = - let nugetFwVersion = projectFwVersion.Replace("v","net") - member x.NugetFwVersion = nugetFwVersion - -type Output = -| Exe -| Library - -let dirI = - directoryInfo ((__SOURCE_DIRECTORY__ @@ "bin") @@ "Tu.Tu") - -let getProjectFile (d:IO.DirectoryInfo) = - let dirI = directoryInfo ((__SOURCE_DIRECTORY__ @@ "src") @@ d.Name) +// Helper function to get the correct project file +// according to src fir directory name convention +// Basically we feed the directory of the bin/[ProjName] +// and we convert to src/[ProjecName] and in this directory +// we expect to find exactly ONE project file. +let getProjectFile projectName = + let dirI = directoryInfo ((__SOURCE_DIRECTORY__ @@ "src") @@ projectName) if not dirI.Exists then failwith (sprintf "%s does not exist" dirI.FullName ) let pfile = match dirI.GetFiles("*.?sproj") with | [|unique|] -> ProjectFile.Load unique.FullName - | [||] -> failwith (sprintf "No project files found in %s" d.FullName) - | many -> failwith (sprintf "More than one project file was found in %s: %A" d.FullName many) + | [||] -> failwith (sprintf "No project files found in %s" dirI.FullName) + | many -> failwith (sprintf "More than one project file was found in %s: %A" dirI.FullName many) match pfile with | Some(p) -> p | None -> failwith "Unable to load project file" + +// helper function to get output type and target fw +let getOutputType projectName = + let fwToNugetFriendlyString (fw:FrameworkIdentifier) = + match fw with + | DotNetFramework(version) -> (version.ToString ()).Replace("v","net") + | _ -> failwith (sprintf "%s not yet supported" (fw.ToString ())) //TODO other platforms like Mono -let getNodes (p:ProjectFile) name = - let query = (sprintf "//ns:%s" name) - let nodes = p.Document.SelectNodes((sprintf "//ns:%s" name), p.Namespaces) - match nodes.Count with - | 0 -> None - | _ -> Some(nodes) - -let getNode (p:ProjectFile) name = - match getNodes p name with - | None -> failwith (sprintf "%s Not found in project file %s" name p.FileName) - | Some(n) when n.Count > 1 -> failwith (sprintf "More than one element of %s found in project file %s" name p.FileName) - | Some(n) -> n.[0] - -let getOutputType (d:IO.DirectoryInfo) = - let projFile = getProjectFile d - let output = (getNode projFile "OutputType").InnerText - let fw = (getNode projFile "TargetFrameworkVersion").InnerText - match output with - | "Exe" -> (Exe, (new FrameworkVersion(fw))) - | _ -> (Library, (new FrameworkVersion(fw))) - -let getFilenamesForLibraryOutput (d:IO.DirectoryInfo) = - [d.FullName @@ (sprintf "%s.dll" d.Name) - d.FullName @@ (sprintf "%s.pdb" d.Name)] - -let getFilenamesForExeOutput (d:IO.DirectoryInfo) = - d.GetFiles("*", IO.SearchOption.AllDirectories) - |> Array.map (fun f -> f.FullName) - |> Array.toList + let projFile = getProjectFile projectName + (projFile.OutputType, projFile.GetTargetFramework () |> fwToNugetFriendlyString) + -let getFilenames (d:IO.DirectoryInfo) = - let (output, fwVersion) = getOutputType d +// helper function to get files to include in nuget package +let getFilenames projectName = + let (output, fwVersion) = getOutputType projectName let files = match output with - | Exe -> getFilenamesForExeOutput d - | Library -> getFilenamesForLibraryOutput d - files |> List.map(fun f -> (f, Some("lib" @@ fwVersion.NugetFwVersion), None)) - -let getAllPackages () = - let dep = (DependenciesFile.ReadFromFile (__SOURCE_DIRECTORY__ @@ "paket.dependencies")) - let lock = (LockFileParser.Parse (IO.File.ReadAllLines (__SOURCE_DIRECTORY__ @@ "paket.lock"))) - (dep.Packages, lock.Packages) - -let getReferencedPackageNamesFromProject projectRefFile = - IO.File.ReadAllLines projectRefFile - -let getCurrentlyInstalledVersion p (resolved:ResolvedPackage List) = - (resolved |> List.find (fun rp -> rp.Name = p)).Version - -let getVersionRequirement (p:PackageRequirement) (resolved:ResolvedPackage List) = - match p.VersionRequirement.Range with - | Minimum(semver) when (semver.ToString()) = "0" -> Minimum(getCurrentlyInstalledVersion p.Name resolved) - | version -> version - -let getReferencedPackagesFromProject projectRefFile = - let referencedPackages = getReferencedPackageNamesFromProject projectRefFile - let (dep, lock) = getAllPackages () - dep - |> List.filter (fun p -> referencedPackages |> Array.exists (fun r -> p.Name = r)) - |> List.map (fun p -> let version = getVersionRequirement p lock |> NugetVersionRangeParser.format - (p.Name, version)) - -let getInterProjectDependencies (d:IO.DirectoryInfo) = - let projFile = getProjectFile d - match getNodes projFile "ProjectReference" with - | None -> [] - | Some(nodes) -> [for n in nodes -> (n.SelectSingleNode("ns:Name", projFile.Namespaces).InnerText, release.NugetVersion)] - -let getDependencies (d:IO.DirectoryInfo) = - match getOutputType d with - | Exe,_ -> [] - | _ ,_ -> let projectSourceDir = (__SOURCE_DIRECTORY__ @@ "src") @@ d.Name - let referencesFile = projectSourceDir @@ "paket.references" - let externalDependencies = match fileExists referencesFile with - | false -> [] - | true -> getReferencedPackagesFromProject referencesFile - (getInterProjectDependencies d) @ externalDependencies + | ProjectOutputType.Exe -> !! (sprintf "bin/%s/*.*" projectName) + | ProjectOutputType.Library -> !! (sprintf "bin/%s/%s.dll" projectName projectName) + ++ (sprintf "bin/%s/%s.pdb" projectName projectName) + files |> Seq.map(fun f -> (f, Some("lib" @@ fwVersion), None)) + |> Seq.toList + +// helper function to determine dependencies of nuget package +let getDependencies projectName = + let getInterProjectDependencies (projFile:ProjectFile) = + projFile.GetInterProjectDependencies () + |> List.map (fun d -> (d.Name, release.NugetVersion)) + + let getReferencedPackagesFromProject projFile = + let normalizeVersionRequirementForNuget name (v:VersionRequirement) = + let getCurrentlyInstalledVersion (packageName:string) = + let lockFile = LockFile.LoadFrom "paket.lock" + let _,v = lockFile.ResolvedPackages |> Map.toList |> List.find (fun (name, v) -> name.ToLower () = packageName.ToLower ()) + v.Version + + match v.Range with + | Minimum(semver) when (semver.ToString()) = "0" -> Minimum(getCurrentlyInstalledVersion name) + | version -> version + + let dependenciesFile = DependenciesFile.ReadFromFile "paket.dependencies" + + DependencyModel.CalcDependencies (dependenciesFile, projFile.FileName) + |> Map.toList + |> List.map (fun (name, v) -> (name, v |> normalizeVersionRequirementForNuget name |> NugetVersionRangeParser.format)) + + match getOutputType projectName with + | ProjectOutputType.Exe, _ -> [] + | _ ,_ -> let p = getProjectFile projectName + (getInterProjectDependencies p) @ (getReferencedPackagesFromProject p) Target "NuGet" (fun _ -> directoryInfo "bin" |> subDirectories - |> Array.iter (fun d -> + |> Array.iter (fun d -> NuGet (fun p -> { p with Authors = authors @@ -281,11 +247,11 @@ Target "NuGet" (fun _ -> Version = release.NugetVersion ReleaseNotes = String.Join(Environment.NewLine, release.Notes) Tags = tags - Files = getFilenames d + Files = getFilenames d.Name OutputPath = "bin" @@ d.Name AccessKey = getBuildParamOrDefault "nugetkey" "" Publish = hasBuildParam "nugetkey" - Dependencies = getDependencies d }) + Dependencies = getDependencies d.Name }) ("nuget/" + project + ".nuspec") ) ) From 482d2bf9ca7ac9010baed6a4a84fe57812812bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 20 Nov 2014 10:26:47 +0100 Subject: [PATCH 07/14] Adapting to new domain types of Paket --- build.template | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build.template b/build.template index 7071734..9884408 100644 --- a/build.template +++ b/build.template @@ -9,6 +9,7 @@ open Fake.Git open Fake.AssemblyInfoFile open Fake.ReleaseNotesHelper open Paket +open Paket.Domain open Paket.PackageResolver open Paket.Requirements open System @@ -214,9 +215,9 @@ let getDependencies projectName = let getReferencedPackagesFromProject projFile = let normalizeVersionRequirementForNuget name (v:VersionRequirement) = - let getCurrentlyInstalledVersion (packageName:string) = + let getCurrentlyInstalledVersion packageName = let lockFile = LockFile.LoadFrom "paket.lock" - let _,v = lockFile.ResolvedPackages |> Map.toList |> List.find (fun (name, v) -> name.ToLower () = packageName.ToLower ()) + let _,v = lockFile.ResolvedPackages |> Map.toList |> List.find (fun (name, v) -> name = NormalizedPackageName(packageName)) v.Version match v.Range with @@ -225,9 +226,12 @@ let getDependencies projectName = let dependenciesFile = DependenciesFile.ReadFromFile "paket.dependencies" + let packageNameToString = function + | PackageName n -> n + DependencyModel.CalcDependencies (dependenciesFile, projFile.FileName) |> Map.toList - |> List.map (fun (name, v) -> (name, v |> normalizeVersionRequirementForNuget name |> NugetVersionRangeParser.format)) + |> List.map (fun (name, v) -> (name |> packageNameToString, v |> normalizeVersionRequirementForNuget name |> NugetVersionRangeParser.format)) match getOutputType projectName with | ProjectOutputType.Exe, _ -> [] From fcbc5fd61b52fc45a6dd6131148885281c6fe51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Wed, 25 Feb 2015 11:46:22 +0100 Subject: [PATCH 08/14] Fixing errors after api changes --- build.template | 11 +++++------ docs/tools/generate.template | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build.template b/build.template index c70bddd..88e5082 100644 --- a/build.template +++ b/build.template @@ -3,7 +3,7 @@ // -------------------------------------------------------------------------------------- #r @"packages/FAKE/tools/FakeLib.dll" -#r @"packages/Paket.Core/lib/Paket.Core.dll" +#r @"packages/Paket.Core/lib/net40/Paket.Core.dll" open Fake open Fake.Git open Fake.AssemblyInfoFile @@ -217,8 +217,7 @@ let getFilenames projectName = let (output, fwVersion) = getOutputType projectName let files = match output with | ProjectOutputType.Exe -> !! (sprintf "bin/%s/*.*" projectName) - | ProjectOutputType.Library -> !! (sprintf "bin/%s/%s.dll" projectName projectName) - ++ (sprintf "bin/%s/%s.pdb" projectName projectName) + | ProjectOutputType.Library -> (!! (sprintf "bin/%s/%s.dll" projectName projectName)).And (sprintf "bin/%s/%s.pdb" projectName projectName) files |> Seq.map(fun f -> (f, Some("lib" @@ fwVersion), None)) |> Seq.toList @@ -236,8 +235,8 @@ let getDependencies projectName = v.Version match v.Range with - | Minimum(semver) when (semver.ToString()) = "0" -> Minimum(getCurrentlyInstalledVersion name) - | version -> version + | Minimum(semver) when (semver.ToString()) = "0" -> Minimum(getCurrentlyInstalledVersion name).FormatInNuGetSyntax () + | version -> version.FormatInNuGetSyntax () let dependenciesFile = DependenciesFile.ReadFromFile "paket.dependencies" @@ -246,7 +245,7 @@ let getDependencies projectName = DependencyModel.CalcDependencies (dependenciesFile, projFile.FileName) |> Map.toList - |> List.map (fun (name, v) -> (name |> packageNameToString, v |> normalizeVersionRequirementForNuget name |> NugetVersionRangeParser.format)) + |> List.map (fun (name, v) -> (name |> packageNameToString, v |> normalizeVersionRequirementForNuget name)) match getOutputType projectName with | ProjectOutputType.Exe, _ -> [] diff --git a/docs/tools/generate.template b/docs/tools/generate.template index 9cac360..580a899 100644 --- a/docs/tools/generate.template +++ b/docs/tools/generate.template @@ -104,7 +104,7 @@ let buildReference () = parameters = ("root", root)::info, sourceRepo = githubLink @@ "tree/master", sourceFolder = __SOURCE_DIRECTORY__ @@ ".." @@ "..", - ?assemblyReferences = references ) + ?assemblyReferences = references, publicOnly = true,libDirs = (findLibDirs ()) ) // Build documentation from `fsx` and `md` files in `docs/content` From e4d793dc98c31f27a450fff19c35cf8ab45f6170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 26 Feb 2015 08:34:05 +0100 Subject: [PATCH 09/14] Remove redundant nuget code --- build.template | 73 -------------------------------------------------- 1 file changed, 73 deletions(-) diff --git a/build.template b/build.template index d6b3022..91bb1d3 100644 --- a/build.template +++ b/build.template @@ -3,15 +3,10 @@ // -------------------------------------------------------------------------------------- #r @"packages/FAKE/tools/FakeLib.dll" -#r @"packages/Paket.Core/lib/net40/Paket.Core.dll" open Fake open Fake.Git open Fake.AssemblyInfoFile open Fake.ReleaseNotesHelper -open Paket -open Paket.Domain -open Paket.PackageResolver -open Paket.Requirements open System open System.IO #if MONO @@ -184,74 +179,6 @@ Target "SourceLink" (fun _ -> // -------------------------------------------------------------------------------------- // Build a NuGet package -// Helper function to get the correct project file -// according to src fir directory name convention -// Basically we feed the directory of the bin/[ProjName] -// and we convert to src/[ProjecName] and in this directory -// we expect to find exactly ONE project file. -let getProjectFile projectName = - let dirI = directoryInfo ((__SOURCE_DIRECTORY__ @@ "src") @@ projectName) - if not dirI.Exists then failwith (sprintf "%s does not exist" dirI.FullName ) - let pfile = match dirI.GetFiles("*.?sproj") with - | [|unique|] -> ProjectFile.Load unique.FullName - | [||] -> failwith (sprintf "No project files found in %s" dirI.FullName) - | many -> failwith (sprintf "More than one project file was found in %s: %A" dirI.FullName many) - - match pfile with - | Some(p) -> p - | None -> failwith "Unable to load project file" - -// helper function to get output type and target fw -let getOutputType projectName = - let fwToNugetFriendlyString (fw:FrameworkIdentifier) = - match fw with - | DotNetFramework(version) -> (version.ToString ()).Replace("v","net") - | _ -> failwith (sprintf "%s not yet supported" (fw.ToString ())) //TODO other platforms like Mono - - let projFile = getProjectFile projectName - (projFile.OutputType, projFile.GetTargetFramework () |> fwToNugetFriendlyString) - - -// helper function to get files to include in nuget package -let getFilenames projectName = - let (output, fwVersion) = getOutputType projectName - let files = match output with - | ProjectOutputType.Exe -> !! (sprintf "bin/%s/*.*" projectName) - | ProjectOutputType.Library -> (!! (sprintf "bin/%s/%s.dll" projectName projectName)).And (sprintf "bin/%s/%s.pdb" projectName projectName) - files |> Seq.map(fun f -> (f, Some("lib" @@ fwVersion), None)) - |> Seq.toList - -// helper function to determine dependencies of nuget package -let getDependencies projectName = - let getInterProjectDependencies (projFile:ProjectFile) = - projFile.GetInterProjectDependencies () - |> List.map (fun d -> (d.Name, release.NugetVersion)) - - let getReferencedPackagesFromProject projFile = - let normalizeVersionRequirementForNuget name (v:VersionRequirement) = - let getCurrentlyInstalledVersion packageName = - let lockFile = LockFile.LoadFrom "paket.lock" - let _,v = lockFile.ResolvedPackages |> Map.toList |> List.find (fun (name, v) -> name = NormalizedPackageName(packageName)) - v.Version - - match v.Range with - | Minimum(semver) when (semver.ToString()) = "0" -> Minimum(getCurrentlyInstalledVersion name).FormatInNuGetSyntax () - | version -> version.FormatInNuGetSyntax () - - let dependenciesFile = DependenciesFile.ReadFromFile "paket.dependencies" - - let packageNameToString = function - | PackageName n -> n - - DependencyModel.CalcDependencies (dependenciesFile, projFile.FileName) - |> Map.toList - |> List.map (fun (name, v) -> (name |> packageNameToString, v |> normalizeVersionRequirementForNuget name)) - - match getOutputType projectName with - | ProjectOutputType.Exe, _ -> [] - | _ ,_ -> let p = getProjectFile projectName - (getInterProjectDependencies p) @ (getReferencedPackagesFromProject p) - Target "NuGet" (fun _ -> Paket.Pack(fun p -> { p with From 1efbffc25154e9d085a220f6592ae465c24047e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 26 Feb 2015 12:40:42 +0100 Subject: [PATCH 10/14] Fixing casing in bin folder name --- build.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.template b/build.template index 91bb1d3..530c9a2 100644 --- a/build.template +++ b/build.template @@ -105,7 +105,7 @@ Target "AssemblyInfo" (fun _ -> Target "CopyBinaries" (fun _ -> directoryInfo "src" |> subDirectories - |> Array.map (fun d -> (d.Name, sprintf "%s/Bin/Release" d.FullName)) + |> Array.map (fun d -> (d.Name, sprintf "%s/bin/Release" d.FullName)) |> Array.iter (fun (n, p) -> CopyDir (sprintf "bin/%s" n) p (fun _ -> true)) ) From 01537a3dff7423d2e15bdcd6f3f65532fb1a33a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 5 Mar 2015 08:24:22 +0100 Subject: [PATCH 11/14] Binaries and libdirs made into values in generate.template --- docs/tools/generate.template | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tools/generate.template b/docs/tools/generate.template index 580a899..a3e1e90 100644 --- a/docs/tools/generate.template +++ b/docs/tools/generate.template @@ -83,13 +83,14 @@ let references = Path.GetFullPath "./../../packages/FSharp.Formatting/lib/net40/FSharp.MetadataFormat.dll" ] |> Some else None -let findBinaries () = + +let binaries = directoryInfo bin |> subDirectories |> Array.map (fun d -> d.FullName @@ (sprintf "%s.dll" d.Name)) |> List.ofArray -let findLibDirs () = +let libDirs = directoryInfo bin |> subDirectories |> Array.map (fun d -> d.FullName) @@ -98,14 +99,13 @@ let findLibDirs () = // Build API reference from XML comments let buildReference () = CleanDir (output @@ "reference") - let binaries = findBinaries () MetadataFormat.Generate ( binaries, output @@ "reference", layoutRootsAll.["en"], parameters = ("root", root)::info, sourceRepo = githubLink @@ "tree/master", sourceFolder = __SOURCE_DIRECTORY__ @@ ".." @@ "..", ?assemblyReferences = references, - publicOnly = true,libDirs = (findLibDirs ()) ) + publicOnly = true,libDirs = libDirs ) // Build documentation from `fsx` and `md` files in `docs/content` let buildDocumentation () = From 0eec754c51775c197bd7da56697e803e96cc4f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 5 Mar 2015 08:24:55 +0100 Subject: [PATCH 12/14] Remove redundant Paket.Core reference --- paket.dependencies | 1 - 1 file changed, 1 deletion(-) diff --git a/paket.dependencies b/paket.dependencies index 378fae8..712fd08 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -5,6 +5,5 @@ nuget NUnit nuget NUnit.Runners nuget FAKE nuget SourceLink.Fake -nuget Paket.Core github fsharp/FAKE modules/Octokit/Octokit.fsx From a89baab1be042d6ed071ecba05b2b43127bb82a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 5 Mar 2015 10:55:30 +0100 Subject: [PATCH 13/14] use proper path combine functions --- build.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.template b/build.template index 530c9a2..d72bf2f 100644 --- a/build.template +++ b/build.template @@ -105,8 +105,8 @@ Target "AssemblyInfo" (fun _ -> Target "CopyBinaries" (fun _ -> directoryInfo "src" |> subDirectories - |> Array.map (fun d -> (d.Name, sprintf "%s/bin/Release" d.FullName)) - |> Array.iter (fun (n, p) -> CopyDir (sprintf "bin/%s" n) p (fun _ -> true)) + |> Array.map (fun d -> (d.Name, (d.FullName @@ "/bin/Release"))) + |> Array.iter (fun (n, p) -> CopyDir ("bin/" @@ n) p (fun _ -> true)) ) // -------------------------------------------------------------------------------------- From 8c3ccbe41304a5132f335f8473813320fcfd2af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20L=2E=20S=C3=B8mme?= Date: Thu, 5 Mar 2015 11:28:29 +0100 Subject: [PATCH 14/14] More robust function to copy binaries --- build.template | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build.template b/build.template index d72bf2f..6efdcd5 100644 --- a/build.template +++ b/build.template @@ -103,10 +103,9 @@ Target "AssemblyInfo" (fun _ -> // But keeps a subdirectory structure for each project in the // src folder to support multiple project outputs Target "CopyBinaries" (fun _ -> - directoryInfo "src" - |> subDirectories - |> Array.map (fun d -> (d.Name, (d.FullName @@ "/bin/Release"))) - |> Array.iter (fun (n, p) -> CopyDir ("bin/" @@ n) p (fun _ -> true)) + !! "src/**/*.??proj" + |> Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) @@ "bin/Release", "bin" @@ (System.IO.Path.GetFileNameWithoutExtension f))) + |> Seq.iter (fun (fromDir, toDir) -> CopyDir toDir fromDir (fun _ -> true)) ) // --------------------------------------------------------------------------------------