From e4c8dcd553232505ff2f922c572f8203a69bf43c Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Wed, 13 Mar 2024 23:50:38 +0200 Subject: [PATCH] Fix lockfile not updating when a local package set changed on disk (#1201) --- README.md | 6 +- src/Spago/Config.purs | 6 ++ .../local-package-set.json | 10 +++ .../new-package-set.json | 11 +++ .../local-package-set-lockfile/spago.lock.new | 42 ++++++++++ .../local-package-set-lockfile/spago.lock.old | 41 ++++++++++ .../local-package-set-lockfile/spago.yaml | 10 +++ test/Spago/Build.purs | 76 +++++++++++-------- 8 files changed, 165 insertions(+), 37 deletions(-) create mode 100644 test-fixtures/build/local-package-set-lockfile/local-package-set.json create mode 100644 test-fixtures/build/local-package-set-lockfile/new-package-set.json create mode 100644 test-fixtures/build/local-package-set-lockfile/spago.lock.new create mode 100644 test-fixtures/build/local-package-set-lockfile/spago.lock.old create mode 100644 test-fixtures/build/local-package-set-lockfile/spago.yaml diff --git a/README.md b/README.md index f8a7b5255..5f5aa1209 100644 --- a/README.md +++ b/README.md @@ -1231,11 +1231,9 @@ workspace: registry: 11.10.0 # Or it could just point to a URL of a custom package set # See the "Custom package sets" section for more info on making one. - # The `hash` field is actually optional and you should not add it. - # It will be tacked on by Spago, to not download the set over and over. - # Remove this field if you'd like Spago to fetch from the remote again. url: https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.7-20230207/packages.json - hash: sha256-UZaygzoqEhhYh2lzUqbiNfOR9J+WNRc9SkQPmoo90jM= + # It is also possible to point to a local package set instead: + path: ./my-custom-package-set.json # This section defines any other packages that you'd like to include # in the build. It's optional, in case you just want to use the ones diff --git a/src/Spago/Config.purs b/src/Spago/Config.purs index c43f56b25..f2f53a451 100644 --- a/src/Spago/Config.purs +++ b/src/Spago/Config.purs @@ -435,6 +435,12 @@ shouldComputeNewLockfile { workspace, workspacePackages } workspaceLock = || (fromMaybe Map.empty workspace.extra_packages /= workspaceLock.extra_packages) -- and the package set address needs to match - we have no way to match the package set contents at this point, so we let it be || (workspace.package_set /= map _.address workspaceLock.package_set) + -- and the package set is not a local file - if it is then we always recompute the lockfile because we have no way to check if it's changed + || + ( case workspace.package_set of + Just (Core.SetFromPath _) -> true + _ -> false + ) getPackageLocation :: PackageName -> Package -> FilePath getPackageLocation name = Paths.mkRelative <<< case _ of diff --git a/test-fixtures/build/local-package-set-lockfile/local-package-set.json b/test-fixtures/build/local-package-set-lockfile/local-package-set.json new file mode 100644 index 000000000..84ca9df03 --- /dev/null +++ b/test-fixtures/build/local-package-set-lockfile/local-package-set.json @@ -0,0 +1,10 @@ +{ + "compiler": "0.15.10", + "published": "2023-09-30", + "version": "1.0.0", + "packages": { + "prelude": "6.0.1", + "console": "6.1.0", + "effect": "4.0.0" + } +} diff --git a/test-fixtures/build/local-package-set-lockfile/new-package-set.json b/test-fixtures/build/local-package-set-lockfile/new-package-set.json new file mode 100644 index 000000000..cf5149834 --- /dev/null +++ b/test-fixtures/build/local-package-set-lockfile/new-package-set.json @@ -0,0 +1,11 @@ +{ + "compiler": "0.15.10", + "published": "2023-09-30", + "version": "1.0.0", + "packages": { + "prelude": "6.0.1", + "typelevel-prelude": "7.0.0", + "console": "6.1.0", + "effect": "4.0.0" + } +} diff --git a/test-fixtures/build/local-package-set-lockfile/spago.lock.new b/test-fixtures/build/local-package-set-lockfile/spago.lock.new new file mode 100644 index 000000000..3fce14642 --- /dev/null +++ b/test-fixtures/build/local-package-set-lockfile/spago.lock.new @@ -0,0 +1,42 @@ +workspace: + packages: + local-package-set-lockfile: + path: ./ + dependencies: + - console + - effect + - prelude + test_dependencies: [] + build_plan: + - console + - effect + - prelude + package_set: + address: + path: ./local-package-set.json + compiler: ">=0.15.10 <0.16.0" + content: + console: 6.1.0 + effect: 4.0.0 + prelude: 6.0.1 + typelevel-prelude: 7.0.0 + extra_packages: {} +packages: + console: + type: registry + version: 6.1.0 + integrity: sha256-CxmAzjgyuGDmt9FZW51VhV6rBPwR6o0YeKUzA9rSzcM= + dependencies: + - effect + - prelude + effect: + type: registry + version: 4.0.0 + integrity: sha256-eBtZu+HZcMa5HilvI6kaDyVX3ji8p0W9MGKy2K4T6+M= + dependencies: + - prelude + prelude: + type: registry + version: 6.0.1 + integrity: sha256-o8p6SLYmVPqzXZhQFd2hGAWEwBoXl1swxLG/scpJ0V0= + dependencies: [] diff --git a/test-fixtures/build/local-package-set-lockfile/spago.lock.old b/test-fixtures/build/local-package-set-lockfile/spago.lock.old new file mode 100644 index 000000000..7d6878645 --- /dev/null +++ b/test-fixtures/build/local-package-set-lockfile/spago.lock.old @@ -0,0 +1,41 @@ +workspace: + packages: + local-package-set-lockfile: + path: ./ + dependencies: + - console + - effect + - prelude + test_dependencies: [] + build_plan: + - console + - effect + - prelude + package_set: + address: + path: ./local-package-set.json + compiler: ">=0.15.10 <0.16.0" + content: + console: 6.1.0 + effect: 4.0.0 + prelude: 6.0.1 + extra_packages: {} +packages: + console: + type: registry + version: 6.1.0 + integrity: sha256-CxmAzjgyuGDmt9FZW51VhV6rBPwR6o0YeKUzA9rSzcM= + dependencies: + - effect + - prelude + effect: + type: registry + version: 4.0.0 + integrity: sha256-eBtZu+HZcMa5HilvI6kaDyVX3ji8p0W9MGKy2K4T6+M= + dependencies: + - prelude + prelude: + type: registry + version: 6.0.1 + integrity: sha256-o8p6SLYmVPqzXZhQFd2hGAWEwBoXl1swxLG/scpJ0V0= + dependencies: [] diff --git a/test-fixtures/build/local-package-set-lockfile/spago.yaml b/test-fixtures/build/local-package-set-lockfile/spago.yaml new file mode 100644 index 000000000..6665bc460 --- /dev/null +++ b/test-fixtures/build/local-package-set-lockfile/spago.yaml @@ -0,0 +1,10 @@ +package: + name: local-package-set-lockfile + dependencies: + - console + - effect + - prelude +workspace: + package_set: + path: ./local-package-set.json + extra_packages: {} diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index 5d09a0c27..7bd842bb3 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -101,35 +101,45 @@ spec = Spec.around withTempDir do } spago [ "build" ] >>= shouldBeFailure - Spec.it "building with a lockfile doesn't need the Registry repo" \{ spago, fixture } -> do - spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess - spago [ "build" ] >>= shouldBeSuccess - -- Check that we have written the lockfile - checkFixture "spago.lock" (fixture "spago.lock") - -- Then remove the registry repo - FSA.rm' Paths.registryPath { force: true, recursive: true, retryDelay: 0, maxRetries: 0 } - -- And check that we can still build - spago [ "build" ] >>= shouldBeSuccess - -- And that we still don't have the registry - FS.exists Paths.registryPath `Assert.shouldReturn` false - - Spec.it "using the --pure flag does not refresh the lockfile" \{ spago, fixture } -> do - spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess - spago [ "build" ] >>= shouldBeSuccess - -- Check that we have written the lockfile - checkFixture "spago.lock" (fixture "spago.lock") - -- Update the config - let - conf = Init.defaultConfig - { name: mkPackageName "aaa" - , testModuleName: "Test.Main" - , withWorkspace: Just { setVersion: Just $ mkVersion "33.0.0" } - } - FS.writeYamlFile Config.configCodec "spago.yaml" - (conf { package = conf.package # map (\pkg -> pkg { dependencies = pkg.dependencies <> mkDependencies [ "maybe" ] }) }) - -- Check that building with --pure does not refresh the lockfile - spago [ "build", "--pure" ] >>= shouldBeSuccess - checkFixture "spago.lock" (fixture "spago.lock") + Spec.describe "lockfile" do + Spec.it "building with a lockfile doesn't need the Registry repo" \{ spago, fixture } -> do + spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess + spago [ "build" ] >>= shouldBeSuccess + -- Check that we have written the lockfile + checkFixture "spago.lock" (fixture "spago.lock") + -- Then remove the registry repo + FSA.rm' Paths.registryPath { force: true, recursive: true, retryDelay: 0, maxRetries: 0 } + -- And check that we can still build + spago [ "build" ] >>= shouldBeSuccess + -- And that we still don't have the registry + FS.exists Paths.registryPath `Assert.shouldReturn` false + + Spec.it "using the --pure flag does not refresh the lockfile" \{ spago, fixture } -> do + spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess + spago [ "build" ] >>= shouldBeSuccess + -- Check that we have written the lockfile + checkFixture "spago.lock" (fixture "spago.lock") + -- Update the config + let + conf = Init.defaultConfig + { name: mkPackageName "aaa" + , testModuleName: "Test.Main" + , withWorkspace: Just { setVersion: Just $ mkVersion "33.0.0" } + } + FS.writeYamlFile Config.configCodec "spago.yaml" + (conf { package = conf.package # map (\pkg -> pkg { dependencies = pkg.dependencies <> mkDependencies [ "maybe" ] }) }) + -- Check that building with --pure does not refresh the lockfile + spago [ "build", "--pure" ] >>= shouldBeSuccess + checkFixture "spago.lock" (fixture "spago.lock") + + Spec.it "lockfile is refreshed when the local package set changes" \{ spago, fixture } -> do + FS.copyTree { src: fixture "build/local-package-set-lockfile", dst: "." } + spago [ "build" ] >>= shouldBeSuccess + checkFixture "spago.lock" (fixture "build/local-package-set-lockfile/spago.lock.old") + FS.moveSync { src: "local-package-set.json", dst: "old-package-set.json" } + FS.moveSync { src: "new-package-set.json", dst: "local-package-set.json" } + spago [ "build" ] >>= shouldBeSuccess + checkFixture "spago.lock" (fixture "build/local-package-set-lockfile/spago.lock.new") Spec.it "compiles with the specified backend" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess @@ -164,10 +174,10 @@ spec = Spec.around withTempDir do Spec.it "failed build with many warnings and --json-errors does not truncate output" \{ spago, fixture } -> do FS.copyTree { src: fixture "build/json-truncated-many-warnings", dst: "." } - spago [ "build", "--json-errors" ] >>= shouldBeFailureOutput case Process.platform of - Just Platform.Win32 -> fixture "build/json-truncated-many-warnings/warnings-windows.json" - _ -> fixture "build/json-truncated-many-warnings/warnings.json" - + spago [ "build", "--json-errors" ] >>= shouldBeFailureOutput case Process.platform of + Just Platform.Win32 -> fixture "build/json-truncated-many-warnings/warnings-windows.json" + _ -> fixture "build/json-truncated-many-warnings/warnings.json" + Pedantic.spec Monorepo.spec