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

do not evaluate all templates with --template switch #2769

Merged
merged 2 commits into from Sep 18, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -23,6 +23,9 @@ build/
[Bb]in/
[Oo]bj/

# Enable scenarios in integration tests
!integrationtests/scenarios/*/before/**
Copy link
Member

Choose a reason for hiding this comment

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

is this a good thing!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as i understand, idea is - all files in "test-scenario/before" folder is "setup" for test.
I think it's slightly easier to remove .idea, .dotsettings etc from commit than add ignored dlls/pdbs.


# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

Expand Down
11 changes: 10 additions & 1 deletion integrationtests/Paket.IntegrationTests/PackSpecs.fs
Expand Up @@ -530,4 +530,13 @@ let ``#2694 paket fixnuspec should not remove project references``() =
// Should we remove Microsoft.NETCore.App?
// Problably not as "packaged" console applications have this dependency by default, see https://www.nuget.org/packages/dotnet-mergenupkg
nuspec.Dependencies.Length
|> shouldEqual 3
|> shouldEqual 3

[<Test>]
let ``#2765 pack single template does not evaluate other template`` () =
let scenario = "i002765-evaluate-only-single-template"
let rootPath = scenarioTempPath scenario
let outPath = Path.Combine(rootPath, "out")
let templatePath = Path.Combine(rootPath, "projectA", "paket.template")
Assert.DoesNotThrow(fun () -> paket ("pack --template " + templatePath + " \"" + outPath + "\"") scenario |> ignore)
CleanDir rootPath
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C22432B4-67E4-42D2-83FF-8F3A473EA8C5}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ProjectA</RootNamespace>
<AssemblyName>ProjectA</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="paket.template" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ProjectA")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ProjectA")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("C22432B4-67E4-42D2-83FF-8F3A473EA8C5")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
@@ -0,0 +1,3 @@
type project
description test
authors test
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D765F8AE-8018-4592-9E42-0FC51995A067}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ProjectB</RootNamespace>
<AssemblyName>ProjectB</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="paket.template" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ProjectB")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ProjectB")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("D765F8AE-8018-4592-9E42-0FC51995A067")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,3 @@
type project
description test
authors test
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.0.0
MinimumVisualStudioVersion = 10.0.0.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectA", "ProjectA\ProjectA.csproj", "{C22432B4-67E4-42D2-83FF-8F3A473EA8C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectB", "ProjectB\ProjectB.csproj", "{D765F8AE-8018-4592-9E42-0FC51995A067}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C22432B4-67E4-42D2-83FF-8F3A473EA8C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C22432B4-67E4-42D2-83FF-8F3A473EA8C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C22432B4-67E4-42D2-83FF-8F3A473EA8C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C22432B4-67E4-42D2-83FF-8F3A473EA8C5}.Release|Any CPU.Build.0 = Release|Any CPU
{D765F8AE-8018-4592-9E42-0FC51995A067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D765F8AE-8018-4592-9E42-0FC51995A067}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D765F8AE-8018-4592-9E42-0FC51995A067}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D765F8AE-8018-4592-9E42-0FC51995A067}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1 @@
source https://www.nuget.org/api/v2
@@ -0,0 +1 @@

30 changes: 17 additions & 13 deletions src/Paket.Core/Packaging/PackageMetaData.fs
Expand Up @@ -159,7 +159,7 @@ 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 findDependencies (dependenciesFile : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies minimumFromLockFile pinProjectReferences (projectWithTemplates : Map<string, TemplateFile * ProjectFile * bool>) includeReferencedProjects (version :SemVerInfo option) specificVersions (projDeps) =
let findDependencies (dependenciesFile : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies minimumFromLockFile pinProjectReferences (projectWithTemplates : Map<string, (Lazy<'TemplateFile>) * ProjectFile * bool>) includeReferencedProjects (version :SemVerInfo option) specificVersions (projDeps) =
let includeReferencedProjects = template.IncludeReferencedProjects || includeReferencedProjects
let targetDir =
match project.OutputType with
Expand Down Expand Up @@ -267,15 +267,16 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
let withDeps =
deps
|> List.map (fun (templateFile, _) ->
match templateFile with
let evaluatedTemplate = templateFile.Force()
match evaluatedTemplate with
| CompleteTemplate(core, _) ->
match core.Version with
| Some v ->
let versionConstraint = if lockDependencies || pinProjectReferences then Specific v else Minimum v
PackageName core.Id, VersionRequirement(versionConstraint, getPreReleaseStatus v)
| None -> failwithf "There was no version given for %s." templateFile.FileName
| None -> failwithf "There was no version given for %s." evaluatedTemplate.FileName
| IncompleteTemplate ->
failwithf "You cannot create a dependency on a template file (%s) with incomplete metadata." templateFile.FileName)
failwithf "You cannot create a dependency on a template file (%s) with incomplete metadata." evaluatedTemplate.FileName)
|> List.fold addDependency templateWithOutputAndExcludes

// If project refs will not be packaged, add the assembly to the package
Expand All @@ -300,15 +301,18 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
[if includeReferencedProjects then
for proj in project.GetAllReferencedProjects(false,projDeps) |> Seq.filter ((<>) project) do
match Map.tryFind proj.FileName projectWithTemplates with
| Some ({ Contents = CompleteInfo(core, _) }, _, _) ->
let versionConstraint =
match core.Version with
| Some v ->
let vr = if lockDependencies || pinProjectReferences then Specific v else Minimum v
VersionRequirement(vr, getPreReleaseStatus v)
| None -> VersionRequirement.AllReleases

yield None, { Name = PackageName core.Id; Settings = InstallSettings.Default }, Some versionConstraint
| Some (template, _, _) ->
match template.Force() with
| { Contents = CompleteInfo(core, _) } ->
let versionConstraint =
match core.Version with
| Some v ->
let vr = if lockDependencies || pinProjectReferences then Specific v else Minimum v
VersionRequirement(vr, getPreReleaseStatus v)
| None -> VersionRequirement.AllReleases

yield None, { Name = PackageName core.Id; Settings = InstallSettings.Default }, Some versionConstraint
| _ -> yield! getPackages proj
| _ -> yield! getPackages proj
yield! getPackages project]

Expand Down
7 changes: 3 additions & 4 deletions src/Paket.Core/Packaging/PackageProcess.fs
Expand Up @@ -171,11 +171,10 @@ let Pack(workingDir,dependenciesFile : DependenciesFile, packageOutputPath, buil
| _ -> true)
|> Array.map (fun (projectFile,templateFile') ->
allTemplateFiles.Remove(templateFile'.FileName) |> ignore

let merged = merge buildConfig buildPlatform version specificVersions projectFile templateFile'
let merged = lazy (merge buildConfig buildPlatform version specificVersions projectFile templateFile')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea of this fix is here - make "dangerous" operation lazy.
So exception only occur if project will actually be needed for packing.

let willBePacked =
match templateFile with
| Some file -> normalizePath (Path.GetFullPath file) = normalizePath (Path.GetFullPath merged.FileName)
| Some file -> normalizePath (Path.GetFullPath file) = normalizePath (Path.GetFullPath templateFile'.FileName)
| None -> true

Path.GetFullPath projectFile.FileName |> normalizePath,(merged,projectFile,willBePacked))
Expand Down Expand Up @@ -210,7 +209,7 @@ let Pack(workingDir,dependenciesFile : DependenciesFile, packageOutputPath, buil
|> Map.toList
|> Seq.collect(fun (_,(t, p, _)) ->
seq {
for template in optWithSymbols p t do
for template in optWithSymbols p (t.Force()) do
yield template, p
}
)
Expand Down