Skip to content

Commit

Permalink
3/n Add rebar includes outside RebarProject::new
Browse files Browse the repository at this point in the history
Summary: In preparation for moving the app data out of `RebarProject`, move the adding of global includes to the apps out of the constructor.

Reviewed By: michalmuskala

Differential Revision: D53130792

fbshipit-source-id: be324538e8c9bbb1f2111f2169a20ab51f45b234
  • Loading branch information
alanz authored and facebook-github-bot committed Jan 26, 2024
1 parent 8df24cc commit db8b43f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion crates/base_db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ impl ChangeFixture {
});
let root = AbsPathBuf::assert("/".into());
let apps = app_map.all_apps().cloned().collect();
let rebar_project = RebarProject::new(apps, vec![], root, Default::default(), &otp.lib_dir);
let apps_with_includes = RebarProject::add_app_includes(apps, &vec![], &otp.lib_dir);
let rebar_project = RebarProject::new(apps_with_includes, vec![], root, Default::default());
let mut project = Project::otp(otp, app_map.otp_apps().cloned().collect());
project.project_build_data = ProjectBuildData::Rebar(rebar_project);
let projects = [project];
Expand Down
33 changes: 20 additions & 13 deletions crates/project_model/src/rebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,11 @@ fn check_build_info(config: &RebarConfig) -> Result<()> {

impl RebarProject {
pub fn new(
mut apps: Vec<ProjectAppData>,
apps: Vec<ProjectAppData>,
deps: Vec<ProjectAppData>,
root: AbsPathBuf,
rebar_config: RebarConfig,
otp_root: &AbsPathBuf,
) -> Self {
let global_includes = RebarProject::global_includes(&apps, &deps);
for app in &mut apps {
let mut include_paths = global_includes.clone();
include_paths.extend(app.include_dirs());
include_paths.push(otp_root.to_path_buf());
app.include_path = include_paths;
}

Self {
apps,
deps,
Expand All @@ -149,18 +140,19 @@ impl RebarProject {
let build_info = eetf::Term::decode(&*data)?;
let otp_root = to_abs_path(map_get(&build_info, "otp_lib_dir")?)?;

let apps = to_vec(map_get(&build_info, "apps")?)?
let apps: Vec<_> = to_vec(map_get(&build_info, "apps")?)?
.iter()
.map(|term| to_app_data(term, AppType::App))
.collect::<Result<_>>()?;
let deps = to_vec(map_get(&build_info, "deps")?)?
let deps: Vec<_> = to_vec(map_get(&build_info, "deps")?)?
.iter()
.map(|term| to_app_data(term, AppType::Dep))
.collect::<Result<_>>()?;
let root = to_abs_path(map_get(&build_info, "source_root")?)?;

let apps_with_includes = RebarProject::add_app_includes(apps, &deps, &otp_root);
return Ok((
RebarProject::new(apps, deps, root, rebar_config, &otp_root),
RebarProject::new(apps_with_includes, deps, root, rebar_config),
otp_root.into(),
));

Expand Down Expand Up @@ -192,6 +184,21 @@ impl RebarProject {
}
}

pub fn add_app_includes(
mut apps: Vec<ProjectAppData>,
deps: &[ProjectAppData],
otp_root: &AbsPathBuf,
) -> Vec<ProjectAppData> {
let global_includes = RebarProject::global_includes(&apps, &deps);
for app in &mut apps {
let mut include_paths = global_includes.clone();
include_paths.extend(app.include_dirs());
include_paths.push(otp_root.to_path_buf());
app.include_path = include_paths;
}
apps
}

/// Replicates behaviour of -include_lib through
/// the -include fallback in a regularly structured
/// rebar3 project without compiling modules
Expand Down

0 comments on commit db8b43f

Please sign in to comment.