Skip to content

Commit

Permalink
Merge pull request #5920 from roc-lang/output-flag
Browse files Browse the repository at this point in the history
Add --output flag
  • Loading branch information
Anton-4 authored Oct 23, 2023
2 parents d11aba1 + 0eefbac commit 54180cc
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 246 deletions.
17 changes: 17 additions & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub const FLAG_CHECK: &str = "check";
pub const FLAG_STDIN: &str = "stdin";
pub const FLAG_STDOUT: &str = "stdout";
pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb";
pub const FLAG_OUTPUT: &str = "output";
pub const ROC_FILE: &str = "ROC_FILE";
pub const ROC_DIR: &str = "ROC_DIR";
pub const GLUE_DIR: &str = "GLUE_DIR";
Expand All @@ -73,6 +74,7 @@ pub const DIRECTORY_OR_FILES: &str = "DIRECTORY_OR_FILES";
pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP";

const VERSION: &str = include_str!("../../../version.txt");
const DEFAULT_GENERATED_DOCS_DIR: &str = "generated-docs";

pub fn build_app() -> Command {
let flag_optimize = Arg::new(FLAG_OPTIMIZE)
Expand Down Expand Up @@ -150,6 +152,12 @@ pub fn build_app() -> Command {
.args_conflicts_with_subcommands(true)
.subcommand(Command::new(CMD_BUILD)
.about("Build a binary from the given .roc file, but don't run it")
.arg(Arg::new(FLAG_OUTPUT)
.long(FLAG_OUTPUT)
.help("The full path to the output binary, including filename. To specify directory only, specify a path that ends in a directory separator (e.g. a slash).")
.value_parser(value_parser!(OsString))
.required(false)
)
.arg(flag_optimize.clone())
.arg(flag_max_threads.clone())
.arg(flag_opt_size.clone())
Expand Down Expand Up @@ -292,6 +300,13 @@ pub fn build_app() -> Command {
.subcommand(
Command::new(CMD_DOCS)
.about("Generate documentation for a Roc package")
.arg(Arg::new(FLAG_OUTPUT)
.long(FLAG_OUTPUT)
.help("Output directory for the generated documentation files.")
.value_parser(value_parser!(OsString))
.required(false)
.default_value(DEFAULT_GENERATED_DOCS_DIR),
)
.arg(Arg::new(ROC_FILE)
.help("The package's main .roc file")
.value_parser(value_parser!(PathBuf))
Expand Down Expand Up @@ -539,6 +554,7 @@ pub fn build(
subcommands: &[String],
config: BuildConfig,
triple: Triple,
out_path: Option<&Path>,
roc_cache_dir: RocCacheDir<'_>,
link_type: LinkType,
) -> io::Result<i32> {
Expand Down Expand Up @@ -727,6 +743,7 @@ pub fn build(
wasm_dev_stack_bytes,
roc_cache_dir,
load_config,
out_path,
);

match res_binary_path {
Expand Down
14 changes: 11 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use roc_build::program::{check_file, CodeGenBackend};
use roc_cli::{
build_app, format_files, format_src, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK,
CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST,
CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_NO_LINK, FLAG_STDIN,
FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE,
CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_NO_LINK, FLAG_OUTPUT,
FLAG_STDIN, FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE,
};
use roc_docs::generate_docs_html;
use roc_error_macros::user_error;
Expand Down Expand Up @@ -49,6 +49,7 @@ fn main() -> io::Result<()> {
&subcommands,
BuildConfig::BuildAndRunIfNoErrors,
Triple::host(),
None,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
LinkType::Executable,
)
Expand All @@ -63,6 +64,7 @@ fn main() -> io::Result<()> {
&subcommands,
BuildConfig::BuildAndRun,
Triple::host(),
None,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
LinkType::Executable,
)
Expand All @@ -88,6 +90,7 @@ fn main() -> io::Result<()> {
&subcommands,
BuildConfig::BuildAndRunIfNoErrors,
Triple::host(),
None,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
LinkType::Executable,
)
Expand Down Expand Up @@ -141,12 +144,16 @@ fn main() -> io::Result<()> {
(false, true) => LinkType::None,
(false, false) => LinkType::Executable,
};
let out_path = matches
.get_one::<OsString>(FLAG_OUTPUT)
.map(OsString::as_ref);

Ok(build(
matches,
&subcommands,
BuildConfig::BuildOnly,
target.to_triple(),
out_path,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
link_type,
)?)
Expand Down Expand Up @@ -214,8 +221,9 @@ fn main() -> io::Result<()> {
Some((CMD_REPL, _)) => Ok(roc_repl_cli::main()),
Some((CMD_DOCS, matches)) => {
let root_path = matches.get_one::<PathBuf>(ROC_FILE).unwrap();
let out_dir = matches.get_one::<OsString>(FLAG_OUTPUT).unwrap();

generate_docs_html(root_path.to_owned());
generate_docs_html(root_path.to_owned(), out_dir.as_ref());

Ok(0)
}
Expand Down
Loading

0 comments on commit 54180cc

Please sign in to comment.