aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.06k stars 3.61k forks source link

[Feature Request] move package builder could use dependency override #9266

Open brmataptos opened 1 year ago

brmataptos commented 1 year ago

🚀 Feature Request

We need a command-line flag or environment variable to override the location of move dependencies.

Motivation

We currently build some example code as part of our CI tests, but since the examples refer to network-based dependencies, they are not hermetic and make it hard to update certain language features without breaking tests.

These dependencies show up in the [dependencies] section of the Move.toml, and by referring to git, http:, or https:, they

There is a --dev flag to aptos-move compile, which apparently causes the build to use dev-addresses and dev-dependencies fields in the Move.toml file, but adding these fields to the examples files may confuse new Move developers, especially since we have no documentation at all for them.

Instead, we should have an external method to override these for the case of tests. The dependencies section is kind of verbose, so perhaps a pointer to an alternative to the Move.toml file would be easiest to use.

Pitch

A few alternatives:

(1) Add a flag --source-dir <SOURCE_DIR> which can be used in combination with --package-dir to allow specification of separate sources and .toml file.

(2) Add a flag --override-config <AlternativeMove.toml> which could be used to specify an alternate Move.toml file. If we do this, the help message for "--package-dir " in the current tools must be changed, as it currently mentions the Move.toml file.

(3) Add a flag --override-dependencies <Dependencies.toml>which could specify a .toml file with just new dependencies.

(4) Add a flag with a string parameter to specify the new dependencies section: --override-dependencies "local = '../../../../aptos-move/framework/aptos-framework'". See some examples below, however, to see why this might be a bad idea.

For each case, the override could instead be in an environment variable.

Additional context

A few examples of dependencies sections in Move.toml files in our source tree:

[dependencies]
local = '../../../..'
subdir = 'aptos-move/framework/aptos-framework'
[dependencies.AptosFramework]
local = '../../../..'
subdir = 'aptos-move/framework/aptos-framework'
[dependencies]
AptosFramework = { local = "../../../framework/aptos-framework" }
AptosStdlib = { local = "../../../framework/aptos-stdlib" }
[dependencies]
Pack2 = { aptos = "http://localhost:8080", address = "default" }

(single Move.toml file:)

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "devnet"
subdir = "aptos-move/framework/aptos-framework"

[dependencies.AptosTokenObjects]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "devnet"
subdir = "aptos-move/framework/aptos-token-objects"
brmataptos commented 1 year ago

Note that the --dev flag also enables test mode (retaining #[test_only] code), so is doubly not a solution for our example Move code.