mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Add --main flag to specify app/package to resolve deps from
This commit is contained in:
parent
75fe98cbaf
commit
2da7ea394b
15 changed files with 89 additions and 19 deletions
|
@ -735,9 +735,14 @@ pub fn build_file<'a>(
|
|||
let compilation_start = Instant::now();
|
||||
|
||||
// Step 1: compile the app and generate the .o file
|
||||
let loaded =
|
||||
roc_load::load_and_monomorphize(arena, app_module_path.clone(), roc_cache_dir, load_config)
|
||||
.map_err(|e| BuildFileError::from_mono_error(e, compilation_start))?;
|
||||
let loaded = roc_load::load_and_monomorphize(
|
||||
arena,
|
||||
app_module_path.clone(),
|
||||
None,
|
||||
roc_cache_dir,
|
||||
load_config,
|
||||
)
|
||||
.map_err(|e| BuildFileError::from_mono_error(e, compilation_start))?;
|
||||
|
||||
build_loaded_file(
|
||||
arena,
|
||||
|
@ -1187,6 +1192,7 @@ fn build_and_preprocess_host_lowlevel(
|
|||
pub fn check_file<'a>(
|
||||
arena: &'a Bump,
|
||||
roc_file_path: PathBuf,
|
||||
opt_main_path: Option<PathBuf>,
|
||||
emit_timings: bool,
|
||||
roc_cache_dir: RocCacheDir<'_>,
|
||||
threading: Threading,
|
||||
|
@ -1209,8 +1215,13 @@ pub fn check_file<'a>(
|
|||
threading,
|
||||
exec_mode: ExecutionMode::Check,
|
||||
};
|
||||
let mut loaded =
|
||||
roc_load::load_and_typecheck(arena, roc_file_path, roc_cache_dir, load_config)?;
|
||||
let mut loaded = roc_load::load_and_typecheck(
|
||||
arena,
|
||||
roc_file_path,
|
||||
opt_main_path,
|
||||
roc_cache_dir,
|
||||
load_config,
|
||||
)?;
|
||||
|
||||
let buf = &mut String::with_capacity(1024);
|
||||
|
||||
|
|
|
@ -121,6 +121,7 @@ pub fn load_and_monomorphize_from_str<'a>(
|
|||
pub fn load_and_monomorphize<'a>(
|
||||
arena: &'a Bump,
|
||||
filename: PathBuf,
|
||||
opt_main_path: Option<PathBuf>,
|
||||
roc_cache_dir: RocCacheDir<'_>,
|
||||
load_config: LoadConfig,
|
||||
) -> Result<MonomorphizedModule<'a>, LoadMonomorphizedError<'a>> {
|
||||
|
@ -129,6 +130,7 @@ pub fn load_and_monomorphize<'a>(
|
|||
let load_start = LoadStart::from_path(
|
||||
arena,
|
||||
filename,
|
||||
opt_main_path,
|
||||
load_config.render,
|
||||
roc_cache_dir,
|
||||
load_config.palette,
|
||||
|
@ -145,6 +147,7 @@ pub fn load_and_monomorphize<'a>(
|
|||
pub fn load_and_typecheck<'a>(
|
||||
arena: &'a Bump,
|
||||
filename: PathBuf,
|
||||
opt_main_path: Option<PathBuf>,
|
||||
roc_cache_dir: RocCacheDir<'_>,
|
||||
load_config: LoadConfig,
|
||||
) -> Result<LoadedModule, LoadingProblem<'a>> {
|
||||
|
@ -153,6 +156,7 @@ pub fn load_and_typecheck<'a>(
|
|||
let load_start = LoadStart::from_path(
|
||||
arena,
|
||||
filename,
|
||||
opt_main_path,
|
||||
load_config.render,
|
||||
roc_cache_dir,
|
||||
load_config.palette,
|
||||
|
|
|
@ -134,6 +134,7 @@ mod test_reporting {
|
|||
let result = roc_load::load_and_typecheck(
|
||||
arena,
|
||||
full_file_path,
|
||||
None,
|
||||
RocCacheDir::Disallowed,
|
||||
load_config,
|
||||
);
|
||||
|
|
|
@ -1105,6 +1105,7 @@ impl<'a> LoadStart<'a> {
|
|||
pub fn from_path(
|
||||
arena: &'a Bump,
|
||||
filename: PathBuf,
|
||||
opt_main_path: Option<PathBuf>,
|
||||
render: RenderTarget,
|
||||
roc_cache_dir: RocCacheDir<'_>,
|
||||
palette: Palette,
|
||||
|
@ -1144,23 +1145,23 @@ impl<'a> LoadStart<'a> {
|
|||
|
||||
match header_type {
|
||||
Module { .. } | Builtin { .. } | Hosted { .. } => {
|
||||
let main_path = loop {
|
||||
let main_path = opt_main_path.or_else(|| loop {
|
||||
match src_dir.join("main.roc").canonicalize() {
|
||||
Ok(path) => break path,
|
||||
Ok(path) => break Some(path),
|
||||
Err(_) => {
|
||||
if !src_dir.pop() {
|
||||
return Err(LoadingProblem::FormattedReport(
|
||||
"todo(agus): good error".to_string(),
|
||||
));
|
||||
break None;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
let mut messages = Vec::with_capacity(4);
|
||||
messages.push(header_output.msg);
|
||||
let cache_dir = roc_cache_dir.as_persistent_path();
|
||||
|
||||
if let (Some(main_path), Some(cache_dir)) = (main_path, cache_dir) {
|
||||
let mut messages = Vec::with_capacity(4);
|
||||
messages.push(header_output.msg);
|
||||
|
||||
if let Some(cache_dir) = roc_cache_dir.as_persistent_path() {
|
||||
load_packages_from_main(
|
||||
arena,
|
||||
src_dir.clone(),
|
||||
|
@ -1171,9 +1172,9 @@ impl<'a> LoadStart<'a> {
|
|||
Arc::clone(&arc_shorthands),
|
||||
cache_dir,
|
||||
)?;
|
||||
}
|
||||
|
||||
header_output.msg = Msg::Many(messages);
|
||||
header_output.msg = Msg::Many(messages);
|
||||
}
|
||||
}
|
||||
App { .. } | Package { .. } | Platform { .. } => {}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ fn load_and_typecheck(
|
|||
let load_start = LoadStart::from_path(
|
||||
arena,
|
||||
filename,
|
||||
None,
|
||||
RenderTarget::Generic,
|
||||
RocCacheDir::Disallowed,
|
||||
DEFAULT_PALETTE,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue