Skip to content
Closed
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
151 changes: 135 additions & 16 deletions build.template
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
Expand Down Expand Up @@ -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 _ ->

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two reasons:

  1. You can add new projects without changing default settings.
  2. Even with the default settings, I like to have my binaries in one place after build

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

Copy link
Copy Markdown
Member

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.

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

Expand Down Expand Up @@ -155,21 +168,126 @@ Target "SourceLink" (fun _ ->
// --------------------------------------------------------------------------------------
// Build a NuGet package

type FrameworkVersion (projectFwVersion:string) =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da fuq? what's Tu.Tu?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it still needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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) =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.
As to the many option. It is just one more opinion: one project in each src. Subfolder. I've used the folder name as key for some of this stuff.

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 =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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) =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably go into Paket's ProjectFile module...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output type is now supported: fsprojects/Paket@9252e92

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is target fw also supported somewhere?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, I'm not sure how we extract the selected framework.
On Oct 29, 2014 9:09 PM, "Vidar Løvbrekke Sømme" [email protected]
wrote:

In build.template:

  • | 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) =

Is target fw also supported somewhere?

—
Reply to this email directly or view it on GitHub
https://github.com/fsprojects/ProjectScaffold/pull/101/files#r19568387.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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").InnerText

But I'm pretty sure there are loads of edge cases (targeting multiple fw versions?) that will not be covered

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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) =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't use FAKE's globbing?! why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 GetPackageHull (as I do not require indirect dependencies)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right that was the wrong one.
Please try fsprojects/Paket@667a1e6#diff-99b45a5cb27d99b9474be5250b7d8f99R16

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) =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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")
)
)

// --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -265,6 +383,7 @@ Target "All" DoNothing
"Clean"
==> "AssemblyInfo"
==> "Build"
==> "CopyBinaries"
==> "RunTests"
=?> ("GenerateReferenceDocs",isLocalBuild && not isMono)
=?> ("GenerateDocs",isLocalBuild && not isMono)
Expand Down
20 changes: 14 additions & 6 deletions docs/tools/generate.template
Original file line number Diff line number Diff line change
Expand Up @@ -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##"

Expand Down Expand Up @@ -67,18 +65,28 @@ let copyFiles () =
CopyRecursive (formatting @@ "styles") (output @@ "content") true
|> Log "Copying styles and scripts: "

let findBinaries () =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean !! "bin/**/*.dll"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 () =
Expand Down
7 changes: 2 additions & 5 deletions nuget/FSharp.ProjectTemplate.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright 2013</copyright>
<tags>@tags@</tags>
<dependencies />
@dependencies@
</metadata>
<files>
<file src="..\bin\FSharp.ProjectTemplate.dll" target="lib/net40" />
<file src="..\bin\FSharp.ProjectTemplate.pdb" target="lib/net40" />
</files>
@files@
</package>
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -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
github fsharp/FAKE modules/Octokit/Octokit.fsx
10 changes: 5 additions & 5 deletions src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>..\..\bin</OutputPath>
<OutputPath>.\bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>..\..\bin\FSharp.ProjectTemplate.xml</DocumentationFile>
<DocumentationFile>.\bin\Debug\FSharp.ProjectTemplate.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>..\..\bin</OutputPath>
<OutputPath>.\bin\Release</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>..\..\bin\FSharp.ProjectTemplate.xml</DocumentationFile>
<DocumentationFile>.\bin\Release\FSharp.ProjectTemplate.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
Expand Down Expand Up @@ -70,4 +70,4 @@
</Target>
-->
<Import Project="..\..\.paket\paket.targets" />
</Project>
</Project>