diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc5611..afa01fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,13 @@ ### Changed +- **BREAKING CHANGE**: the syntax for specifying a package from a custom + index has now changed to be consistent with the docs: + + ```toml + "index/explicit" = { version = ">= 0.1.0", index = "index+dir+../index" } + ``` + - **BREAKING CHANGE**: the `backend` field in `index.toml` is now `registry`. diff --git a/Cargo.lock b/Cargo.lock index 46684f3..4b0ac24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,6 +445,7 @@ dependencies = [ "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "simsearch 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -638,6 +639,15 @@ dependencies = [ "tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hashbrown" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "http" version = "0.1.15" @@ -880,6 +890,14 @@ name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "matrixmultiply" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memchr" version = "2.2.0" @@ -992,6 +1010,17 @@ dependencies = [ "tempfile 3.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ndarray" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "matrixmultiply 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "net2" version = "0.2.33" @@ -1016,6 +1045,14 @@ dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num-complex" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-integer" version = "0.1.39" @@ -1319,6 +1356,11 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rawpointer" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rdrand" version = "0.4.0" @@ -1572,6 +1614,14 @@ name = "shell-escape" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "simsearch" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "strsim 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "siphasher" version = "0.2.3" @@ -1643,6 +1693,15 @@ name = "strsim" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "strsim" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "ndarray 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "symlink" version = "0.1.0" @@ -2155,6 +2214,7 @@ dependencies = [ "checksum git2 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "591f8be1674b421644b6c030969520bc3fa12114d2eb467471982ed3e9584e71" "checksum globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4743617a7464bbda3c8aec8558ff2f9429047e025771037df561d383337ff865" "checksum h2 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ddb2b25a33e231484694267af28fec74ac63b5ccf51ee2065a5e313b834d836e" +"checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum http 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1a10e5b573b9a0146545010f50772b9e8b1dd0a256564cc4307694c68832a2f5" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum hyper 0.12.24 (registry+https://github.com/rust-lang/crates.io-index)" = "fdfa9b401ef6c4229745bb6e9b2529192d07b920eed624cdee2a82348cd550af" @@ -2181,6 +2241,7 @@ dependencies = [ "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +"checksum matrixmultiply 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "dcad67dcec2d58ff56f6292582377e6921afdf3bfbd533e26fb8900ae575e002" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425" @@ -2192,9 +2253,11 @@ dependencies = [ "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" "checksum native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ff8e08de0070bbf4c31f452ea2a70db092f36f6f2e4d897adf5674477d488fb2" +"checksum ndarray 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7cf380a8af901ad627594013a3bbac903ae0a6f94e176e47e46b5bbc1877b928" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b30adc557058ce00c9d0d7cb3c6e0b5bc6f36e2e2eabe74b0ba726d194abd588" +"checksum num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "107b9be86cd2481930688277b675b0114578227f034674726605b8a482d8baf8" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" @@ -2229,6 +2292,7 @@ dependencies = [ "checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d" "checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rawpointer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebac11a9d2e11f2af219b8b8d833b76b1ea0e054aa0e8d8e9e4cbde353bdf019" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" @@ -2258,6 +2322,7 @@ dependencies = [ "checksum serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d48f9f99cd749a2de71d29da5f948de7f2764cc5a9d7f3c97e3514d4ee6eabf2" "checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" "checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9" +"checksum simsearch 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "169d5cb326e0780d5c6b7341ddf90afc99795bcd2158693dec3e6e4c20ca2efa" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1a2eec401952cd7b12a84ea120e2d57281329940c3f93c2bf04f462539508e" @@ -2268,6 +2333,7 @@ dependencies = [ "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum strsim 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34ac666ab1423aa93bbd4cd47b6e62db5a846df4e28b959d823776eed5b57643" "checksum symlink 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a" "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" diff --git a/Cargo.toml b/Cargo.toml index 4b019f6..01f49cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ serde_derive = "1.0" serde_json = "1.0" sha2 = "0.7" shell-escape = "0.1" +simsearch = "0.1" slog = { version = "2", features = ["max_level_trace", "release_max_level_warn"] } slog-async = "2" slog-term = "2" diff --git a/src/bin/cmds/search.rs b/src/bin/cmds/search.rs index 1de2164..d7dd536 100644 --- a/src/bin/cmds/search.rs +++ b/src/bin/cmds/search.rs @@ -1,4 +1,4 @@ -use super::{args, get}; +use super::get; use clap::{App, Arg, ArgMatches, SubCommand}; use elba::{ cli::registry, @@ -14,21 +14,13 @@ pub fn cli() -> App<'static, 'static> { .required(true) .help("The search query."), ) - .arg(args::index()) } pub fn exec(c: &mut Config, args: &ArgMatches) -> Res { - let bck = get::index(c, args)?; let query = args.value_of("query").unwrap(); - let bcx = get::build_ctx(c, args); - let bck_text = bck.to_string(); - let ctx = registry::RegistryCtx { - index: bck, - data_dir: c.directories.data.clone(), - }; - println!("{}", registry::search(&bcx, &ctx, &query)?); + println!("{}", registry::search(&bcx, &query)?); - Ok(format!("search complete in index {}", bck_text)) + Ok("search complete".to_string()) } diff --git a/src/lib/build/mod.rs b/src/lib/build/mod.rs index 2f02c8d..c85f0f2 100644 --- a/src/lib/build/mod.rs +++ b/src/lib/build/mod.rs @@ -169,9 +169,7 @@ pub fn compile_lib( let src_walker = source .meta() - .list_files(source.path(), &src_path, |x| { - x.path() != &layout.build - })?; + .list_files(source.path(), &src_path, |x| x.path() != layout.build)?; clear_dir(&layout.build.join("lib"))?; copy_dir_iter(src_walker, &src_path, &layout.build.join("lib"))?; diff --git a/src/lib/cli/registry.rs b/src/lib/cli/registry.rs index 0a387a0..746b321 100644 --- a/src/lib/cli/registry.rs +++ b/src/lib/cli/registry.rs @@ -105,21 +105,28 @@ pub fn yank(bcx: &build::BuildCtx, ctx: &RegistryCtx, name: &Name, ver: &Version Ok(()) } -// TODO: Local fallback -// TODO: Search from multiple indices -pub fn search(bcx: &build::BuildCtx, ctx: &RegistryCtx, query: &str) -> Res { - let mut cache = Cache::from_disk(&bcx.logger, bcx.global_cache.clone(), bcx.shell)?; - let (indices, registry) = get_registry(&mut cache, ctx.index.res.clone(), false); - let registry = registry?; - - let res = registry.search(&indices, query)?; - - let mut s = String::new(); - for x in res.packages { - s.push_str(&format!("\"{}/{}\" = \"{}\"\n", x.group, x.name, x.version)); +pub fn search(bcx: &build::BuildCtx, query: &str) -> Res { + let cache = Cache::from_disk(&bcx.logger, bcx.global_cache.clone(), bcx.shell)?; + let ixs = bcx + .indices + .values() + .cloned() + .map(|x| x.res) + .collect::>(); + let indices = cache.get_indices(&ixs, false, false); + + let pkgs = indices.search(query)?; + let mut res = String::new(); + + for (name, ver, ir) in &pkgs { + if ir.res == ixs[0] { + res.push_str(&format!("\"{}\" = \"{}\"", name, ver)); + } else { + res.push_str(&format!("\"{}\" = \"{{ version = {}, index = {} }}\"", name, ver, ir)); + } } - Ok(s) + Ok(res) } pub fn publish(bcx: &build::BuildCtx, ctx: &RegistryCtx, project: &Path, verify: bool) -> Res<()> { @@ -175,7 +182,11 @@ fn get_token(ctx: &RegistryCtx) -> Res { }) } -fn get_registry(c: &mut Cache, d: DirectRes, eager: bool) -> (remote::Indices, Res) { +fn get_registry( + c: &mut Cache, + d: DirectRes, + eager: bool, +) -> (remote::Indices, Res) { let dt = d.to_string(); let indices = c.get_indices(&[d], eager, false); let registry = (|| { diff --git a/src/lib/package/manifest.rs b/src/lib/package/manifest.rs index 604167e..74cc646 100644 --- a/src/lib/package/manifest.rs +++ b/src/lib/package/manifest.rs @@ -170,8 +170,8 @@ pub struct PackageInfo { pub enum DepReq { Registry(Constraint), RegLong { - con: Constraint, - registry: String, + version: Constraint, + index: String, }, Local { path: PathBuf, @@ -202,14 +202,14 @@ impl DepReq { let pi = PackageId::new(n, def_index.1.clone().into()); Ok((pi, c)) } - DepReq::RegLong { con, registry } => { - if let Some(mapped) = ixmap.get(®istry) { + DepReq::RegLong { version, index } => { + if let Some(mapped) = ixmap.get(&index) { let pi = PackageId::new(n, mapped.clone().into()); - Ok((pi, con)) + Ok((pi, version)) } else { - let ix = IndexRes::from_str(®istry)?; + let ix = IndexRes::from_str(&index)?; let pi = PackageId::new(n, ix.into()); - Ok((pi, con)) + Ok((pi, version)) } } DepReq::Local { path } => { diff --git a/src/lib/remote/index.rs b/src/lib/remote/index.rs index 308a96f..c1ff944 100644 --- a/src/lib/remote/index.rs +++ b/src/lib/remote/index.rs @@ -37,12 +37,14 @@ use semver::Version; use semver_constraints::Constraint; use serde_derive::{Deserialize, Serialize}; use serde_json; +use simsearch::SimSearch; use std::{ fs, io::{self, prelude::*, BufReader}, str::FromStr, }; use toml; +use walkdir::WalkDir; #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IndexConfig { @@ -179,6 +181,29 @@ impl Indices { Err(Error::from(ErrorKind::PackageNotFound)) } } + + pub fn search(&self, query: &str) -> Res> { + let mut engine: SimSearch<(&IndexRes, &str)> = SimSearch::new(); + let x = self + .indices + .iter() + .map(|x| x.1.packages().map(move |p| (x.0, p))) + .flatten() + .collect::>(); + + for (ir, pkg) in &x { + engine.insert((ir, pkg), pkg); + } + let pkgs = engine.search(query); + + pkgs.iter().map(|(ir, pkg)| { + let name = Name::from_str(pkg).unwrap(); + let ix = &self.indices[*ir]; + let ver: Version = ix.entries(&name)?.into_iter().map(|x| x.0).last().unwrap(); + + Ok((name, ver, *ir)) + }).collect::>>() + } } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] @@ -286,6 +311,21 @@ impl Index { Ok(res) } + pub fn packages(&self) -> impl Iterator { + let root_path = self.path.path().to_path_buf(); + let git_path = root_path.join(".git"); + WalkDir::new(self.path.path()) + .min_depth(2) + .max_depth(3) + .into_iter() + .filter_entry(move |x| x.path().parent().unwrap() != git_path) + .filter_map(|x| x.ok()) + .map(move |x| { + let stripped = x.path().strip_prefix(&root_path).unwrap(); + stripped.to_string_lossy().to_string() + }) + } + pub fn depends(&self) -> impl Iterator { self.config.index.dependencies.iter().map(|x| x.1) }