@@ -69,6 +69,7 @@ import (
6969 "github.com/pkg/errors"
7070 "github.com/spdx/tools-golang/spdx"
7171 "github.com/stretchr/testify/require"
72+ "github.com/tonistiigi/fsutil"
7273 "golang.org/x/crypto/ssh/agent"
7374 "golang.org/x/sync/errgroup"
7475 "google.golang.org/grpc"
@@ -210,6 +211,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
210211 testSnapshotWithMultipleBlobs ,
211212 testExportLocalNoPlatformSplit ,
212213 testExportLocalNoPlatformSplitOverwrite ,
214+ testSolverOptLocalDirsStillWorks ,
213215}
214216
215217func TestIntegration (t * testing.T ) {
@@ -272,9 +274,9 @@ func testCacheExportCacheKeyLoop(t *testing.T, sb integration.Sandbox) {
272274 require .NoError (t , err )
273275 defer c .Close ()
274276
275- tmpdir := t . TempDir ( )
277+ tmpdir := integration . Tmpdir ( t )
276278
277- err = os .WriteFile (filepath .Join (tmpdir , "foo" ), []byte ("foodata" ), 0600 )
279+ err = os .WriteFile (filepath .Join (tmpdir . Name , "foo" ), []byte ("foodata" ), 0600 )
278280 require .NoError (t , err )
279281
280282 for _ , mode := range []bool {false , true } {
@@ -295,11 +297,11 @@ func testCacheExportCacheKeyLoop(t *testing.T, sb integration.Sandbox) {
295297 {
296298 Type : "local" ,
297299 Attrs : map [string ]string {
298- "dest" : filepath .Join (tmpdir , "cache" ),
300+ "dest" : filepath .Join (tmpdir . Name , "cache" ),
299301 },
300302 },
301303 },
302- LocalDirs : map [string ]string {
304+ LocalMounts : map [string ]fsutil. FS {
303305 "mylocal" : tmpdir ,
304306 },
305307 }, nil )
@@ -1515,7 +1517,7 @@ func testLocalSymlinkEscape(t *testing.T, sb integration.Sandbox) {
15151517 require .NoError (t , err )
15161518
15171519 _ , err = c .Solve (sb .Context (), def , SolveOpt {
1518- LocalDirs : map [string ]string {
1520+ LocalMounts : map [string ]fsutil. FS {
15191521 "mylocal" : dir ,
15201522 },
15211523 }, nil )
@@ -1554,6 +1556,49 @@ func testRelativeWorkDir(t *testing.T, sb integration.Sandbox) {
15541556 require .Equal (t , []byte ("/test1/test2\n " ), dt )
15551557}
15561558
1559+ // TODO: remove this test once `client.SolveOpt.LocalDirs`, now marked as deprecated, is removed.
1560+ // For more context on this test, please check:
1561+ // https://github.com/moby/buildkit/pull/4583#pullrequestreview-1847043452
1562+ func testSolverOptLocalDirsStillWorks (t * testing.T , sb integration.Sandbox ) {
1563+ integration .SkipOnPlatform (t , "windows" )
1564+
1565+ c , err := New (sb .Context (), sb .Address ())
1566+ require .NoError (t , err )
1567+ defer c .Close ()
1568+
1569+ out := llb .Image ("docker.io/library/busybox:latest" ).
1570+ File (llb .Copy (llb .Local ("mylocal" ), "input.txt" , "input.txt" )).
1571+ Run (llb .Shlex (`sh -c "/bin/rev < input.txt > /out/output.txt"` )).
1572+ AddMount (`/out` , llb .Scratch ())
1573+
1574+ def , err := out .Marshal (sb .Context ())
1575+ require .NoError (t , err )
1576+
1577+ srcDir := integration .Tmpdir (t ,
1578+ fstest .CreateFile ("input.txt" , []byte ("Hello World" ), 0600 ),
1579+ )
1580+
1581+ destDir := integration .Tmpdir (t )
1582+
1583+ _ , err = c .Solve (sb .Context (), def , SolveOpt {
1584+ LocalDirs : map [string ]string {
1585+ "mylocal" : srcDir .Name ,
1586+ },
1587+ Exports : []ExportEntry {
1588+ {
1589+ Type : ExporterLocal ,
1590+ OutputDir : destDir .Name ,
1591+ },
1592+ },
1593+ }, nil )
1594+
1595+ require .NoError (t , err )
1596+
1597+ dt , err := os .ReadFile (filepath .Join (destDir .Name , "output.txt" ))
1598+ require .NoError (t , err )
1599+ require .Equal (t , []byte ("dlroW olleH" ), dt )
1600+ }
1601+
15571602func testFileOpMkdirMkfile (t * testing.T , sb integration.Sandbox ) {
15581603 requiresLinux (t )
15591604 c , err := New (sb .Context (), sb .Address ())
@@ -1624,7 +1669,7 @@ func testFileOpCopyRm(t *testing.T, sb integration.Sandbox) {
16241669 OutputDir : destDir ,
16251670 },
16261671 },
1627- LocalDirs : map [string ]string {
1672+ LocalMounts : map [string ]fsutil. FS {
16281673 "mylocal" : dir ,
16291674 "mylocal2" : dir2 ,
16301675 },
@@ -1751,7 +1796,7 @@ func testFileOpCopyIncludeExclude(t *testing.T, sb integration.Sandbox) {
17511796 OutputDir : destDir ,
17521797 },
17531798 },
1754- LocalDirs : map [string ]string {
1799+ LocalMounts : map [string ]fsutil. FS {
17551800 "mylocal" : dir ,
17561801 },
17571802 }, nil )
@@ -1772,7 +1817,7 @@ func testFileOpCopyIncludeExclude(t *testing.T, sb integration.Sandbox) {
17721817 // Create additional file which doesn't match the include pattern, and make
17731818 // sure this doesn't invalidate the cache.
17741819
1775- err = fstest .Apply (fstest .CreateFile ("unmatchedfile" , []byte ("data1" ), 0600 )).Apply (dir )
1820+ err = fstest .Apply (fstest .CreateFile ("unmatchedfile" , []byte ("data1" ), 0600 )).Apply (dir . Name )
17761821 require .NoError (t , err )
17771822
17781823 st = llb .Scratch ().File (
@@ -1798,7 +1843,7 @@ func testFileOpCopyIncludeExclude(t *testing.T, sb integration.Sandbox) {
17981843 OutputDir : destDir ,
17991844 },
18001845 },
1801- LocalDirs : map [string ]string {
1846+ LocalMounts : map [string ]fsutil. FS {
18021847 "mylocal" : dir ,
18031848 },
18041849 }, nil )
@@ -1861,7 +1906,7 @@ func testLocalSourceWithDiffer(t *testing.T, sb integration.Sandbox, d llb.DiffT
18611906
18621907 tv := syscall .NsecToTimespec (time .Now ().UnixNano ())
18631908
1864- err = syscall .UtimesNano (filepath .Join (dir , "foo" ), []syscall.Timespec {tv , tv })
1909+ err = syscall .UtimesNano (filepath .Join (dir . Name , "foo" ), []syscall.Timespec {tv , tv })
18651910 require .NoError (t , err )
18661911
18671912 st := llb .Local ("mylocal" + string (d ), llb .Differ (d , false ))
@@ -1878,7 +1923,7 @@ func testLocalSourceWithDiffer(t *testing.T, sb integration.Sandbox, d llb.DiffT
18781923 OutputDir : destDir ,
18791924 },
18801925 },
1881- LocalDirs : map [string ]string {
1926+ LocalMounts : map [string ]fsutil. FS {
18821927 "mylocal" + string (d ): dir ,
18831928 },
18841929 }, nil )
@@ -1888,10 +1933,10 @@ func testLocalSourceWithDiffer(t *testing.T, sb integration.Sandbox, d llb.DiffT
18881933 require .NoError (t , err )
18891934 require .Equal (t , []byte ("foo" ), dt )
18901935
1891- err = os .WriteFile (filepath .Join (dir , "foo" ), []byte ("bar" ), 0600 )
1936+ err = os .WriteFile (filepath .Join (dir . Name , "foo" ), []byte ("bar" ), 0600 )
18921937 require .NoError (t , err )
18931938
1894- err = syscall .UtimesNano (filepath .Join (dir , "foo" ), []syscall.Timespec {tv , tv })
1939+ err = syscall .UtimesNano (filepath .Join (dir . Name , "foo" ), []syscall.Timespec {tv , tv })
18951940 require .NoError (t , err )
18961941
18971942 _ , err = c .Solve (context .TODO (), def , SolveOpt {
@@ -1901,7 +1946,7 @@ func testLocalSourceWithDiffer(t *testing.T, sb integration.Sandbox, d llb.DiffT
19011946 OutputDir : destDir ,
19021947 },
19031948 },
1904- LocalDirs : map [string ]string {
1949+ LocalMounts : map [string ]fsutil. FS {
19051950 "mylocal" + string (d ): dir ,
19061951 },
19071952 }, nil )
@@ -2211,7 +2256,7 @@ func testFileOpRmWildcard(t *testing.T, sb integration.Sandbox) {
22112256 OutputDir : destDir ,
22122257 },
22132258 },
2214- LocalDirs : map [string ]string {
2259+ LocalMounts : map [string ]fsutil. FS {
22152260 "mylocal" : dir ,
22162261 },
22172262 }, nil )
@@ -7658,7 +7703,7 @@ func testParallelLocalBuilds(t *testing.T, sb integration.Sandbox) {
76587703 OutputDir : destDir ,
76597704 },
76607705 },
7661- LocalDirs : map [string ]string {
7706+ LocalMounts : map [string ]fsutil. FS {
76627707 "source" : srcDir ,
76637708 },
76647709 }, nil )
@@ -9713,7 +9758,7 @@ func ensureFileContents(t *testing.T, path, expectedContents string) {
97139758
97149759func makeSSHAgentSock (t * testing.T , agent agent.Agent ) (p string , err error ) {
97159760 tmpDir := integration .Tmpdir (t )
9716- sockPath := filepath .Join (tmpDir , "ssh_auth_sock" )
9761+ sockPath := filepath .Join (tmpDir . Name , "ssh_auth_sock" )
97179762
97189763 l , err := net .Listen ("unix" , sockPath )
97199764 if err != nil {
0 commit comments