@@ -8,6 +8,7 @@ open NUnit.Framework
88open FsUnit
99open System
1010open System.IO
11+ open System.IO .Compression
1112open Paket.Logging
1213
1314let disableScenarioCleanup = false // change to true to debug a single test temporarily.
@@ -86,19 +87,98 @@ let prepare scenario =
8687 if not ( isNull shouldDispose) then shouldDispose.Dispose()
8788
8889
89- let prepareSdk scenario =
90+ let private copyRestoreTargets scenario =
9091 let tmpPaketFolder = ( scenarioTempPath scenario) @@ " .paket"
9192 let targetsFile = FullName(__ SOURCE_ DIRECTORY__ + " ../../../src/Paket.Core/embedded/Paket.Restore.targets" )
92- let paketExe = snd paketToolPath
93-
94- setEnvironVar " PaketExePath" paketExe
95- let cleanup = prepare scenario
9693 if ( not ( Directory.Exists tmpPaketFolder)) then
9794 Directory.CreateDirectory tmpPaketFolder |> ignore
9895
9996 FileHelper.CopyFile tmpPaketFolder targetsFile
97+
98+ let prepareSdk scenario =
99+ let paketExe = snd paketToolPath
100+
101+ setEnvironVar " PaketExePath" paketExe
102+ let cleanup = prepare scenario
103+ copyRestoreTargets scenario
100104 cleanup
101105
106+ /// The version of the Paket tool package packTool makes. Any version does: the package is made
107+ /// again for each test, from the build under test, and installed into a scenario folder.
108+ let paketToolPackageVersion = " 0.0.0-integrationtest"
109+
110+ /// Packs the paket of bin/net10.0 as a .NET tool into the folder, the way PackAsTool lays it out
111+ let private packTool folder =
112+ let toolDir = FullName(__ SOURCE_ DIRECTORY__ + " ../../../bin/net10.0" )
113+ Directory.CreateDirectory folder |> ignore
114+ use zip = ZipFile.Open( folder @@ $" Paket.%s {paketToolPackageVersion}.nupkg" , ZipArchiveMode.Create)
115+ let addText ( name : string ) ( text : string ) =
116+ use writer = new StreamWriter( zip.CreateEntry( name) .Open())
117+ writer.Write text
118+ addText " Paket.nuspec" ( sprintf """ <?xml version="1.0" encoding="utf-8"?>
119+ <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
120+ <metadata>
121+ <id>Paket</id>
122+ <version>%s </version>
123+ <authors>Paket</authors>
124+ <description>The paket under test, packed as a .NET tool</description>
125+ <packageTypes>
126+ <packageType name="DotnetTool" />
127+ </packageTypes>
128+ </metadata>
129+ </package>
130+ """ paketToolPackageVersion)
131+ addText " tools/net10.0/any/DotnetToolSettings.xml" """ <?xml version="1.0" encoding="utf-8"?>
132+ <DotNetCliTool Version="1">
133+ <Commands>
134+ <Command Name="paket" EntryPoint="paket.dll" Runner="dotnet" />
135+ </Commands>
136+ </DotNetCliTool>
137+ """
138+ for file in Directory.GetFiles( toolDir, " *" , SearchOption.AllDirectories) do
139+ let relativePath = file.Substring( toolDir.Length) .TrimStart( Path.DirectorySeparatorChar) .Replace( '\\' , '/' )
140+ zip.CreateEntryFromFile( file, " tools/net10.0/any/" + relativePath) |> ignore
141+
142+ /// Like prepareSdk, but lets Paket.Restore.targets find paket on its own, the way it does
143+ /// for a user of the Paket .NET tool. Returns the cleanup, the full version of the paket
144+ /// under test (with its "+<commit >"), and the environment to run dotnet with.
145+ /// The tool is packed from bin/net10.0 into a feed of the scenario, the only source of its
146+ /// nuget.config, and installed into a packages folder of the scenario: the global one may
147+ /// hold a package of the same version.
148+ let prepareSdkForTool scenario =
149+ let productVersion =
150+ Diagnostics.FileVersionInfo.GetVersionInfo( FullName(__ SOURCE_ DIRECTORY__ + " ../../../bin/net10.0/paket.dll" )) .ProductVersion
151+
152+ let cleanup = prepare scenario
153+ copyRestoreTargets scenario
154+ let scenarioPath = scenarioTempPath scenario
155+ let feed = scenarioPath @@ " tool-feed"
156+ packTool feed
157+ File.WriteAllText(
158+ scenarioPath @@ " nuget.config" ,
159+ sprintf """ <?xml version="1.0" encoding="utf-8"?>
160+ <configuration>
161+ <packageSources>
162+ <clear />
163+ <add key="paket-build" value="%s " />
164+ </packageSources>
165+ </configuration>
166+ """ feed)
167+ // A manifest of its own, so that dotnet doesn't walk up to the one of the Paket repository,
168+ // neither to run `dotnet paket` nor to install a local tool
169+ Directory.CreateDirectory( scenarioPath @@ " .config" ) |> ignore
170+ File.WriteAllText( scenarioPath @@ " .config" @@ " dotnet-tools.json" , """ { "version": 1, "isRoot": true, "tools": {} }""" )
171+
172+ let env = [
173+ " NUGET_PACKAGES" , scenarioPath @@ " nuget-packages"
174+ // prepareSdk sets it for the whole test process
175+ " PaketExePath" , " "
176+ // The Linux CI sets it, and it makes the restore ask for Microsoft.WindowsDesktop.App.Ref,
177+ // which the feed of the scenario doesn't have
178+ " EnableWindowsTargeting" , " false"
179+ ]
180+ cleanup, productVersion, env
181+
102182type OutputMsg =
103183 { IsError : bool ; Message : string }
104184 static member isError ({ IsError = e }: OutputMsg ) = e
0 commit comments