Skip to content

Commit f9f9347

Browse files
metajackbors-libra
authored andcommitted
[move-cli] Rename binary and reorganize project tree
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: diem#6622
1 parent 3472d14 commit f9f9347

File tree

62 files changed

+156
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+156
-148
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ language/tools/vm-genesis/genesis/vm_config.toml
4343
.terraform/
4444

4545
# Move Build Output
46-
move_build_output/
46+
build/
4747

4848
# Docker incremental build temporary files and directories
4949
target-out-docker

language/move-lang/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ FLAGS:
100100
OPTIONS:
101101
-s, --sender <ADDRESS> The sender address for modules and scripts
102102
-d, --dependency <PATH_TO_DEPENDENCY_FILE>... The library files needed as dependencies
103-
-o, --out-dir <PATH_TO_OUTPUT_DIRECTORY> The Move bytecode output directory [default: move_build_output]
103+
-o, --out-dir <PATH_TO_OUTPUT_DIRECTORY> The Move bytecode output directory [default: build]
104104
105105
ARGS:
106106
<PATH_TO_SOURCE_FILE>... The source files to check and compile

language/move-lang/src/command_line/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const SENDER_SHORT: &str = "s";
1111

1212
pub const OUT_DIR: &str = "out-dir";
1313
pub const OUT_DIR_SHORT: &str = "o";
14-
pub const DEFAULT_OUTPUT_DIR: &str = "move_build_output";
14+
pub const DEFAULT_OUTPUT_DIR: &str = "build";
1515

1616
pub const SOURCE_MAP: &str = "source-map";
1717
pub const SOURCE_MAP_SHORT: &str = "m";

language/tools/move-cli/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ vm-genesis = { path = "../vm-genesis", version = "0.1.0" }
3434
datatest-stable = { path = "../../../common/datatest-stable", version = "0.1.0" }
3535
lcs = { path = "../../../common/lcs", version = "0.1.0", package = "libra-canonical-serialization" }
3636

37+
[[bin]]
38+
name = "move"
39+
path = "src/main.rs"
40+
3741
[[test]]
3842
name = "cli_testsuite"
3943
harness = false

language/tools/move-cli/README.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ This is a tool for experimenting with Move without validators, a blockchain, or
44

55
## Installation
66
```
7-
λ cargo build --release
8-
λ export LIBRA_HOME=<path_to_your_libra_repo>
9-
λ alias move="$LIBRA_HOME/target/release/move-cli $@"
7+
λ cargo install --path libra/language/tools/move-cli
8+
```
9+
or
10+
```
11+
λ cargo install --git https://github.com/libra/libra move-cli
1012
```
1113

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

3133
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.
3234

33-
## Adding new modules via `move_src`
35+
## Adding new modules via `src`
3436

35-
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.
37+
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.
3638

37-
Try saving this code in `move_src/Test.move`:
39+
Try saving this code in `src/modules/Test.move`:
3840

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

67-
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
69+
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
6870

6971
```
7072
λ move compile -c
7173
Compiling 1 user module(s)
7274
Committed changes.
7375
```
7476

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

7779
```
78-
λ ls move_data/0x00000000000000000000000000000002/modules
80+
λ ls storage/0x00000000000000000000000000000002/modules
7981
Test
8082
```
8183

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

8486
```
85-
λ move view move_data/0x00000000000000000000000000000002/modules/Test
87+
λ move view storage/0x00000000000000000000000000000002/modules/Test
8688
module 00000000.Test {
8789
resource Resource {
8890
i: u64
@@ -142,7 +144,7 @@ Committed changes.
142144
We can also inspect this newly published resource using `move view`:
143145

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

160-
will execute each command in this file and leave you the resulting `move_data` to experiment with.
162+
will execute each command in this file and leave you the resulting `storage` to experiment with.

language/tools/move-cli/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ use std::{
3333
pub mod test;
3434

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

3838
/// Default directory where Move modules live
39-
pub const MOVE_SRC: &str = "move_src";
39+
pub const DEFAULT_SOURCE_DIR: &str = "src";
4040

4141
/// Default directory for build output
42-
pub use move_lang::command_line::DEFAULT_OUTPUT_DIR as DEFAULT_BUILD_OUTPUT_DIR;
42+
pub use move_lang::command_line::DEFAULT_OUTPUT_DIR as DEFAULT_BUILD_DIR;
4343

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

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

@@ -79,7 +79,7 @@ impl OnDiskStateView {
7979
Ok(Self {
8080
modules,
8181
resources,
82-
move_data_dir,
82+
storage_dir,
8383
})
8484
}
8585

@@ -88,7 +88,7 @@ impl OnDiskStateView {
8888
return false;
8989
}
9090
let p = p.canonicalize().unwrap();
91-
p.starts_with(&self.move_data_dir)
91+
p.starts_with(&self.storage_dir)
9292
&& match p.parent() {
9393
Some(parent) => parent.ends_with(parent_dir),
9494
None => false,
@@ -108,7 +108,7 @@ impl OnDiskStateView {
108108
}
109109

110110
fn get_addr_path(&self, addr: &AccountAddress) -> PathBuf {
111-
let mut path = self.move_data_dir.clone();
111+
let mut path = self.storage_dir.clone();
112112
path.push(format!("0x{}", addr.to_string()));
113113
path
114114
}

language/tools/move-cli/src/main.rs

+42-40
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,34 @@ use std::{
2929
use structopt::StructOpt;
3030

3131
#[derive(StructOpt)]
32-
#[structopt(name = "Move", about = "CLI frontend for Move compiler and VM")]
32+
#[structopt(
33+
name = "move",
34+
about = "CLI frontend for Move compiler and VM",
35+
rename_all = "kebab-case"
36+
)]
3337
struct Move {
3438
/// Directory storing Move resources, events, and module bytecodes produced by script execution.
35-
#[structopt(name = "move-data", long = "move-data", default_value = MOVE_DATA, global = true)]
36-
move_data: String,
39+
#[structopt(long, default_value = DEFAULT_STORAGE_DIR, global = true)]
40+
storage_dir: String,
3741
/// Directory storing Move resources, events, and module bytecodes produced by script execution.
38-
#[structopt(
39-
name = "move-build-output",
40-
long = "build-output",
41-
default_value = DEFAULT_BUILD_OUTPUT_DIR,
42-
global = true,
43-
)]
44-
build_output: String,
42+
#[structopt(long, default_value = DEFAULT_BUILD_DIR, global = true)]
43+
build_dir: String,
4544
/// Print additional diagnostics
46-
#[structopt(name = "verbose", short = "v", global = true)]
45+
#[structopt(short = "v", global = true)]
4746
verbose: bool,
4847
#[structopt(subcommand)]
4948
cmd: Command,
5049
}
5150

5251
#[derive(StructOpt)]
5352
enum Command {
54-
/// Type check and verify the specified script and modules against the modules in `move_data`
53+
/// Type check and verify the specified script and modules against the modules in `storage`
5554
#[structopt(name = "check")]
5655
Check {
5756
/// The source files to check
5857
#[structopt(
5958
name = "PATH_TO_SOURCE_FILE",
60-
default_value = MOVE_SRC,
59+
default_value = DEFAULT_SOURCE_DIR,
6160
)]
6261
source_files: Vec<String>,
6362
},
@@ -66,16 +65,16 @@ enum Command {
6665
/// The source files containing modules to publish
6766
#[structopt(
6867
name = "PATH_TO_SOURCE_FILE",
69-
default_value = MOVE_SRC,
68+
default_value = DEFAULT_SOURCE_DIR,
7069
)]
7170
source_files: Vec<String>,
7271
/// If set, the effects of executing `script_file` (i.e., published, updated, and
7372
/// deleted resources) will NOT be committed to disk.
7473
#[structopt(long = "dry-run", short = "n")]
7574
dry_run: bool,
7675
},
77-
/// Compile/run a Move script that reads/writes resources stored on disk in `move_data`.
78-
/// This command compiles each each module stored in `move_src` and loads it into the VM
76+
/// Compile/run a Move script that reads/writes resources stored on disk in `storage`.
77+
/// This command compiles each each module stored in `src` and loads it into the VM
7978
/// before running the script.
8079
#[structopt(name = "run")]
8180
Run {
@@ -123,8 +122,8 @@ enum Command {
123122
#[structopt(name = "file")]
124123
file: String,
125124
},
126-
/// Delete all resources, events, and modules stored on disk under `move_data`.
127-
/// Does *not* delete anything in `move_src`.
125+
/// Delete all resources, events, and modules stored on disk under `storage`.
126+
/// Does *not* delete anything in `src`.
128127
Clean {},
129128
}
130129

@@ -140,8 +139,8 @@ fn maybe_create_dir(dir_name: &str) -> Result<&Path> {
140139
/// Generate interface files for published files
141140
fn generate_interface_files(args: &Move) -> Result<()> {
142141
move_lang::generate_interface_files(
143-
&[args.move_data.clone()],
144-
Some(args.build_output.clone()),
142+
&[args.storage_dir.clone()],
143+
Some(args.build_dir.clone()),
145144
false,
146145
)?;
147146
Ok(())
@@ -155,23 +154,23 @@ fn interface_files_dir(build_dir: &str) -> Result<String> {
155154
Ok(dir)
156155
}
157156

158-
/// Compile the user modules in `move_src` and the script in `script_file`
157+
/// Compile the user modules in `src` and the script in `script_file`
159158
fn check(args: &Move, files: &[String]) -> Result<()> {
160159
if args.verbose {
161160
println!("Checking Move files...");
162161
}
163-
let interface_dir = interface_files_dir(&args.build_output)?;
162+
let interface_dir = interface_files_dir(&args.build_dir)?;
164163
move_lang::move_check(files, &[interface_dir], None, None)?;
165164
Ok(())
166165
}
167166

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

171170
if args.verbose {
172171
println!("Compiling Move modules...")
173172
}
174-
let interface_dir = interface_files_dir(&args.build_output)?;
173+
let interface_dir = interface_files_dir(&args.build_dir)?;
175174
let (_, compiled_units) = move_lang::move_compile(files, &[interface_dir], None, None)?;
176175

177176
let num_modules = compiled_units
@@ -197,7 +196,10 @@ fn publish(args: &Move, files: &[String]) -> Result<OnDiskStateView> {
197196
CompiledUnit::Module { module, .. } => modules.push(module),
198197
}
199198
}
200-
Ok(OnDiskStateView::create(move_data.to_path_buf(), &modules)?)
199+
Ok(OnDiskStateView::create(
200+
storage_dir.to_path_buf(),
201+
&modules,
202+
)?)
201203
}
202204

203205
fn run(
@@ -213,12 +215,12 @@ fn run(
213215
args: &Move,
214216
script_file: &str,
215217
) -> Result<(OnDiskStateView, Option<CompiledScript>)> {
216-
let move_data = maybe_create_dir(&args.move_data)?;
218+
let storage_dir = maybe_create_dir(&args.storage_dir)?;
217219

218220
if args.verbose {
219221
println!("Compiling transaction script...")
220222
}
221-
let interface_dir = interface_files_dir(&args.build_output)?;
223+
let interface_dir = interface_files_dir(&args.build_dir)?;
222224
let (_, compiled_units) = move_lang::move_compile(
223225
&[script_file.to_string()],
224226
&[interface_dir.clone()],
@@ -247,7 +249,7 @@ fn run(
247249
}
248250
}
249251
Ok((
250-
OnDiskStateView::create(move_data.to_path_buf(), &[])?,
252+
OnDiskStateView::create(storage_dir.to_path_buf(), &[])?,
251253
script_opt,
252254
))
253255
}
@@ -535,7 +537,7 @@ fn explain_error(
535537
VMStatus::Error(TYPE_MISMATCH) => explain_type_error(script, signers, txn_args),
536538
VMStatus::Error(LINKER_ERROR) => {
537539
// TODO: is this the only reason we can see LINKER_ERROR?
538-
// Can we also see it if someone manually deletes modules in move_data?
540+
// Can we also see it if someone manually deletes modules in storage?
539541
println!(
540542
"Execution failed due to unresolved type argument(s) (i.e., `--type-args \
541543
0x1::M:T` when there is no module named M at 0x1 or no type named T in module \
@@ -552,9 +554,9 @@ fn explain_error(
552554

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

559561
let path = Path::new(&file);
560562
if state.is_resource_path(path) {
@@ -577,7 +579,7 @@ fn view(args: &Move, file: &str) -> Result<()> {
577579
None => println!("Module not found."),
578580
}
579581
} else {
580-
bail!("`move view <file>` must point to a valid file under move_data")
582+
bail!("`move view <file>` must point to a valid file under storage")
581583
}
582584
Ok(())
583585
}
@@ -617,16 +619,16 @@ fn main() -> Result<()> {
617619
),
618620
Command::View { file } => view(&move_args, file),
619621
Command::Clean {} => {
620-
// delete move_data
621-
let move_data = Path::new(&move_args.move_data);
622-
if move_data.exists() {
623-
fs::remove_dir_all(&move_data)?;
622+
// delete storage
623+
let storage_dir = Path::new(&move_args.storage_dir);
624+
if storage_dir.exists() {
625+
fs::remove_dir_all(&storage_dir)?;
624626
}
625627

626-
// delete build_output
627-
let build_output = Path::new(&move_args.build_output);
628-
if build_output.exists() {
629-
fs::remove_dir_all(&build_output)?;
628+
// delete build
629+
let build_dir = Path::new(&move_args.build_dir);
630+
if build_dir.exists() {
631+
fs::remove_dir_all(&build_dir)?;
630632
}
631633
Ok(())
632634
}

0 commit comments

Comments
 (0)