diff --git a/crates/elp/src/bin/args.rs b/crates/elp/src/bin/args.rs index 9981bf5e36..35d3bed3ee 100644 --- a/crates/elp/src/bin/args.rs +++ b/crates/elp/src/bin/args.rs @@ -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, } diff --git a/crates/elp/src/bin/build_info_cli.rs b/crates/elp/src/bin/build_info_cli.rs index 9959ade992..035573dac4 100644 --- a/crates/elp/src/bin/build_info_cli.rs +++ b/crates/elp/src/bin/build_info_cli.rs @@ -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; @@ -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::(&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::(&project.as_json(root))?; + writer.write_all(json_str.as_bytes())?; + Ok(()) } pub(crate) fn save_project_info(args: ProjectInfo, query_config: &BuckQueryConfig) -> Result<()> { diff --git a/crates/elp/src/resources/test/build_info_help.stdout b/crates/elp/src/resources/test/build_info_help.stdout index c475984ef4..82ca764be4 100644 --- a/crates/elp/src/resources/test/build_info_help.stdout +++ b/crates/elp/src/resources/test/build_info_help.stdout @@ -3,5 +3,6 @@ Usage: [--project PROJECT] --to TO [--json] Available options: --project Path to directory with project, or to a JSON file (defaults 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 diff --git a/crates/project_model/src/buck.rs b/crates/project_model/src/buck.rs index f1c43466de..beb98688d2 100644 --- a/crates/project_model/src/buck.rs +++ b/crates/project_model/src/buck.rs @@ -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; @@ -166,17 +161,15 @@ impl BuckProject { pub fn load_from_config( buck_conf: &BuckConfig, query_config: &BuckQueryConfig, - ) -> Result<(BuckProject, Vec, BuildInfoFile, PathBuf), anyhow::Error> { + ) -> Result<(BuckProject, Vec, 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 { @@ -529,79 +522,6 @@ fn buck_path_to_abs_path(root: &AbsPath, target: &str) -> Result { } } -/// creates erlang term for an app in a format required by eqwalizer -pub fn build_info_app(project_data: &ProjectAppData, ebin: impl AsRef) -> 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::>() - .into(), - ); - - let include_dirs = Term::List( - project_data - .include_dirs - .iter() - .map(path_to_binary) - .collect::>() - .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::>() - .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, diff --git a/crates/project_model/src/eqwalizer_support.rs b/crates/project_model/src/eqwalizer_support.rs index 3365038af8..6024e92299 100644 --- a/crates/project_model/src/eqwalizer_support.rs +++ b/crates/project_model/src/eqwalizer_support.rs @@ -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; @@ -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()), @@ -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<()> { diff --git a/crates/project_model/src/json.rs b/crates/project_model/src/json.rs index 7a8257980d..aaf397205d 100644 --- a/crates/project_model/src/json.rs +++ b/crates/project_model/src/json.rs @@ -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; @@ -182,13 +181,7 @@ impl JsonConfig { pub(crate) fn gen_app_data( config: &JsonConfig, otp_root: &AbsPath, -) -> ( - Vec, - Vec, - Vec, - Vec, -) { - let mut terms = vec![]; +) -> (Vec, Vec) { let mut global_includes = indexset![otp_root.to_path_buf()]; let path = config.config_path().parent().unwrap(); @@ -196,7 +189,6 @@ pub(crate) fn gen_app_data( path: &AbsPath, data: &[JsonProjectAppData], is_dep: bool, - terms: &mut Vec, global_includes: &mut IndexSet, ) -> Vec { let mut result = vec![]; @@ -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); @@ -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) -> Result { diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs index ff571d40f2..efa2475a3c 100644 --- a/crates/project_model/src/lib.rs +++ b/crates/project_model/src/lib.rs @@ -28,8 +28,6 @@ use anyhow::Context; use anyhow::Result; use buck::BuckConfig; use buck::BuckQueryConfig; -use eetf::Term; -use eetf::Term::Atom; use elp_log::timeit; use fxhash::FxHashMap; use glob::glob; @@ -619,7 +617,6 @@ fn app_data_from_path(path: &PathBuf) -> Option { /// server, and CLI invocations to set up ELP for use. #[derive(Clone)] pub struct Project { - pub build_info_file: Option, pub otp: Otp, pub project_build_data: ProjectBuildData, pub project_apps: Vec, @@ -652,7 +649,6 @@ impl PartialEq for Project { impl Project { pub fn otp(otp: Otp, project_apps: Vec) -> Self { Self { - build_info_file: None, otp, project_build_data: ProjectBuildData::Otp, project_apps, @@ -662,7 +658,6 @@ impl Project { pub fn empty(otp: Otp) -> Self { Self { - build_info_file: None, otp, project_build_data: ProjectBuildData::Rebar(Default::default()), project_apps: Vec::default(), @@ -718,12 +713,6 @@ impl Project { .unwrap_or_else(move || root.as_os_str().to_string_lossy().to_string()) } - pub fn build_info_file(&self) -> Option { - self.build_info_file - .as_ref() - .map(|info| info.build_info_file()) - } - pub fn deps_ebins(&self) -> Vec { self.deps().flat_map(|app| app.ebin.clone()).collect() } @@ -919,7 +908,7 @@ impl Project { eqwalizer_config: EqwalizerConfig, query_config: &BuckQueryConfig, ) -> Result { - let (project_build_info, mut project_apps, build_info, otp_root) = match manifest { + let (project_build_info, mut project_apps, otp_root) = match manifest { ProjectManifest::Rebar(rebar_setting) => { let _timer = timeit!( "load project from rebar config {}", @@ -946,69 +935,37 @@ impl Project { manifest ) })?; - ( - ProjectBuildData::Rebar(rebar_project), - apps, - Some(BuildInfoFile::TempPath(Arc::new(loaded))), - otp_root, - ) + (ProjectBuildData::Rebar(rebar_project), apps, otp_root) } ProjectManifest::TomlBuck(buck) => { // We only select this manifest if buck is actually enabled - let (project, apps, build_info, otp_root) = - BuckProject::load_from_config(buck, query_config)?; - ( - ProjectBuildData::Buck(project), - apps, - Some(build_info), - otp_root, - ) + let (project, apps, otp_root) = BuckProject::load_from_config(buck, query_config)?; + (ProjectBuildData::Buck(project), apps, otp_root) } ProjectManifest::Json(config) => { let otp_root = Otp::find_otp()?; let config_path = config.config_path().to_path_buf(); - let (mut apps, deps, terms, deps_terms) = - json::gen_app_data(config, AbsPath::assert(&otp_root)); - let build_info_term = make_build_info(terms, deps_terms, &otp_root, &config_path); - let build_info = save_build_info(build_info_term)?; + let (mut apps, deps) = json::gen_app_data(config, AbsPath::assert(&otp_root)); let project = StaticProject { config_path }; apps.extend(deps); - ( - ProjectBuildData::Static(project), - apps, - Some(build_info), - otp_root, - ) + (ProjectBuildData::Static(project), apps, otp_root) } ProjectManifest::NoManifest(config) => { let otp_root = Otp::find_otp()?; let abs_otp_root = AbsPath::assert(&otp_root); let config_path = config.config_path().to_path_buf(); - let (mut apps, terms) = config.to_project_app_data(abs_otp_root); - let (eqwalizer_support_app, eqwalizer_support_term) = + let mut apps = config.to_project_app_data(abs_otp_root); + let eqwalizer_support_app = eqwalizer_support::eqwalizer_suppport_data(abs_otp_root); - let build_info_term = make_build_info( - terms, - vec![eqwalizer_support_term], - abs_otp_root, - &config_path, - ); - let build_info = save_build_info(build_info_term)?; let project = StaticProject { config_path }; apps.push(eqwalizer_support_app); - ( - ProjectBuildData::Static(project), - apps, - Some(build_info), - otp_root, - ) + (ProjectBuildData::Static(project), apps, otp_root) } }; let (otp, otp_project_apps) = Otp::discover(otp_root); project_apps.extend(otp_project_apps); Ok(Project { - build_info_file: build_info, otp, project_build_data: project_build_info, project_apps, @@ -1049,42 +1006,6 @@ pub fn utf8_stdout(cmd: &mut Command) -> Result { Ok(stdout.trim().to_string()) } -pub fn make_build_info( - apps: Vec, - deps: Vec, - otp_root: impl AsRef, - source_root: impl AsRef, -) -> Term { - let apps = Term::List(apps.into()); - let deps = Term::List(deps.into()); - let otp_lib_dir = path_to_binary(otp_root); - let source_root = path_to_binary(source_root); - Term::Map( - [ - (Atom("apps".into()), apps), - (Atom("deps".into()), deps), - (Atom("otp_lib_dir".into()), otp_lib_dir), - (Atom("source_root".into()), source_root), - ] - .into(), - ) -} - -fn str_to_binary(s: &str) -> Term { - Term::Binary(s.as_bytes().into()) -} - -fn path_to_binary(path: impl AsRef) -> Term { - str_to_binary(path.as_ref().as_os_str().to_str().unwrap()) -} - -pub fn save_build_info(term: Term) -> Result { - let mut out_file = NamedTempFile::new()?; - term.encode(&mut out_file)?; - let build_info_path = out_file.into_temp_path(); - Ok(BuildInfoFile::TempPath(Arc::new(build_info_path))) -} - #[cfg(test)] mod tests { use std::fs; diff --git a/crates/project_model/src/no_manifest.rs b/crates/project_model/src/no_manifest.rs index 71e6b4821f..9f4e29ac7b 100644 --- a/crates/project_model/src/no_manifest.rs +++ b/crates/project_model/src/no_manifest.rs @@ -9,11 +9,9 @@ use std::fs; -use eetf::Term; use paths::AbsPath; use paths::AbsPathBuf; -use crate::buck; use crate::AppName; use crate::AppType; use crate::ProjectAppData; @@ -56,7 +54,7 @@ impl NoManifestConfig { &self.config_path } - pub fn to_project_app_data(&self, otp_root: &AbsPath) -> (Vec, Vec) { + pub fn to_project_app_data(&self, otp_root: &AbsPath) -> Vec { let mut data = ProjectAppData { name: self.name.clone(), dir: self.root_path.clone(), @@ -73,7 +71,6 @@ impl NoManifestConfig { if let Some(path) = self.root_path.parent() { data.include_path.push(path.to_path_buf()); } - let term = buck::build_info_app(&data, &self.root_path); - (vec![data], vec![term]) + vec![data] } }