Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jam40jeff committed Mar 27, 2019
1 parent 92981d9 commit 71c150b
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 72 deletions.
164 changes: 103 additions & 61 deletions src/Paket.Core/Packaging/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let readAssembly fileName =

let readAssemblyFromProjFile buildConfig buildPlatform (projectFile : ProjectFile) =
let root = Path.GetDirectoryName projectFile.FileName
let subFolder = projectFile.GetOutputDirectory buildConfig buildPlatform
let subFolder = projectFile.GetOutputDirectory buildConfig buildPlatform None
let assemblyName = projectFile.GetAssemblyName()
FileInfo(Path.Combine(root, subFolder, assemblyName) |> normalizePath).FullName
|> readAssembly
Expand Down Expand Up @@ -155,8 +155,11 @@ let excludeDependency (templateFile : TemplateFile) (exclude : PackageName) =
| IncompleteTemplate ->
failwith (sprintf "You should only try to exclude dependencies to template files with complete metadata.%sFile: %s" Environment.NewLine templateFile.FileName)

let toFile config platform (p : ProjectFile) =
Path.Combine(Path.GetDirectoryName p.FileName, p.GetOutputDirectory config platform, p.GetAssemblyName())
let toFileWithOutputDirectory (p : ProjectFile) outputDirectory =
Path.Combine(Path.GetDirectoryName p.FileName, outputDirectory, p.GetAssemblyName())

let toFile config platform (p : ProjectFile) targetProfile =
p.GetOutputDirectory config platform targetProfile |> toFileWithOutputDirectory p

let addFile (source : string) (target : string) (templateFile : TemplateFile) =
match templateFile with
Expand All @@ -166,6 +169,37 @@ let addFile (source : string) (target : string) (templateFile : TemplateFile) =
| IncompleteTemplate ->
failwith (sprintf "You should only try and add files to template files with complete metadata.%sFile: %s" Environment.NewLine templateFile.FileName)

let findBestDependencyTargetProfile dependencyTargetProfiles (targetProfile : TargetProfile option) =
match targetProfile with
| None -> None
| Some targetProfile ->
let exactMatch =
dependencyTargetProfiles
|> List.tryFind ((=) targetProfile)
match exactMatch with
| Some x -> Some x
| None ->
dependencyTargetProfiles
|> List.filter targetProfile.IsAtLeast
|> List.sortDescending
|> List.tryHead

let getTargetDir (project : ProjectFile) targetProfile =
match project.BuildOutputTargetFolder with
| Some x -> x
| None ->
match project.OutputType with
| ProjectOutputType.Exe -> "tools/"
| ProjectOutputType.Library ->
match targetProfile with
| Some targetProfile -> sprintf "lib/%O/" targetProfile
| None -> "lib/"

let getTargetProfiles (project : ProjectFile) =
match project.GetTargetProfiles() with
| [] -> [None]
| x -> List.map Some x

let findDependencies (dependenciesFile : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies minimumFromLockFile pinProjectReferences interprojectReferencesConstraint (projectWithTemplates : Map<string, (Lazy<'TemplateFile>) * ProjectFile * bool>) includeReferencedProjects (version :SemVerInfo option) cache =
let includeReferencedProjects = template.IncludeReferencedProjects || includeReferencedProjects

Expand All @@ -181,13 +215,7 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
else
InterprojectReferencesConstraint.Min

let targetDir =
match project.BuildOutputTargetFolder with
| Some x -> x
| None ->
match project.OutputType with
| ProjectOutputType.Exe -> "tools/"
| ProjectOutputType.Library -> project.GetTargetProfiles() |> List.map (sprintf "lib/%O/") |> List.head // TODO: multi target pack
let targetProfiles = getTargetProfiles project

let projectDir = Path.GetDirectoryName project.FileName

Expand Down Expand Up @@ -228,29 +256,33 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp

let satelliteDlls =
seq {
for project in projects do
let satelliteAssemblyName = Path.GetFileNameWithoutExtension(project.GetAssemblyName()) + ".resources.dll"
let projectDir = Path.GetDirectoryName(Path.GetFullPath(project.FileName))
let outputDir = Path.Combine(projectDir, project.GetOutputDirectory config platform)

let satelliteWithFolders =
Directory.GetFiles(outputDir, satelliteAssemblyName, SearchOption.AllDirectories)
|> Array.map (fun sa -> (sa, Directory.GetParent(sa)))
|> Array.filter (fun (sa, dirInfo) -> Cultures.isLanguageName (dirInfo.Name))

let existedSatelliteLanguages =
satelliteWithFolders
|> Array.map (fun (_, dirInfo) -> dirInfo.Name)
|> Set.ofArray

project.FindLocalizedLanguageNames()
|> List.filter (existedSatelliteLanguages.Contains >> not)
|> List.iter (fun lang ->
traceWarnfn "Did not find satellite assembly for (%s) try building and running pack again." lang)

yield!
satelliteWithFolders
|> Array.map (fun (sa, dirInfo) -> (FileInfo sa, Path.Combine(targetDir, dirInfo.Name)))
for targetProfile in targetProfiles do
let targetDir = getTargetDir project targetProfile
for project in projects do
let dependencyTargetProfiles = project.GetTargetProfiles()
let dependencyTargetProfile = findBestDependencyTargetProfile dependencyTargetProfiles targetProfile
let satelliteAssemblyName = Path.GetFileNameWithoutExtension(project.GetAssemblyName()) + ".resources.dll"
let projectDir = Path.GetDirectoryName(Path.GetFullPath(project.FileName))
let outputDir = Path.Combine(projectDir, project.GetOutputDirectory config platform dependencyTargetProfile)

let satelliteWithFolders =
Directory.GetFiles(outputDir, satelliteAssemblyName, SearchOption.AllDirectories)
|> Array.map (fun sa -> (sa, Directory.GetParent(sa)))
|> Array.filter (fun (sa, dirInfo) -> Cultures.isLanguageName (dirInfo.Name))

let existedSatelliteLanguages =
satelliteWithFolders
|> Array.map (fun (_, dirInfo) -> dirInfo.Name)
|> Set.ofArray

project.FindLocalizedLanguageNames()
|> List.filter (existedSatelliteLanguages.Contains >> not)
|> List.iter (fun lang ->
traceWarnfn "Did not find satellite assembly for (%s) try building and running pack again." lang)

yield!
satelliteWithFolders
|> Array.map (fun (sa, dirInfo) -> (FileInfo sa, Path.Combine(targetDir, dirInfo.Name)))
}

let template =
Expand All @@ -261,34 +293,37 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
projects
|> List.map (fun proj -> proj.GetAssemblyName())

let additionalFiles =
assemblyNames
|> Seq.collect (fun assemblyFileName ->
let assemblyfi = FileInfo(assemblyFileName)
let name = Path.GetFileNameWithoutExtension assemblyfi.Name

let path = Path.Combine(projectDir, project.GetOutputDirectory config platform)

Directory.GetFiles(path, name + ".*")
|> Array.map (fun f -> FileInfo f)
|> Array.filter (fun fi ->
let isSameFileName = (Path.GetFileNameWithoutExtension fi.Name) = name
let validExtensions =
match template.Contents with
| CompleteInfo(core, optional) ->
if core.Symbols || optional.IncludePdbs then [".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
else [".xml"; ".dll"; ".exe";]
| ProjectInfo(core, optional) ->
if core.Symbols || optional.IncludePdbs then [".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
else [".xml"; ".dll"; ".exe";]
let isValidExtension =
validExtensions
|> List.exists (String.equalsIgnoreCase fi.Extension)
isSameFileName && isValidExtension))
let additionalFiles =
targetProfiles
|> Seq.collect (fun targetProfile ->
let targetDir = getTargetDir project targetProfile
let outputDir = project.GetOutputDirectory config platform targetProfile
let path = Path.Combine(projectDir, outputDir)
assemblyNames
|> Seq.collect (fun assemblyFileName ->
let assemblyfi = FileInfo(assemblyFileName)
let name = Path.GetFileNameWithoutExtension assemblyfi.Name

Directory.GetFiles(path, name + ".*")
|> Array.map (fun f -> (targetDir, FileInfo f))
|> Array.filter (fun (_, fi) ->
let isSameFileName = (Path.GetFileNameWithoutExtension fi.Name) = name
let validExtensions =
match template.Contents with
| CompleteInfo(core, optional) ->
if core.Symbols || optional.IncludePdbs then [".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
else [".xml"; ".dll"; ".exe";]
| ProjectInfo(core, optional) ->
if core.Symbols || optional.IncludePdbs then [".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
else [".xml"; ".dll"; ".exe";]
let isValidExtension =
validExtensions
|> List.exists (String.equalsIgnoreCase fi.Extension)
isSameFileName && isValidExtension)))
|> Seq.toArray

additionalFiles
|> Array.fold (fun template file -> addFile file.FullName targetDir template) template
|> Array.fold (fun template (targetDir, file) -> addFile file.FullName targetDir template) template

let templateWithOutputAndExcludes =
match template.Contents with
Expand All @@ -314,9 +349,16 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
|> List.fold addDependency templateWithOutputAndExcludes

// If project refs will not be packaged, add the assembly to the package
let withDepsAndIncluded =
files
|> List.fold (fun templatefile file -> addFile (toFile config platform file) targetDir templatefile) withDeps
let withDepsAndIncluded =
targetProfiles
|> List.collect (fun targetProfile ->
let targetDir = getTargetDir project targetProfile
files |>
List.map (fun file ->
let dependencyTargetProfiles = file.GetTargetProfiles()
let dependencyTargetProfile = findBestDependencyTargetProfile dependencyTargetProfiles targetProfile
(targetProfile, targetDir, file.GetOutputDirectory config platform dependencyTargetProfile, file)))
|> List.fold (fun templatefile (targetProfile, targetDir, outputDir, file) -> addFile (toFileWithOutputDirectory file outputDir) targetDir templatefile) withDeps

let lockFile =
dependenciesFile.FindLockFile().FullName
Expand Down
19 changes: 11 additions & 8 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,14 +1609,17 @@ module ProjectFile =
let getAssetsFileInfo (projectFileInfo:FileInfo) =
FileInfo(Path.Combine(projectFileInfo.Directory.FullName,"obj","project.assets.json"))

let getOutputDirectory buildConfiguration buildPlatform (project:ProjectFile) =
let targetFramework =
match getTargetFramework project with
| Some x -> x
let getOutputDirectory buildConfiguration buildPlatform (targetProfile : TargetProfile option) (project:ProjectFile) =
let targetFramework =
match targetProfile with
| Some x -> x.ToString()
| None ->
match getTargetFrameworksParsed project with
| fwk :: _ -> fwk
| [] -> ""
match getTargetFramework project with
| Some x -> x
| None ->
match getTargetFrameworksParsed project with
| fwk :: _ -> fwk
| [] -> ""

let platforms =
if not (String.IsNullOrWhiteSpace buildPlatform) then
Expand Down Expand Up @@ -1791,7 +1794,7 @@ type ProjectFile with

member this.DetermineBuildActionForRemoteItems fileName = ProjectFile.determineBuildActionForRemoteItems fileName this

member this.GetOutputDirectory buildConfiguration buildPlatform = ProjectFile.getOutputDirectory buildConfiguration buildPlatform this
member this.GetOutputDirectory buildConfiguration buildPlatform targetFramework = ProjectFile.getOutputDirectory buildConfiguration buildPlatform targetFramework this

member this.GetAssemblyName () = ProjectFile.getAssemblyName this

Expand Down
6 changes: 3 additions & 3 deletions tests/Paket.Tests/ProjectFile/OutputSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let ``should detect output path for proj file``
([<Values("Project1", "Project2", "Project3", "ProjectWithConditions")>] project)
([<Values("Debug", "Release", "dEbUg", "rElEaSe")>] configuration) =
ensureDir ()
let outPath = ProjectFile.TryLoad(sprintf "./ProjectFile/TestData/%s.fsprojtest" project).Value.GetOutputDirectory configuration ""
let outPath = ProjectFile.TryLoad(sprintf "./ProjectFile/TestData/%s.fsprojtest" project).Value.GetOutputDirectory configuration "" None
let expected = (System.IO.Path.Combine(@"bin", configuration) |> normalizePath)
outPath.ToLowerInvariant() |> shouldEqual (expected.ToLowerInvariant())

Expand All @@ -78,7 +78,7 @@ let ``should detect output path for netsdk csproj file``
ensureDir ()
let projectFile = ProjectFile.TryLoad(sprintf "./ProjectFile/TestData/%s" project).Value
let target = projectFile.GetTargetProfiles().Head.ToString()
let outPath = projectFile.GetOutputDirectory configuration ""
let outPath = projectFile.GetOutputDirectory configuration "" None
let expected = (System.IO.Path.Combine(@"bin", configuration, target) |> normalizePath)
outPath.ToLowerInvariant() |> shouldEqual (expected.ToLowerInvariant())

Expand All @@ -89,7 +89,7 @@ let ``should detect output path for netsdk with outputPath csproj file``
ensureDir ()
let projectFile = ProjectFile.TryLoad(sprintf "./ProjectFile/TestData/%s" project).Value
let target = projectFile.GetTargetProfiles().Head.ToString()
let outPath = projectFile.GetOutputDirectory configuration ""
let outPath = projectFile.GetOutputDirectory configuration "" None
let expected = (System.IO.Path.Combine(@"bin", configuration,"netstandard1.4_bin", target) |> normalizePath)
outPath.ToLowerInvariant() |> shouldEqual (expected.ToLowerInvariant())

Expand Down

0 comments on commit 71c150b

Please sign in to comment.