feat: do not hardcode the platform path

This commit is contained in:
rvcas 2020-12-01 23:03:31 -05:00
parent 4f19eedce4
commit bddc69896c

View file

@ -20,7 +20,9 @@ use roc_mono::ir::{
}; };
use roc_mono::layout::{Layout, LayoutCache}; use roc_mono::layout::{Layout, LayoutCache};
use roc_parse::ast::{self, Attempting, StrLiteral, TypeAnnotation}; use roc_parse::ast::{self, Attempting, StrLiteral, TypeAnnotation};
use roc_parse::header::{ExposesEntry, ImportsEntry, PlatformHeader, TypedIdent}; use roc_parse::header::{
ExposesEntry, ImportsEntry, PackageEntry, PackageOrPath, PlatformHeader, TypedIdent,
};
use roc_parse::module::module_defs; use roc_parse::module::module_defs;
use roc_parse::parser::{self, Fail, Parser}; use roc_parse::parser::{self, Fail, Parser};
use roc_region::all::{Located, Region}; use roc_region::all::{Located, Region};
@ -542,6 +544,7 @@ struct ModuleHeader<'a> {
exposed_ident_ids: IdentIds, exposed_ident_ids: IdentIds,
deps_by_name: MutMap<ModuleName, ModuleId>, deps_by_name: MutMap<ModuleName, ModuleId>,
imported_modules: MutSet<ModuleId>, imported_modules: MutSet<ModuleId>,
imported_package_modules: MutSet<ModuleId>,
exposes: Vec<Symbol>, exposes: Vec<Symbol>,
exposed_imports: MutMap<Ident, (Symbol, Region)>, exposed_imports: MutMap<Ident, (Symbol, Region)>,
src: &'a [u8], src: &'a [u8],
@ -2036,27 +2039,57 @@ fn parse_header<'a>(
module_timing, module_timing,
); );
// check whether we can find a Pkg-Config.roc file let opt_base_package = header.packages.iter().find(|loc_package_entry| {
let mut pkg_config_roc = pkg_config_dir.clone(); let Located { value, .. } = loc_package_entry;
pkg_config_roc.push("platform");
pkg_config_roc.push(PKG_CONFIG_FILE_NAME);
pkg_config_roc.set_extension(ROC_FILE_EXTENSION);
if pkg_config_roc.as_path().exists() { match value {
let load_pkg_config_msg = load_pkg_config( PackageEntry::Entry { shorthand, .. } => shorthand == &"base",
arena, _ => false,
&pkg_config_dir, }
module_ids, });
ident_ids_by_module,
mode,
)?;
Ok(( match opt_base_package {
module_id, Some(Located {
Msg::Many(vec![app_module_header_msg, load_pkg_config_msg]), value:
)) PackageEntry::Entry {
} else { package_or_path:
Ok((module_id, app_module_header_msg)) Located {
value: package_or_path,
..
},
..
},
..
}) => {
match package_or_path {
PackageOrPath::Path(StrLiteral::PlainLine(package)) => {
// check whether we can find a Pkg-Config.roc file
let mut pkg_config_roc = pkg_config_dir.clone();
pkg_config_roc.push(package);
pkg_config_roc.push(PKG_CONFIG_FILE_NAME);
pkg_config_roc.set_extension(ROC_FILE_EXTENSION);
if pkg_config_roc.as_path().exists() {
let load_pkg_config_msg = load_pkg_config(
arena,
&pkg_config_dir,
module_ids,
ident_ids_by_module,
mode,
)?;
Ok((
module_id,
Msg::Many(vec![app_module_header_msg, load_pkg_config_msg]),
))
} else {
Ok((module_id, app_module_header_msg))
}
}
_ => panic!("TODO not yet implement none path platform imports"),
}
}
_ => panic!("could not find base"),
} }
} }
Ok((ast::Module::Platform { header }, _parse_state)) => fabricate_effects_module( Ok((ast::Module::Platform { header }, _parse_state)) => fabricate_effects_module(
@ -2291,6 +2324,7 @@ fn send_header<'a>(
exposed_ident_ids: ident_ids, exposed_ident_ids: ident_ids,
module_name: loc_name.value, module_name: loc_name.value,
imported_modules, imported_modules,
imported_package_modules,
deps_by_name, deps_by_name,
exposes: exposed, exposes: exposed,
src: parse_state.bytes, src: parse_state.bytes,