digital-asset / daml

The Daml smart contract language
https://www.digitalasset.com/developers
797 stars 199 forks source link

`module-prefixes` change is ignored by `daml build` #17313

Open akrmn opened 1 year ago

akrmn commented 1 year ago

Adding a module-prefixes entry to the daml.yaml file of a project that has previously been built results in spurious errors because the module-prefixes are ignored until a daml clean

repro script:

#!/usr/bin/env bash

mkdir p1
cat >p1/daml.yaml <<EOF
sdk-version: 2.7.0
build-options: []
name: p1
source: P1.daml
version: 0.0.1
dependencies:
  - daml-prim
  - daml-stdlib
EOF

cat >p1/P1.daml <<EOF
module P1 where p1 = ()
EOF

DAML_PROJECT=p1 daml build

mkdir p2
cat >p2/daml.yaml <<EOF
sdk-version: 2.7.0
build-options: []
name: p2
source: P2.daml
version: 0.0.1
dependencies:
  - daml-prim
  - daml-stdlib
data-dependencies:
  - ../p1/.daml/dist/p1-0.0.1.dar
EOF

cat >p2/P2.daml <<EOF
module P2 where
import qualified P1
p2 = P1.p1
EOF

# We first build p2 without any `module-prefixes`
DAML_PROJECT=p2 daml build # all good!

# Now we add a prefix for `p1`...
cat >>p2/daml.yaml <<EOF
module-prefixes:
  p1-0.0.1: Prefixed
EOF

# ... and update P2.daml accordingly
cat >p2/P2.daml <<EOF
module P2 where
import qualified Prefixed.P1
p2 = Prefixed.P1.p1
EOF

# but the prefixed import doesn't work
DAML_PROJECT=p2 daml build # fails!
# Could not find module ‘Prefixed.P1’
# It is not a module in the current program, or in any known package.

# cleaning and then rebuilding works, which means some data from the first build was being reused, causing the error
DAML_PROJECT=p2 daml clean
DAML_PROJECT=p2 daml build # now it works!

thanks @samuel-williams-da for spotting this!

basvangijzel-DA commented 1 year ago

Samuel: might be good to replace module-prefixes by package imports entirely. Problem: In GHC package imports only take names rather than IDs. We need versions: package names and version to be able to package imports. Bas: might be good to replace it as part of multipackage if that makes sense.