From 3a538f98ed67772189e7bd3fc0e1366ed6ac6047 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Sat, 2 Nov 2019 23:36:28 -0700 Subject: [PATCH] Tightened project discovery behavior --- CHANGELOG.md | 3 +++ src/project.rs | 38 ++++++++++++++++++++------------------ tests/read_projects.rs | 8 -------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7c3e77b..7bef57e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ * Added support for automatically finding Roblox Studio's auth cookie for `rojo upload` on Windows. * Added support for building, serving and uploading sources that aren't Rojo projects. * Improved feedback from `rojo serve`. +* Removed support for legacy `roblox-project.json` projects, deprecated in an early Rojo 0.5.0 alpha. +* Rojo no longer traverses directories upwards looking for project files. + * Though undocumented, Rojo 0.5.x will search for a project file contained in any ancestor folders. This feature was removed to better support other 0.6.x features. ### Roblox Studio Plugin * Added "connecting" state to improve experience when live syncing. diff --git a/src/project.rs b/src/project.rs index d84e1244..fc039f34 100644 --- a/src/project.rs +++ b/src/project.rs @@ -432,31 +432,33 @@ impl Project { Ok(project_path) } - fn locate(start_location: &Path) -> Option { - // TODO: Check for specific error kinds, convert 'not found' to Result. - let location_metadata = fs::metadata(start_location).ok()?; + /// Attempt to locate a project represented by the given path. + /// + /// This will find a project if the path refers to a `.project.json` file, + /// or is a folder that contains a `default.project.json` file. + fn locate(path: &Path) -> Option { + let meta = fs::metadata(path).ok()?; - // If this is a file, assume it's the config the user was looking for. - if location_metadata.is_file() { - if Project::is_project_file(start_location) { - return Some(start_location.to_path_buf()); + if meta.is_file() { + if Project::is_project_file(path) { + Some(path.to_path_buf()) } else { - return None; + None } } else { - let with_file = start_location.join(PROJECT_FILENAME); + let child_path = path.join(PROJECT_FILENAME); + let child_meta = fs::metadata(&child_path).ok()?; - if let Ok(file_metadata) = fs::metadata(&with_file) { - if file_metadata.is_file() { - return Some(with_file); - } + if child_meta.is_file() { + Some(child_path) + } else { + // This is a folder with the same name as a Rojo default project + // file. + // + // That's pretty weird, but we can roll with it. + None } } - - match start_location.parent() { - Some(parent_location) => Self::locate(parent_location), - None => None, - } } fn load_from_str( diff --git a/tests/read_projects.rs b/tests/read_projects.rs index 25844b9b..e2eeaf60 100644 --- a/tests/read_projects.rs +++ b/tests/read_projects.rs @@ -16,14 +16,6 @@ lazy_static! { { Path::new(env!("CARGO_MANIFEST_DIR")).join("test-projects") }; } -#[test] -fn empty() { - let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json"); - let project = Project::load_exact(&project_file_location).unwrap(); - - assert_eq!(project.name, "empty"); -} - #[test] fn empty_fuzzy_file() { let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json");