Skip to content

Commit

Permalink
[move-cli] Rename binary and reorganize project tree
Browse files Browse the repository at this point in the history
The move-cli binary is now just named move. The crate did not change names,
only the binary it produces.

The following directories were renamed:

move_src -> src/modules and src/scripts
move_data -> storage
move_build_output -> build

Closes: aptos-labs#6622
  • Loading branch information
metajack authored and bors-libra committed Nov 3, 2020
1 parent 3472d14 commit f9f9347
Show file tree
Hide file tree
Showing 62 changed files with 156 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ language/tools/vm-genesis/genesis/vm_config.toml
.terraform/

# Move Build Output
move_build_output/
build/

# Docker incremental build temporary files and directories
target-out-docker
Expand Down
2 changes: 1 addition & 1 deletion language/move-lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ FLAGS:
OPTIONS:
-s, --sender <ADDRESS> The sender address for modules and scripts
-d, --dependency <PATH_TO_DEPENDENCY_FILE>... The library files needed as dependencies
-o, --out-dir <PATH_TO_OUTPUT_DIRECTORY> The Move bytecode output directory [default: move_build_output]
-o, --out-dir <PATH_TO_OUTPUT_DIRECTORY> The Move bytecode output directory [default: build]
ARGS:
<PATH_TO_SOURCE_FILE>... The source files to check and compile
Expand Down
2 changes: 1 addition & 1 deletion language/move-lang/src/command_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const SENDER_SHORT: &str = "s";

pub const OUT_DIR: &str = "out-dir";
pub const OUT_DIR_SHORT: &str = "o";
pub const DEFAULT_OUTPUT_DIR: &str = "move_build_output";
pub const DEFAULT_OUTPUT_DIR: &str = "build";

pub const SOURCE_MAP: &str = "source-map";
pub const SOURCE_MAP_SHORT: &str = "m";
Expand Down
4 changes: 4 additions & 0 deletions language/tools/move-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ vm-genesis = { path = "../vm-genesis", version = "0.1.0" }
datatest-stable = { path = "../../../common/datatest-stable", version = "0.1.0" }
lcs = { path = "../../../common/lcs", version = "0.1.0", package = "libra-canonical-serialization" }

[[bin]]
name = "move"
path = "src/main.rs"

[[test]]
name = "cli_testsuite"
harness = false
26 changes: 14 additions & 12 deletions language/tools/move-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ This is a tool for experimenting with Move without validators, a blockchain, or

## Installation
```
λ cargo build --release
λ export LIBRA_HOME=<path_to_your_libra_repo>
λ alias move="$LIBRA_HOME/target/release/move-cli $@"
λ cargo install --path libra/language/tools/move-cli
```
or
```
λ cargo install --git https://github.com/libra/libra move-cli
```

## Compiling and running scripts
Expand All @@ -30,11 +32,11 @@ Place this in a file named `script.move` and try

The `--signers 0xf` part indicates which account address(es) have signed off on the script. Omitting `--signers` or passing multiple signers to this single-`signer` script will trigger a type error.

## Adding new modules via `move_src`
## Adding new modules via `src`

By default, the CLI compiles and includes all files from the Move standard library and Libra Framework. New modules can be added to the `move_src` directory (or a directory of your choosing specified via `--move-src`. The `move run` command will compile and publish each module source file in this directory before running the given script.
By default, the CLI compiles and includes all files from the Move standard library and Libra Framework. New modules can be added to the `src` directory (or a directory of your choosing specified via `--source-dir`. The `move run` command will compile and publish each module source file in this directory before running the given script.

Try saving this code in `move_src/Test.move`:
Try saving this code in `src/modules/Test.move`:

```
module Test {
Expand Down Expand Up @@ -64,25 +66,25 @@ Compiling 1 user module(s)
Discarding changes; re-run with --commit if you would like to keep them.
```

The CLI has successfully compiled the module, but by default it chooses not to publish the module bytecode under `move_data`. Re-running the command with `--commit` (`-c` for short) will produce
The CLI has successfully compiled the module, but by default it chooses not to publish the module bytecode under `storage`. Re-running the command with `--commit` (`-c` for short) will produce

```
λ move compile -c
Compiling 1 user module(s)
Committed changes.
```

If we take a look under `move_data`, we will now see the published bytecodes for our test module:
If we take a look under `storage`, we will now see the published bytecodes for our test module:

```
λ ls move_data/0x00000000000000000000000000000002/modules
λ ls storage/0x00000000000000000000000000000002/modules
Test
```

We can also inspect the compiled bytecode using `move view`:

```
λ move view move_data/0x00000000000000000000000000000002/modules/Test
λ move view storage/0x00000000000000000000000000000002/modules/Test
module 00000000.Test {
resource Resource {
i: u64
Expand Down Expand Up @@ -142,7 +144,7 @@ Committed changes.
We can also inspect this newly published resource using `move view`:

```
λ move view move_data/0x0000000000000000000000000000000f/resources/0x00000000000000000000000000000002\:\:Test\:\:Resource
λ move view storage/0x0000000000000000000000000000000f/resources/0x00000000000000000000000000000002\:\:Test\:\:Resource
resource 00000000::Test::Resource {
i: 10
}
Expand All @@ -157,4 +159,4 @@ Take a look at `tests/testsuite/liba_smoke/args.txt`. This test uses the CLI to
λ NO_MOVE_CLEAN=1 cargo xtest libra_smoke
```

will execute each command in this file and leave you the resulting `move_data` to experiment with.
will execute each command in this file and leave you the resulting `storage` to experiment with.
22 changes: 11 additions & 11 deletions language/tools/move-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ use std::{
pub mod test;

/// Default directory where saved Move resources live
pub const MOVE_DATA: &str = "move_data";
pub const DEFAULT_STORAGE_DIR: &str = "storage";

/// Default directory where Move modules live
pub const MOVE_SRC: &str = "move_src";
pub const DEFAULT_SOURCE_DIR: &str = "src";

/// Default directory for build output
pub use move_lang::command_line::DEFAULT_OUTPUT_DIR as DEFAULT_BUILD_OUTPUT_DIR;
pub use move_lang::command_line::DEFAULT_OUTPUT_DIR as DEFAULT_BUILD_DIR;

/// Extension for resource and event files, which are in LCS format
const LCS_EXTENSION: &str = "lcs";
Expand All @@ -55,17 +55,17 @@ const EVENTS_DIR: &str = "events";
pub struct OnDiskStateView {
modules: HashMap<ModuleId, Vec<u8>>,
resources: HashMap<(AccountAddress, StructTag), Vec<u8>>,
move_data_dir: PathBuf,
storage_dir: PathBuf,
}

impl OnDiskStateView {
/// Create an `OnDiskStateView` that reads/writes resource data in `move_data_dir` and can
/// Create an `OnDiskStateView` that reads/writes resource data in `storage_dir` and can
/// execute code in `compiled_modules`.
pub fn create(move_data_dir: PathBuf, compiled_modules: &[CompiledModule]) -> Result<Self> {
if !move_data_dir.exists() || !move_data_dir.is_dir() {
pub fn create(storage_dir: PathBuf, compiled_modules: &[CompiledModule]) -> Result<Self> {
if !storage_dir.exists() || !storage_dir.is_dir() {
bail!(
"Attempting to create OnDiskStateView from bad data directory {:?}",
move_data_dir
storage_dir
)
}

Expand All @@ -79,7 +79,7 @@ impl OnDiskStateView {
Ok(Self {
modules,
resources,
move_data_dir,
storage_dir,
})
}

Expand All @@ -88,7 +88,7 @@ impl OnDiskStateView {
return false;
}
let p = p.canonicalize().unwrap();
p.starts_with(&self.move_data_dir)
p.starts_with(&self.storage_dir)
&& match p.parent() {
Some(parent) => parent.ends_with(parent_dir),
None => false,
Expand All @@ -108,7 +108,7 @@ impl OnDiskStateView {
}

fn get_addr_path(&self, addr: &AccountAddress) -> PathBuf {
let mut path = self.move_data_dir.clone();
let mut path = self.storage_dir.clone();
path.push(format!("0x{}", addr.to_string()));
path
}
Expand Down
82 changes: 42 additions & 40 deletions language/tools/move-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,34 @@ use std::{
use structopt::StructOpt;

#[derive(StructOpt)]
#[structopt(name = "Move", about = "CLI frontend for Move compiler and VM")]
#[structopt(
name = "move",
about = "CLI frontend for Move compiler and VM",
rename_all = "kebab-case"
)]
struct Move {
/// Directory storing Move resources, events, and module bytecodes produced by script execution.
#[structopt(name = "move-data", long = "move-data", default_value = MOVE_DATA, global = true)]
move_data: String,
#[structopt(long, default_value = DEFAULT_STORAGE_DIR, global = true)]
storage_dir: String,
/// Directory storing Move resources, events, and module bytecodes produced by script execution.
#[structopt(
name = "move-build-output",
long = "build-output",
default_value = DEFAULT_BUILD_OUTPUT_DIR,
global = true,
)]
build_output: String,
#[structopt(long, default_value = DEFAULT_BUILD_DIR, global = true)]
build_dir: String,
/// Print additional diagnostics
#[structopt(name = "verbose", short = "v", global = true)]
#[structopt(short = "v", global = true)]
verbose: bool,
#[structopt(subcommand)]
cmd: Command,
}

#[derive(StructOpt)]
enum Command {
/// Type check and verify the specified script and modules against the modules in `move_data`
/// Type check and verify the specified script and modules against the modules in `storage`
#[structopt(name = "check")]
Check {
/// The source files to check
#[structopt(
name = "PATH_TO_SOURCE_FILE",
default_value = MOVE_SRC,
default_value = DEFAULT_SOURCE_DIR,
)]
source_files: Vec<String>,
},
Expand All @@ -66,16 +65,16 @@ enum Command {
/// The source files containing modules to publish
#[structopt(
name = "PATH_TO_SOURCE_FILE",
default_value = MOVE_SRC,
default_value = DEFAULT_SOURCE_DIR,
)]
source_files: Vec<String>,
/// If set, the effects of executing `script_file` (i.e., published, updated, and
/// deleted resources) will NOT be committed to disk.
#[structopt(long = "dry-run", short = "n")]
dry_run: bool,
},
/// Compile/run a Move script that reads/writes resources stored on disk in `move_data`.
/// This command compiles each each module stored in `move_src` and loads it into the VM
/// Compile/run a Move script that reads/writes resources stored on disk in `storage`.
/// This command compiles each each module stored in `src` and loads it into the VM
/// before running the script.
#[structopt(name = "run")]
Run {
Expand Down Expand Up @@ -123,8 +122,8 @@ enum Command {
#[structopt(name = "file")]
file: String,
},
/// Delete all resources, events, and modules stored on disk under `move_data`.
/// Does *not* delete anything in `move_src`.
/// Delete all resources, events, and modules stored on disk under `storage`.
/// Does *not* delete anything in `src`.
Clean {},
}

Expand All @@ -140,8 +139,8 @@ fn maybe_create_dir(dir_name: &str) -> Result<&Path> {
/// Generate interface files for published files
fn generate_interface_files(args: &Move) -> Result<()> {
move_lang::generate_interface_files(
&[args.move_data.clone()],
Some(args.build_output.clone()),
&[args.storage_dir.clone()],
Some(args.build_dir.clone()),
false,
)?;
Ok(())
Expand All @@ -155,23 +154,23 @@ fn interface_files_dir(build_dir: &str) -> Result<String> {
Ok(dir)
}

/// Compile the user modules in `move_src` and the script in `script_file`
/// Compile the user modules in `src` and the script in `script_file`
fn check(args: &Move, files: &[String]) -> Result<()> {
if args.verbose {
println!("Checking Move files...");
}
let interface_dir = interface_files_dir(&args.build_output)?;
let interface_dir = interface_files_dir(&args.build_dir)?;
move_lang::move_check(files, &[interface_dir], None, None)?;
Ok(())
}

fn publish(args: &Move, files: &[String]) -> Result<OnDiskStateView> {
let move_data = maybe_create_dir(&args.move_data)?;
let storage_dir = maybe_create_dir(&args.storage_dir)?;

if args.verbose {
println!("Compiling Move modules...")
}
let interface_dir = interface_files_dir(&args.build_output)?;
let interface_dir = interface_files_dir(&args.build_dir)?;
let (_, compiled_units) = move_lang::move_compile(files, &[interface_dir], None, None)?;

let num_modules = compiled_units
Expand All @@ -197,7 +196,10 @@ fn publish(args: &Move, files: &[String]) -> Result<OnDiskStateView> {
CompiledUnit::Module { module, .. } => modules.push(module),
}
}
Ok(OnDiskStateView::create(move_data.to_path_buf(), &modules)?)
Ok(OnDiskStateView::create(
storage_dir.to_path_buf(),
&modules,
)?)
}

fn run(
Expand All @@ -213,12 +215,12 @@ fn run(
args: &Move,
script_file: &str,
) -> Result<(OnDiskStateView, Option<CompiledScript>)> {
let move_data = maybe_create_dir(&args.move_data)?;
let storage_dir = maybe_create_dir(&args.storage_dir)?;

if args.verbose {
println!("Compiling transaction script...")
}
let interface_dir = interface_files_dir(&args.build_output)?;
let interface_dir = interface_files_dir(&args.build_dir)?;
let (_, compiled_units) = move_lang::move_compile(
&[script_file.to_string()],
&[interface_dir.clone()],
Expand Down Expand Up @@ -247,7 +249,7 @@ fn run(
}
}
Ok((
OnDiskStateView::create(move_data.to_path_buf(), &[])?,
OnDiskStateView::create(storage_dir.to_path_buf(), &[])?,
script_opt,
))
}
Expand Down Expand Up @@ -535,7 +537,7 @@ fn explain_error(
VMStatus::Error(TYPE_MISMATCH) => explain_type_error(script, signers, txn_args),
VMStatus::Error(LINKER_ERROR) => {
// TODO: is this the only reason we can see LINKER_ERROR?
// Can we also see it if someone manually deletes modules in move_data?
// Can we also see it if someone manually deletes modules in storage?
println!(
"Execution failed due to unresolved type argument(s) (i.e., `--type-args \
0x1::M:T` when there is no module named M at 0x1 or no type named T in module \
Expand All @@ -552,9 +554,9 @@ fn explain_error(

/// Print a module or resource stored in `file`
fn view(args: &Move, file: &str) -> Result<()> {
let move_data = maybe_create_dir(&args.move_data)?.canonicalize()?;
let storage_dir = maybe_create_dir(&args.storage_dir)?.canonicalize()?;
let stdlib_modules = vec![]; // ok to use empty dir here since we're not compiling
let state = OnDiskStateView::create(move_data, &stdlib_modules)?;
let state = OnDiskStateView::create(storage_dir, &stdlib_modules)?;

let path = Path::new(&file);
if state.is_resource_path(path) {
Expand All @@ -577,7 +579,7 @@ fn view(args: &Move, file: &str) -> Result<()> {
None => println!("Module not found."),
}
} else {
bail!("`move view <file>` must point to a valid file under move_data")
bail!("`move view <file>` must point to a valid file under storage")
}
Ok(())
}
Expand Down Expand Up @@ -617,16 +619,16 @@ fn main() -> Result<()> {
),
Command::View { file } => view(&move_args, file),
Command::Clean {} => {
// delete move_data
let move_data = Path::new(&move_args.move_data);
if move_data.exists() {
fs::remove_dir_all(&move_data)?;
// delete storage
let storage_dir = Path::new(&move_args.storage_dir);
if storage_dir.exists() {
fs::remove_dir_all(&storage_dir)?;
}

// delete build_output
let build_output = Path::new(&move_args.build_output);
if build_output.exists() {
fs::remove_dir_all(&build_output)?;
// delete build
let build_dir = Path::new(&move_args.build_dir);
if build_dir.exists() {
fs::remove_dir_all(&build_dir)?;
}
Ok(())
}
Expand Down
Loading

0 comments on commit f9f9347

Please sign in to comment.