Skip to content

Commit

Permalink
Remove eetf::Term based build info
Browse files Browse the repository at this point in the history
Summary:
This removes the last of the on-disk build info for eqwalizer.

It also makes the `--json` flag to `elp build-info` a NOP, as it is always used.
We mark it as deprecated though, in case it is used in scripting anywhere.

Reviewed By: jcpetruzza

Differential Revision: D60887466

fbshipit-source-id: b14ff68e4100c25e79aff51377b2604a9d571a2e
  • Loading branch information
alanz authored and facebook-github-bot committed Aug 7, 2024
1 parent 3b400e3 commit baad626
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 213 deletions.
4 changes: 3 additions & 1 deletion crates/elp/src/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ pub struct BuildInfo {
/// Path to a directory where to dump wa.build_info
#[bpaf(argument("TO"))]
pub to: PathBuf,
/// Generate JSON output rather than Erlang terms
/// Generate JSON output rather than Erlang terms.
/// DEPRECATED: we now always generate JSON output
#[allow(unused)]
pub json: bool,
}

Expand Down
18 changes: 4 additions & 14 deletions crates/elp/src/bin/build_info_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::fs;
use std::fs::File;
use std::io::Write;

use anyhow::bail;
use anyhow::Result;
use elp_ide::elp_ide_db::elp_base_db::AbsPath;
use elp_ide::elp_ide_db::elp_base_db::AbsPathBuf;
Expand All @@ -33,19 +32,10 @@ pub(crate) fn save_build_info(args: BuildInfo, query_config: &BuckQueryConfig) -
let root = AbsPathBuf::assert(root);
let (_elp_config, manifest) = ProjectManifest::discover(&root)?;
let project = Project::load(&manifest, EqwalizerConfig::default(), query_config)?;
if args.json {
let mut writer = File::create(&args.to)?;
let json_str = serde_json::to_string_pretty::<JsonConfig>(&project.as_json(root))?;
writer.write_all(json_str.as_bytes())?;
Ok(())
} else {
if let Some(build_info_file) = project.build_info_file() {
std::fs::copy(build_info_file, args.to)?;
Ok(())
} else {
bail!("Loaded project does not have build info generated")
}
}
let mut writer = File::create(&args.to)?;
let json_str = serde_json::to_string_pretty::<JsonConfig>(&project.as_json(root))?;
writer.write_all(json_str.as_bytes())?;
Ok(())
}

pub(crate) fn save_project_info(args: ProjectInfo, query_config: &BuckQueryConfig) -> Result<()> {
Expand Down
3 changes: 2 additions & 1 deletion crates/elp/src/resources/test/build_info_help.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Usage: [--project PROJECT] --to TO [--json]
Available options:
--project <PROJECT> Path to directory with project, or to a JSON file (defaults to `.`)
--to <TO> Path to a directory where to dump wa.build_info
--json Generate JSON output rather than Erlang terms
--json Generate JSON output rather than Erlang terms.
DEPRECATED: we now always generate JSON output
-h, --help Prints help information
84 changes: 2 additions & 82 deletions crates/project_model/src/buck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ use paths::RelPathBuf;
use serde::Deserialize;
use serde::Serialize;

use crate::make_build_info;
use crate::otp::Otp;
use crate::path_to_binary;
use crate::save_build_info;
use crate::str_to_binary;
use crate::AppName;
use crate::AppType;
use crate::BuildInfoFile;
use crate::CommandProxy;
use crate::ElpConfig;
use crate::ProjectAppData;
Expand Down Expand Up @@ -166,17 +161,15 @@ impl BuckProject {
pub fn load_from_config(
buck_conf: &BuckConfig,
query_config: &BuckQueryConfig,
) -> Result<(BuckProject, Vec<ProjectAppData>, BuildInfoFile, PathBuf), anyhow::Error> {
) -> Result<(BuckProject, Vec<ProjectAppData>, PathBuf), anyhow::Error> {
let target_info = load_buck_targets(buck_conf, query_config)?;
let otp_root = Otp::find_otp()?;
let project_app_data = targets_to_project_data(&target_info.targets, &otp_root);
let build_info_term = build_info(buck_conf, &project_app_data, &otp_root);
let build_info = save_build_info(build_info_term)?;
let project = BuckProject {
target_info,
buck_conf: buck_conf.clone(),
};
Ok((project, project_app_data, build_info, otp_root))
Ok((project, project_app_data, otp_root))
}

pub fn target(&self, file_path: &AbsPathBuf) -> Option<String> {
Expand Down Expand Up @@ -529,79 +522,6 @@ fn buck_path_to_abs_path(root: &AbsPath, target: &str) -> Result<AbsPathBuf> {
}
}

/// creates erlang term for an app in a format required by eqwalizer
pub fn build_info_app(project_data: &ProjectAppData, ebin: impl AsRef<Path>) -> Term {
let dir = path_to_binary(&project_data.dir);
let ebin = path_to_binary(ebin);

let extra_src_dirs = Term::List(
project_data
.extra_src_dirs
.iter()
.map(|s| str_to_binary(s.as_ref()))
.collect::<Vec<Term>>()
.into(),
);

let include_dirs = Term::List(
project_data
.include_dirs
.iter()
.map(path_to_binary)
.collect::<Vec<Term>>()
.into(),
);

let macros = Term::List(project_data.macros.clone().into());
let name = str_to_binary(&project_data.name.0);
let parse_transforms = Term::List(project_data.parse_transforms.clone().into());

let src_dirs = Term::List(
project_data
.abs_src_dirs
.iter()
.filter_map(|src| src.strip_prefix(project_data.dir.as_ref()))
.map(|path| path_to_binary(path.as_ref()))
.collect::<Vec<Term>>()
.into(),
);

Term::Map(
[
(Atom("dir".into()), dir),
(Atom("ebin".into()), ebin),
(Atom("extra_src_dirs".into()), extra_src_dirs),
(Atom("include_dirs".into()), include_dirs),
(Atom("macros".into()), macros),
(Atom("name".into()), name),
(Atom("parse_transforms".into()), parse_transforms),
(Atom("src_dirs".into()), src_dirs),
]
.into(),
)
}

pub fn build_info(config: &BuckConfig, project_apps: &[ProjectAppData], otp_root: &Path) -> Term {
let mut apps = vec![];
let mut deps = vec![];
let default_ebin = config.buck_root().join("buck-out/ebins");
for project in project_apps {
let ebin = match &project.ebin {
None => default_ebin.as_path(),
Some(ebin) => ebin.as_path(),
};

match project.app_type {
AppType::App => apps.push(build_info_app(project, ebin)),
AppType::Dep if !config.build_deps => apps.push(build_info_app(project, ebin)),
AppType::Dep => deps.push(build_info_app(project, ebin)),
_ => {}
};
}
let path = &config.source_root();
make_build_info(apps, deps, otp_root, path.as_ref())
}

/// convert call//path/target:tgt_name into abs path ~/buckroot/path/target
fn find_buck_file_base_target_dir(
root: &AbsPath,
Expand Down
7 changes: 2 additions & 5 deletions crates/project_model/src/eqwalizer_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ use std::path::PathBuf;

use anyhow::Result;
use dirs;
use eetf::Term;
use include_dir::Dir;
use lazy_static::lazy_static;
use paths::AbsPath;
use paths::AbsPathBuf;

use crate::buck;
use crate::AppName;
use crate::AppType;
use crate::ProjectAppData;
Expand All @@ -30,7 +28,7 @@ lazy_static! {
.join("eqwalizer_support");
}

pub(crate) fn eqwalizer_suppport_data(otp_root: &AbsPath) -> (ProjectAppData, Term) {
pub(crate) fn eqwalizer_suppport_data(otp_root: &AbsPath) -> ProjectAppData {
let eqwalizer_support = AbsPathBuf::assert(EQWALIZER_SUPPORT.to_path_buf());
let eqwalizer_support_app = ProjectAppData {
name: AppName("eqwalizer_support".to_string()),
Expand All @@ -45,8 +43,7 @@ pub(crate) fn eqwalizer_suppport_data(otp_root: &AbsPath) -> (ProjectAppData, Te
include_path: vec![otp_root.to_path_buf()],
};

let eqwalizer_support_term = buck::build_info_app(&eqwalizer_support_app, &eqwalizer_support);
(eqwalizer_support_app, eqwalizer_support_term)
eqwalizer_support_app
}

pub fn setup_eqwalizer_support(project_dir: &Dir) -> Result<()> {
Expand Down
22 changes: 5 additions & 17 deletions crates/project_model/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use paths::AbsPathBuf;
use serde::Deserialize;
use serde::Serialize;

use crate::buck;
use crate::eqwalizer_support;
use crate::AppName;
use crate::AppType;
Expand Down Expand Up @@ -182,21 +181,14 @@ impl JsonConfig {
pub(crate) fn gen_app_data(
config: &JsonConfig,
otp_root: &AbsPath,
) -> (
Vec<ProjectAppData>,
Vec<ProjectAppData>,
Vec<Term>,
Vec<Term>,
) {
let mut terms = vec![];
) -> (Vec<ProjectAppData>, Vec<ProjectAppData>) {
let mut global_includes = indexset![otp_root.to_path_buf()];
let path = config.config_path().parent().unwrap();

fn make_app_data(
path: &AbsPath,
data: &[JsonProjectAppData],
is_dep: bool,
terms: &mut Vec<Term>,
global_includes: &mut IndexSet<AbsPathBuf>,
) -> Vec<ProjectAppData> {
let mut result = vec![];
Expand All @@ -208,9 +200,6 @@ pub(crate) fn gen_app_data(
continue;
}
};
let ebin = app.ebin.clone().unwrap_or(app.dir.join("ebin"));
let term = buck::build_info_app(&app, ebin);
terms.push(term);
let parent = app.dir.parent().map(|path| path.to_path_buf());
if let Some(path) = parent {
global_includes.insert(path);
Expand All @@ -220,19 +209,18 @@ pub(crate) fn gen_app_data(
result
}

let mut apps = make_app_data(path, &config.apps, false, &mut terms, &mut global_includes);
let mut deps = make_app_data(path, &config.deps, true, &mut terms, &mut global_includes);
let mut apps = make_app_data(path, &config.apps, false, &mut global_includes);
let mut deps = make_app_data(path, &config.deps, true, &mut global_includes);

for app in &mut apps {
let mut include_path = global_includes.clone();
include_path.extend(app.include_dirs());
app.include_path = include_path.into_iter().collect();
}
let (eqwalizer_support_app, eqwalizer_support_term) =
eqwalizer_support::eqwalizer_suppport_data(otp_root);
let eqwalizer_support_app = eqwalizer_support::eqwalizer_suppport_data(otp_root);
deps.push(eqwalizer_support_app);

(apps, deps, terms, vec![eqwalizer_support_term])
(apps, deps)
}

fn canonicalize(path: impl AsRef<Path>) -> Result<AbsPathBuf> {
Expand Down
Loading

0 comments on commit baad626

Please sign in to comment.