Skip to content

Commit

Permalink
[artifacts] Add a test which ensures generated Move artifacts are up-…
Browse files Browse the repository at this point in the history
…to-date (aptos-labs#5226)

This uses the generated documentation as an indicator whether `cached-packages` has been built and therefore all generated artifacts in the depot are up-to-date.
  • Loading branch information
wrwg authored Oct 24, 2022
1 parent 976d7e5 commit a408cde
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions aptos-move/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ move-vm-types ={ workspace = true }

[dev-dependencies]
claims = "0.7"
dir-diff = "0.3.2"
fs_extra = "1.2.0"

aptos-gas = { path = "../../aptos-move/aptos-gas" }
aptos-vm = { path = "../../aptos-move/aptos-vm", features = ["testing"] }
Expand Down
27 changes: 1 addition & 26 deletions aptos-move/framework/aptos-stdlib/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,7 @@ This is the reference documentation of the Aptos standard library.
## Index


- [`0x1::any`](any.md#0x1_any)
- [`0x1::aptos_hash`](hash.md#0x1_aptos_hash)
- [`0x1::bcs`](../../move-stdlib/doc/bcs.md#0x1_bcs)
- [`0x1::bls12381`](bls12381.md#0x1_bls12381)
- [`0x1::capability`](capability.md#0x1_capability)
- [`0x1::comparator`](comparator.md#0x1_comparator)
- [`0x1::copyable_any`](copyable_any.md#0x1_copyable_any)
- [`0x1::debug`](debug.md#0x1_debug)
- [`0x1::ed25519`](ed25519.md#0x1_ed25519)
- [`0x1::error`](../../move-stdlib/doc/error.md#0x1_error)
- [`0x1::from_bcs`](from_bcs.md#0x1_from_bcs)
- [`0x1::hash`](../../move-stdlib/doc/hash.md#0x1_hash)
- [`0x1::math128`](math128.md#0x1_math128)
- [`0x1::math64`](math64.md#0x1_math64)
- [`0x1::multi_ed25519`](multi_ed25519.md#0x1_multi_ed25519)
- [`0x1::option`](../../move-stdlib/doc/option.md#0x1_option)
- [`0x1::pool_u64`](pool_u64.md#0x1_pool_u64)
- [`0x1::ristretto255`](ristretto255.md#0x1_ristretto255)
- [`0x1::secp256k1`](secp256k1.md#0x1_secp256k1)
- [`0x1::signer`](../../move-stdlib/doc/signer.md#0x1_signer)
- [`0x1::simple_map`](simple_map.md#0x1_simple_map)
- [`0x1::string`](../../move-stdlib/doc/string.md#0x1_string)
- [`0x1::table`](table.md#0x1_table)
- [`0x1::table_with_length`](table_with_length.md#0x1_table_with_length)
- [`0x1::type_info`](type_info.md#0x1_type_info)
- [`0x1::vector`](../../move-stdlib/doc/vector.md#0x1_vector)
- [Index](#@Index_1)


[move-book]: https://move-language.github.io/move/introduction.html
9 changes: 6 additions & 3 deletions aptos-move/framework/src/aptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ReleaseTarget {
ReleaseBundle::read(path)
}

pub fn create_release(self, with_srcs: bool, out: Option<PathBuf>) -> anyhow::Result<()> {
pub fn create_release_options(self, with_srcs: bool, out: Option<PathBuf>) -> ReleaseOptions {
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let packages = self
.packages()
Expand All @@ -96,7 +96,7 @@ impl ReleaseTarget {
(crate_dir.join(path), binding_path.unwrap_or("").to_owned())
})
.collect::<Vec<_>>();
let options = ReleaseOptions {
ReleaseOptions {
build_options: BuildOptions {
with_srcs,
with_abis: true,
Expand Down Expand Up @@ -132,8 +132,11 @@ impl ReleaseTarget {
// Place in current directory
PathBuf::from(self.file_name())
},
};
}
}

pub fn create_release(self, with_srcs: bool, out: Option<PathBuf>) -> anyhow::Result<()> {
let options = self.create_release_options(with_srcs, out);
#[cfg(unix)]
{
options.create_release()
Expand Down
43 changes: 43 additions & 0 deletions aptos-move/framework/tests/artifact_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use framework::{BuiltPackage, ReleaseOptions, ReleaseTarget};
use tempfile::tempdir;

/// Test which ensures that generated artifacts (sdks, documentation, etc) are up-to-date.
/// Those artifacts are updated as a side-effect when `cached-packages` is build. However,
/// a user may have not needed to trigger building this crate. This test forces them to do so.
#[test]
fn artifacts_are_updated() {
let temp_dir = tempdir().unwrap();
let ReleaseOptions {
build_options,
packages,
..
} = ReleaseTarget::Head.create_release_options(false, None);
for package_path in packages {
// Copy the package content over to tempdir.
let copied_path = temp_dir.path().join(package_path.file_name().unwrap());
fs_extra::dir::copy(
&package_path,
&copied_path,
&fs_extra::dir::CopyOptions {
copy_inside: true,
..Default::default()
},
)
.unwrap();

// Build the copy of the package and compare the generated documentation. Because the
// documentation reflects the source, it is the strictest indicator whether
// `cached_packages` had been build and therefore things are up-to-date.
BuiltPackage::build(copied_path.clone(), build_options.clone()).unwrap();
assert!(
!dir_diff::is_different(package_path.join("doc"), copied_path.join("doc")).unwrap(),
"Artifacts generated from Move code are not up-to-date (sdk, docs, ...). Those \
artifacts are automatically updated if you run a build step depending on them. To force a \
build step, run `cargo build -p cached-packages`.
"
)
}
}

0 comments on commit a408cde

Please sign in to comment.