Repository navigation
[Suggestion] Support for multiple projects with deliverable output #101
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
Changes from all commits
2f11147
0fa87c4
fc90f53
669ce37
3847785
cf5ce8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| // -------------------------------------------------------------------------------------- | ||
| // -------------------------------------------------------------------------------------- | ||
| // FAKE build script | ||
| // -------------------------------------------------------------------------------------- | ||
|
|
||
| #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 | ||
| open System.IO | ||
| #if MONO | ||
|
|
@@ -98,6 +101,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 | ||
|
|
||
|
|
@@ -155,21 +168,126 @@ Target "SourceLink" (fun _ -> | |
| // -------------------------------------------------------------------------------------- | ||
| // Build a NuGet package | ||
|
|
||
| type FrameworkVersion (projectFwVersion:string) = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created fsprojects/Paket#291 - it's up-for-grabs ;-) |
||
| let nugetFwVersion = projectFwVersion.Replace("v","net") | ||
| member x.NugetFwVersion = nugetFwVersion | ||
|
|
||
| type Output = | ||
| | Exe | ||
| | Library | ||
|
|
||
| let dirI = | ||
| directoryInfo ((__SOURCE_DIRECTORY__ @@ "bin") @@ "Tu.Tu") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Da fuq? what's Tu.Tu?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A skirt for ballet dansers, didn't you know 😏 (Apperently, some test data has made its way into this...)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it still needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found that this entire line of code was completely dead. |
||
|
|
||
| let getProjectFile (d:IO.DirectoryInfo) = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have something like that in Paket. but it will find all proj files. why do you exclude the many case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't quite remember why I didn't use the paket one, but I remember having a look at finding it did not quite do what I needed. |
||
| 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 = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure where to put it, yet. Hopefully we can say "bye bye"... |
||
| 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 = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure where to put it, yet. Hopefully we can say "bye bye"... |
||
| 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) = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably go into Paket's ProjectFile module...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Output type is now supported: fsprojects/Paket@9252e92
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is target fw also supported somewhere?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet, I'm not sure how we extract the selected framework.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had the luxury of being really naive in my implementation: let fw = (getNode projFile "TargetFrameworkVersion").InnerTextBut I'm pretty sure there are loads of edge cases (targeting multiple fw versions?) that will not be covered
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so how do we want to proceed with this? |
||
| 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 getFilenames (d:IO.DirectoryInfo) = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't use FAKE's globbing?! why?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignorance would be the obvious answer, no? 😏 (Honestly, I just haven't fully embraced the globbing yet, mostly because it is one of those things I never can seem to learn properly, I have to look it up every time
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please try to use it. We spent months to fix all the strange edge cases that might arise... |
||
| 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")) | ||
| 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 = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you see fsprojects/Paket@75e8896#diff-1c0402362ea00603323e9471b28eba0eR178? Is that what you need?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Partly, it gets me the names. But I also need any version restriction from paket.dependencies
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, just reading the reference file directly is actually less code than using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you are right that was the wrong one. |
||
| 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) = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you now can use fsprojects/Paket@7a3e253 and map over it. But I wonder if we should also capture the path
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah. I just did... fsprojects/Paket@2a020ec#diff-bb5be43f98d6a2cbf84418f550d07b97R269
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments belong to getInterProjectDependencies |
||
| 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 _ -> | ||
| 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") | ||
| ) | ||
| ) | ||
|
|
||
| // -------------------------------------------------------------------------------------- | ||
|
|
@@ -265,6 +383,7 @@ Target "All" DoNothing | |
| "Clean" | ||
| ==> "AssemblyInfo" | ||
| ==> "Build" | ||
| ==> "CopyBinaries" | ||
| ==> "RunTests" | ||
| =?> ("GenerateReferenceDocs",isLocalBuild && not isMono) | ||
| =?> ("GenerateDocs",isLocalBuild && not isMono) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,18 +65,28 @@ let copyFiles () = | |
| CopyRecursive (formatting @@ "styles") (output @@ "content") true | ||
| |> Log "Copying styles and scripts: " | ||
|
|
||
| let findBinaries () = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we don't want to document all dll's in the bin folder for the project. Only the dll output from the project |
||
| directoryInfo bin | ||
| |> subDirectories | ||
| |> 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") | ||
| let binaries = | ||
| referenceBinaries | ||
| |> List.map (fun lib-> bin @@ lib) | ||
| let binaries = findBinaries () | ||
| MetadataFormat.Generate | ||
| ( binaries, output @@ "reference", layoutRoots, | ||
| 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 () = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this step needed? I assume only for the test step, right? why not change the search pattern there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons:
But this is all just for convenience based on peronal preferences, more than actual requirements.
Big thing is not to have all bins for all projects in a single messy bin folder with no proj structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are building opnionated solution layout so opions are good.