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

Install props and targets files to the project #578

Merged
merged 3 commits into from
Feb 3, 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
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.27.0-alpha001 - 03.02.2015
* Allow to reference `.props` and `.targets` files - https://github.com/fsprojects/Paket/issues/516

#### 0.26.4 - 02.02.2015
* Create a install function in the api which takes a `paket.dependencies` file as text - https://github.com/fsprojects/Paket/issues/576

Expand Down
99 changes: 73 additions & 26 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ open Paket.Requirements
[<RequireQualifiedAccess>]
type Reference =
| Library of string
| TargetsFile of string
| FrameworkAssemblyReference of string

member this.LibName =
Expand All @@ -21,20 +22,24 @@ type Reference =

member this.FrameworkReferenceName =
match this with
| FrameworkAssemblyReference name -> Some name
| Reference.FrameworkAssemblyReference name -> Some name
| _ -> None

member this.ReferenceName =
match this with
| FrameworkAssemblyReference name -> name
| Reference.FrameworkAssemblyReference name -> name
| Reference.TargetsFile targetsFile ->
let fi = new FileInfo(normalizePath targetsFile)
fi.Name.Replace(fi.Extension, "")
| Reference.Library lib ->
let fi = new FileInfo(normalizePath lib)
fi.Name.Replace(fi.Extension, "")

member this.Path =
match this with
| Library path -> path
| FrameworkAssemblyReference path -> path
| Reference.Library path -> path
| Reference.TargetsFile path -> path
| Reference.FrameworkAssemblyReference path -> path

type InstallFiles =
{ References : Reference Set
Expand All @@ -49,6 +54,9 @@ type InstallFiles =
member this.AddReference lib =
{ this with References = Set.add (Reference.Library lib) this.References }

member this.AddTargetsFile targetsFile =
{ this with References = Set.add (Reference.TargetsFile targetsFile) this.References }

member this.AddFrameworkAssemblyReference assemblyName =
{ this with References = Set.add (Reference.FrameworkAssemblyReference assemblyName) this.References }

Expand All @@ -57,7 +65,7 @@ type InstallFiles =
|> Set.map (fun r -> r.FrameworkReferenceName)
|> Seq.choose id

member this.MergeWith(that:InstallFiles)=
member this.MergeWith(that:InstallFiles) =
{ this with
References = Set.union that.References this.References
ContentFiles = Set.union that.ContentFiles this.ContentFiles }
Expand Down Expand Up @@ -97,6 +105,16 @@ type InstallModel =
| _ -> None)
|> Seq.choose id
| None -> Seq.empty

member this.GetTargetsFiles(target : TargetProfile) =
match Seq.tryFind (fun lib -> Seq.exists (fun t -> t = target) lib.Targets) this.LibFolders with
| Some folder -> folder.Files.References
|> Set.map (fun x ->
match x with
| Reference.TargetsFile targetsFile -> Some targetsFile
| _ -> None)
|> Seq.choose id
| None -> Seq.empty

member this.AddLibFolders(libs : seq<string>) : InstallModel =
let libFolders =
Expand All @@ -114,48 +132,75 @@ type InstallModel =
|> Seq.toList

{ this with LibFolders = libFolders}

member this.AddBuildFolders(libs : seq<string>) : InstallModel =
let libFolders =
libs
|> Seq.map this.ExtractBuildFolder
|> Seq.choose id
|> Seq.distinct
|> List.ofSeq

if libFolders.Length = 0 then this
else
let libFolders =
PlatformMatching.getSupportedTargetProfiles libFolders
|> Seq.map (fun entry -> { Name = entry.Key; Targets = entry.Value; Files = InstallFiles.empty })
|> Seq.toList

{ this with LibFolders = libFolders}

member this.ExtractLibFolder(path : string) : string option=
let path = path.Replace("\\", "/").ToLower()
let fi = new FileInfo(path)
member this.ExtractLibFolder path = Utils.extractPath "lib" path

let startPos = path.LastIndexOf("lib/")
let endPos = path.IndexOf('/', startPos + 4)
if startPos < 0 then None
elif endPos < 0 then Some("")
else
Some(path.Substring(startPos + 4, endPos - startPos - 4))
member this.ExtractBuildFolder path = Utils.extractPath "build" path

member this.MapFolders(mapF) = { this with LibFolders = List.map mapF this.LibFolders }

member this.MapFiles(mapF) =
this.MapFolders(fun folder -> { folder with Files = mapF folder.Files })

member this.AddPackageFiles(path : LibFolder, file : string, references) : InstallModel =
member this.AddPackageFile(path : LibFolder, file : string, references) : InstallModel =
let install =
match references with
| NuspecReferences.All -> true
| NuspecReferences.Explicit list -> List.exists file.EndsWith list

if not install then this else

let folders = List.map (fun p ->
let folders =
this.LibFolders
|> List.map (fun p ->
if p.Name = path.Name then { p with Files = p.Files.AddReference file }
else p) this.LibFolders
else p)

{ this with LibFolders = folders }

member this.AddFiles(files : seq<string>, references) : InstallModel =
member this.AddReferences(libs, references) : InstallModel =
Seq.fold (fun model file ->
match model.ExtractLibFolder file with
| Some folderName ->
match Seq.tryFind (fun folder -> folder.Name = folderName) model.LibFolders with
| Some path -> model.AddPackageFiles(path, file, references)
| Some path -> model.AddPackageFile(path, file, references)
| _ -> model
| None -> model) this files
| None -> model) (this.AddLibFolders(libs)) libs

member this.AddTargetsFile(path : LibFolder, file : string) : InstallModel =
let folders =
this.LibFolders
|> List.map (fun p ->
if p.Name = path.Name then { p with Files = p.Files.AddTargetsFile file }
else p)
{ this with LibFolders = folders }

member this.AddReferences(libs, references) : InstallModel =
this.AddLibFolders(libs)
.AddFiles(libs, references)

member this.AddTargetsFiles(libs) : InstallModel =
Seq.fold (fun model file ->
match model.ExtractBuildFolder file with
| Some folderName ->
match Seq.tryFind (fun folder -> folder.Name = folderName) model.LibFolders with
| Some path -> model.AddTargetsFile(path, file)
| _ -> model
| None -> model) (this.AddBuildFolders(libs)) libs

member this.AddReferences(libs) = this.AddReferences(libs, NuspecReferences.All)

Expand Down Expand Up @@ -189,7 +234,8 @@ type InstallModel =

member this.FilterBlackList() =
let includeLibs = function
| Reference.Library lib -> not (lib.EndsWith ".dll" || lib.EndsWith ".exe")
| Reference.Library lib -> not (lib.ToLower().EndsWith ".dll" || lib.ToLower().EndsWith ".exe")
| Reference.TargetsFile targetsFile -> not (targetsFile.ToLower().EndsWith ".props" || targetsFile.ToLower().EndsWith ".targets")
| _ -> false

let excludeSatelliteAssemblies = function
Expand Down Expand Up @@ -250,15 +296,16 @@ type InstallModel =
|> Set.ofList)

member this.RemoveIfCompletelyEmpty() =
if Set.isEmpty (this.GetFrameworkAssemblies.Force()) && Set.isEmpty (this.GetReferences.Force()) then
if Set.isEmpty (this.GetFrameworkAssemblies.Force()) && Set.isEmpty (this.GetReferences.Force()) then
InstallModel.EmptyModel(this.PackageName,this.PackageVersion)
else
this

static member CreateFromLibs(packageName, packageVersion, frameworkRestrictions:FrameworkRestrictions, libs, nuspec : Nuspec) =
static member CreateFromLibs(packageName, packageVersion, frameworkRestrictions:FrameworkRestrictions, libs, targetsFiles, nuspec : Nuspec) =
InstallModel
.EmptyModel(packageName, packageVersion)
.AddReferences(libs, nuspec.References)
.AddTargetsFiles(targetsFiles)
.AddFrameworkAssemblyReferences(nuspec.FrameworkAssemblyReferences)
.FilterBlackList()
.ApplyFrameworkRestrictions(frameworkRestrictions)
Expand Down
7 changes: 4 additions & 3 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ let private removeCopiedFiles (project: ProjectFile) =

let CreateInstallModel(root, sources, force, package) =
async {
let! (package, files) = RestoreProcess.ExtractPackage(root, sources, force, package)
let! (package, files, targetsFiles) = RestoreProcess.ExtractPackage(root, sources, force, package)
let (PackageName name) = package.Name
let nuspec = FileInfo(sprintf "%s/packages/%s/%s.nuspec" root name name)
let nuspec = Nuspec.Load nuspec.FullName
let files = files |> Seq.map (fun fi -> fi.FullName)
return package, InstallModel.CreateFromLibs(package.Name, package.Version, package.FrameworkRestrictions, files, nuspec)
let files = files |> Array.map (fun fi -> fi.FullName)
let targetsFiles = targetsFiles |> Array.map (fun fi -> fi.FullName)
return package, InstallModel.CreateFromLibs(package.Name, package.Version, package.FrameworkRestrictions, files, targetsFiles, nuspec)
}

/// Restores the given packages from the lock file.
Expand Down
23 changes: 22 additions & 1 deletion src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ let DownloadPackage(root, auth, url, name, version:SemVerInfo, force) =
}

/// Finds all libraries in a nuget package.
let GetLibFiles(targetFolder) =
let GetLibFiles(targetFolder) =
let libs =
let dir = DirectoryInfo(targetFolder)
let libPath = dir.FullName.ToLower() + Path.DirectorySeparatorChar.ToString() + "lib"
Expand All @@ -434,6 +434,27 @@ let GetLibFiles(targetFolder) =

libs

/// Finds all targets files in a nuget package.
let GetTargetsFiles(targetFolder) =
let targetsFiles =
let dir = DirectoryInfo(targetFolder)
let path = dir.FullName.ToLower() + Path.DirectorySeparatorChar.ToString() + "build"
if dir.Exists then
dir.GetDirectories()
|> Array.filter (fun fi -> fi.FullName.ToLower() = path)
|> Array.collect (fun dir -> dir.GetFiles("*.*",SearchOption.AllDirectories))
else
Array.empty

if Logging.verbose then
if Array.isEmpty targetsFiles then
verbosefn "No .targets files found in %s" targetFolder
else
let s = String.Join(Environment.NewLine + " - ",targetsFiles |> Array.map (fun l -> l.FullName))
verbosefn ".targets files found in %s:%s - %s" targetFolder Environment.NewLine s

targetsFiles

let GetPackageDetails force sources (PackageName package) (version:SemVerInfo) : PackageResolver.PackageDetails=
let rec tryNext xs =
match xs with
Expand Down
Loading