diff --git a/tests/pkg/assets/install3/gold/test.gold b/tests/pkg/assets/install3/gold/test.gold new file mode 100644 index 000000000..09b558757 --- /dev/null +++ b/tests/pkg/assets/install3/gold/test.gold @@ -0,0 +1,4 @@ +// Nothing to install. +================== +OK +[pkg, install] diff --git a/tests/pkg/assets/install3/main.toit b/tests/pkg/assets/install3/main.toit new file mode 100644 index 000000000..d2ebc0557 --- /dev/null +++ b/tests/pkg/assets/install3/main.toit @@ -0,0 +1,4 @@ +// Copyright (C) 2021 Toitware ApS. All rights reserved. + +main: + print "nothing to do" diff --git a/tests/pkg/assets/install3/package.yaml b/tests/pkg/assets/install3/package.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pkg/assets/install4/gold/test-0.gold b/tests/pkg/assets/install4/gold/test-0.gold new file mode 100644 index 000000000..69460fb68 --- /dev/null +++ b/tests/pkg/assets/install4/gold/test-0.gold @@ -0,0 +1,50 @@ +OK +[pkg, init] +================== +// No package installed yet. +================== +exec main.toit + +STDERR--- +main.toit:5:8: error: Package for prefix 'pkg4-pre' not found +import pkg4-pre.pkg4 + ^~~~~~~~ +main.toit:8:14: error: Unresolved identifier: 'identify' + print pkg4.identify + ^~~~~~~~ +Compilation failed +Exit Code: 1 +================== +exec main2.toit + +STDERR--- +main2.toit:5:8: error: Package for prefix 'pkg1' not found +import pkg1 + ^~~~ +main2.toit:8:14: error: Unresolved identifier: 'identify' + print pkg1.identify + ^~~~~~~~ +Compilation failed +Exit Code: 1 +================== +// Install pkg4 for 'main.toit', creating/updating a lock file. +================== +OK +[pkg, install, pkg4, --prefix=pkg4_pre] +Package 'pkg4@4.9.9' installed with prefix 'pkg4'. +================== +// main.toit should work now. +================== +exec main.toit +pkg4-4.9.9 +Exit Code: 0 +================== +OK +[pkg, install, pkg1] +Package 'pkg1@1.0.0' installed with prefix 'pkg1'. +================== +// main2.toit should also work now. +================== +exec main2.toit +pkg1-1.0.0pkg2-2.4.2pkg3-3.1.2 +Exit Code: 0 diff --git a/tests/pkg/assets/install4/gold/test-1.gold b/tests/pkg/assets/install4/gold/test-1.gold new file mode 100644 index 000000000..69460fb68 --- /dev/null +++ b/tests/pkg/assets/install4/gold/test-1.gold @@ -0,0 +1,50 @@ +OK +[pkg, init] +================== +// No package installed yet. +================== +exec main.toit + +STDERR--- +main.toit:5:8: error: Package for prefix 'pkg4-pre' not found +import pkg4-pre.pkg4 + ^~~~~~~~ +main.toit:8:14: error: Unresolved identifier: 'identify' + print pkg4.identify + ^~~~~~~~ +Compilation failed +Exit Code: 1 +================== +exec main2.toit + +STDERR--- +main2.toit:5:8: error: Package for prefix 'pkg1' not found +import pkg1 + ^~~~ +main2.toit:8:14: error: Unresolved identifier: 'identify' + print pkg1.identify + ^~~~~~~~ +Compilation failed +Exit Code: 1 +================== +// Install pkg4 for 'main.toit', creating/updating a lock file. +================== +OK +[pkg, install, pkg4, --prefix=pkg4_pre] +Package 'pkg4@4.9.9' installed with prefix 'pkg4'. +================== +// main.toit should work now. +================== +exec main.toit +pkg4-4.9.9 +Exit Code: 0 +================== +OK +[pkg, install, pkg1] +Package 'pkg1@1.0.0' installed with prefix 'pkg1'. +================== +// main2.toit should also work now. +================== +exec main2.toit +pkg1-1.0.0pkg2-2.4.2pkg3-3.1.2 +Exit Code: 0 diff --git a/tests/pkg/assets/install4/main.toit b/tests/pkg/assets/install4/main.toit new file mode 100644 index 000000000..1261ff701 --- /dev/null +++ b/tests/pkg/assets/install4/main.toit @@ -0,0 +1,8 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/LICENSE file. + +import pkg4-pre.pkg4 + +main: + print pkg4.identify diff --git a/tests/pkg/assets/install4/main2.toit b/tests/pkg/assets/install4/main2.toit new file mode 100644 index 000000000..639920025 --- /dev/null +++ b/tests/pkg/assets/install4/main2.toit @@ -0,0 +1,8 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/LICENSE file. + +import pkg1 + +main: + print pkg1.identify diff --git a/tests/pkg/install3-gold-test.toit b/tests/pkg/install3-gold-test.toit new file mode 100644 index 000000000..515c9c3a6 --- /dev/null +++ b/tests/pkg/install3-gold-test.toit @@ -0,0 +1,14 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/LICENSE file. + +import .gold-tester + +main args: + with-gold-tester args: test it + +test tester/GoldTester: + tester.gold "test" [ + ["// Nothing to install."], + ["pkg", "install"], + ] diff --git a/tests/pkg/install4-gold-test.toit b/tests/pkg/install4-gold-test.toit new file mode 100644 index 000000000..6cfd50acc --- /dev/null +++ b/tests/pkg/install4-gold-test.toit @@ -0,0 +1,32 @@ +// Copyright (C) 2025 Toit contributors. +// Use of this source code is governed by a Zero-Clause BSD license that can +// be found in the tests/LICENSE file. + +import host.file + +import .gold-tester + +main args: + with-gold-tester args --with-git-pkg-registry: | tester/GoldTester | + 2.repeat: | iteration/int | + test tester iteration + +test tester/GoldTester iteration/int: + if iteration == 1: + // Second round remove the package and lock file. + file.delete "$tester.working-dir/package.yaml" + file.delete "$tester.working-dir/package.lock" + + tester.gold "test-$iteration" [ + ["pkg", "init"], // So we don't accidentally use a /tmp/package.yaml. + ["// No package installed yet."], + ["exec", "main.toit"], + ["exec", "main2.toit"], + ["// Install pkg4 for 'main.toit', creating/updating a lock file."], + ["pkg", "install", "pkg4", "--prefix=pkg4_pre"], + ["// main.toit should work now."], + ["exec", "main.toit"], + ["pkg", "install", "pkg1"], + ["// main2.toit should also work now."], + ["exec", "main2.toit"], + ] diff --git a/tools/pkg/commands/install.toit b/tools/pkg/commands/install.toit index ca5815036..7b04305f8 100644 --- a/tools/pkg/commands/install.toit +++ b/tools/pkg/commands/install.toit @@ -60,10 +60,7 @@ class InstallCommand extends PkgProjectCommand: execute: if not package: - if recompute: - project.install --recompute=recompute --registries=registries - else: - project.install + project.install --recompute=recompute --registries=registries else if not local: execute-remote else: diff --git a/tools/pkg/project/project.toit b/tools/pkg/project/project.toit index 395936acf..313c3e955 100644 --- a/tools/pkg/project/project.toit +++ b/tools/pkg/project/project.toit @@ -117,12 +117,10 @@ class Project: solve_ --update-everything --registries=registries save - install --recompute/True --registries/Registries -> none: - solve_ --no-update-everything --registries=registries - save - lock-file.install - - install --recompute/bool=false -> none: + install --recompute/bool --registries/Registries -> none: + if recompute or not lock-file: + solve_ --no-update-everything --registries=registries + save lock-file.install clean -> none: