Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --output-directory to forc build and related commands #796

Merged
merged 14 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Forc's build directory
out
1 change: 0 additions & 1 deletion examples/hello_world/my-contract-abi.json

This file was deleted.

2 changes: 1 addition & 1 deletion examples/hello_world/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand::{Rng, SeedableRng};

// Generate Rust bindings from our contract JSON ABI
// FIXME: Incorrect path, see https://github.com/FuelLabs/fuels-rs/issues/94
abigen!(MyContract, "./my-contract-abi.json");
abigen!(MyContract, "./out/hello_world-abi.json");

#[tokio::test]
async fn harness() {
Expand Down
16 changes: 15 additions & 1 deletion forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use crate::ops::forc_build;
use structopt::{self, StructOpt};

/// Compile the current or target project.
#[derive(Debug, StructOpt)]
///
/// The output produced will depend on the project's program type. Building script, predicate and
/// contract projects will produce their bytecode in binary format `<project-name>.bin`. Building
/// contracts and libraries will also produce the public ABI in JSON format
/// `<project-name>-abi.json`.
#[derive(Debug, Default, StructOpt)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
Expand Down Expand Up @@ -32,6 +37,15 @@ pub struct Command {
/// Silent mode. Don't output any warnings or errors to the command line.
#[structopt(long = "silent", short = "s")]
pub silent_mode: bool,
/// The directory in which the sway compiler output artifacts are placed.
///
/// By default, this is `<project-root>/out`.
#[structopt(long)]
pub output_directory: Option<String>,
/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[structopt(long)]
pub minify_json_abi: bool,
}

pub(crate) fn exec(command: Command) -> Result<(), String> {
Expand Down
16 changes: 16 additions & 0 deletions forc/src/cli/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::ops::forc_clean;
use structopt::{self, StructOpt};

/// Removes the default forc compiler output artifact directory, i.e. `<project-name>/out`. Also
/// calls `cargo clean` which removes the `target` directory generated by `cargo` when running
/// tests.
#[derive(Debug, StructOpt)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
pub path: Option<String>,
}

pub fn exec(command: Command) -> Result<(), String> {
forc_clean::clean(command)
}
11 changes: 10 additions & 1 deletion forc/src/cli/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use structopt::{self, StructOpt};

/// Deploy contract project.
/// Crafts a contract deployment transaction then sends it to a running node.
#[derive(Debug, StructOpt)]
#[derive(Debug, Default, StructOpt)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
Expand Down Expand Up @@ -33,6 +33,15 @@ pub struct Command {
/// Silent mode. Don't output any warnings or errors to the command line.
#[structopt(long = "silent", short = "s")]
pub silent_mode: bool,
/// The directory in which the sway compiler output artifacts are placed.
///
/// By default, this is `<project-root>/out`.
#[structopt(long)]
pub output_directory: Option<String>,
/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[structopt(long)]
pub minify_json_abi: bool,
}

pub(crate) async fn exec(command: Command) -> Result<(), String> {
Expand Down
6 changes: 5 additions & 1 deletion forc/src/cli/commands/json_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::ops::forc_abi_json;
use structopt::{self, StructOpt};

/// Output the JSON associated with the ABI.
#[derive(Debug, StructOpt)]
#[derive(Debug, Default, StructOpt)]
pub struct Command {
/// Path to the project, if not specified, current working directory will be used.
#[structopt(short, long)]
Expand All @@ -17,6 +17,10 @@ pub struct Command {
/// Silent mode. Don't output any warnings or errors to the command line.
#[structopt(long = "silent", short = "s")]
pub silent_mode: bool,
/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[structopt(long)]
pub minify: bool,
}

pub(crate) fn exec(command: Command) -> Result<(), String> {
Expand Down
1 change: 1 addition & 0 deletions forc/src/cli/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod addr2line;
pub mod build;
pub mod clean;
pub mod deploy;
pub mod explorer;
pub mod format;
Expand Down
13 changes: 12 additions & 1 deletion forc/src/cli/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use structopt::{self, StructOpt};

/// Run script project.
/// Crafts a script transaction then sends it to a running node.
#[derive(Debug, StructOpt)]
#[derive(Debug, Default, StructOpt)]
pub struct Command {
/// Hex string of data to input to script.
#[structopt(short, long)]
Expand Down Expand Up @@ -61,6 +61,17 @@ pub struct Command {
/// 32-byte contract ID that will be called during the transaction.
#[structopt(long = "contract")]
pub contract: Option<Vec<String>>,

/// The directory in which the sway compiler output artifacts are placed.
///
/// By default, this is `<project-root>/out`.
#[structopt(long)]
pub output_directory: Option<String>,

/// By default the JSON for ABIs is formatted for human readability. By using this option JSON
/// output will be "minified", i.e. all on one line without whitespace.
#[structopt(long)]
pub minify_json_abi: bool,
}

pub(crate) async fn exec(command: Command) -> Result<(), String> {
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::ops::forc_build;
use std::io::{BufRead, BufReader};
use std::process::Command as ProcessCommand;
use std::process::Stdio;
Expand All @@ -18,6 +19,9 @@ pub(crate) struct Command {
}

pub(crate) fn exec(command: Command) -> Result<(), String> {
// Ensure the project builds before running tests.
forc_build::build(Default::default())?;

// Cargo args setup
let mut args: Vec<String> = vec!["test".into()];
if let Some(name) = command.test_name {
Expand Down
7 changes: 5 additions & 2 deletions forc/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use structopt::StructOpt;

mod commands;
use self::commands::{
addr2line, build, deploy, explorer, format, init, json_abi, lsp, parse_bytecode, run, test,
update,
addr2line, build, clean, deploy, explorer, format, init, json_abi, lsp, parse_bytecode, run,
test, update,
};

use addr2line::Command as Addr2LineCommand;
pub use build::Command as BuildCommand;
pub use clean::Command as CleanCommand;
pub use deploy::Command as DeployCommand;
pub use explorer::Command as ExplorerCommand;
pub use format::Command as FormatCommand;
Expand All @@ -32,6 +33,7 @@ enum Forc {
#[structopt(name = "addr2line")]
Addr2Line(Addr2LineCommand),
Build(BuildCommand),
Clean(CleanCommand),
Deploy(DeployCommand),
Explorer(ExplorerCommand),
#[structopt(name = "fmt")]
Expand All @@ -50,6 +52,7 @@ pub(crate) async fn run_cli() -> Result<(), String> {
match opt.command {
Forc::Addr2Line(command) => addr2line::exec(command),
Forc::Build(command) => build::exec(command),
Forc::Clean(command) => clean::exec(command),
Forc::Deploy(command) => deploy::exec(command).await,
Forc::Explorer(command) => explorer::exec(command).await,
Forc::Format(command) => format::exec(command),
Expand Down
Loading