From 980000e8557ede3fbb14c52b12faa12f7919244d Mon Sep 17 00:00:00 2001 From: Eric Ratliff Date: Sun, 25 Jan 2026 17:57:49 -0600 Subject: [PATCH] project now builds properly --- src/commands/new.rs | 2 +- src/commands/sdk.rs | 2 +- src/commands/upgrade.rs | 21 +++++++++++++++++++++ src/sdk/ftc.rs | 26 +++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/commands/new.rs b/src/commands/new.rs index 4cdb05c..ea1e338 100644 --- a/src/commands/new.rs +++ b/src/commands/new.rs @@ -71,7 +71,7 @@ fn ensure_sdks(config: &SdkConfig) -> Result<()> { // Check FTC SDK if !config.ftc_sdk_path.exists() { println!("FTC SDK not found. Installing..."); - crate::sdk::ftc::install(&config.ftc_sdk_path)?; + crate::sdk::ftc::install(&config.ftc_sdk_path, &config.android_sdk_path)?; } else { println!("{} FTC SDK found at: {}", "✓".green(), config.ftc_sdk_path.display()); crate::sdk::ftc::verify(&config.ftc_sdk_path)?; diff --git a/src/commands/sdk.rs b/src/commands/sdk.rs index 3e7555c..ddc3aa6 100644 --- a/src/commands/sdk.rs +++ b/src/commands/sdk.rs @@ -9,7 +9,7 @@ pub fn install_sdks() -> Result<()> { let config = SdkConfig::new()?; // Install FTC SDK - crate::sdk::ftc::install(&config.ftc_sdk_path)?; + crate::sdk::ftc::install(&config.ftc_sdk_path, &config.android_sdk_path)?; // Install Android SDK crate::sdk::android::install(&config.android_sdk_path)?; diff --git a/src/commands/upgrade.rs b/src/commands/upgrade.rs index 0cd0b91..e31c1e2 100644 --- a/src/commands/upgrade.rs +++ b/src/commands/upgrade.rs @@ -20,6 +20,9 @@ pub fn upgrade_project(path: &str) -> Result<()> { // Get SDK config let sdk_config = crate::sdk::SdkConfig::new()?; + // Ensure FTC SDK has local.properties (in case it was installed before this feature) + ensure_local_properties(&sdk_config)?; + // Load or create project config let project_config = if has_config { println!("Found existing .weevil.toml"); @@ -115,5 +118,23 @@ pub fn upgrade_project(path: &str) -> Result<()> { println!("Test it: ./gradlew test"); println!(); + Ok(()) +} + +fn ensure_local_properties(sdk_config: &crate::sdk::SdkConfig) -> Result<()> { + let local_properties_path = sdk_config.ftc_sdk_path.join("local.properties"); + + if !local_properties_path.exists() { + println!("Creating local.properties in FTC SDK..."); + let android_sdk_str = sdk_config.android_sdk_path + .display() + .to_string() + .replace("\\", "/"); + + let local_properties = format!("sdk.dir={}\n", android_sdk_str); + fs::write(&local_properties_path, local_properties)?; + println!("{} Created local.properties", "✓".green()); + } + Ok(()) } \ No newline at end of file diff --git a/src/sdk/ftc.rs b/src/sdk/ftc.rs index 4dcb949..778cece 100644 --- a/src/sdk/ftc.rs +++ b/src/sdk/ftc.rs @@ -2,16 +2,19 @@ use std::path::Path; use anyhow::{Result, Context}; use git2::Repository; use colored::*; +use std::fs; const FTC_SDK_URL: &str = "https://github.com/FIRST-Tech-Challenge/FtcRobotController.git"; const FTC_SDK_VERSION: &str = "v10.1.1"; -pub fn install(sdk_path: &Path) -> Result<()> { +pub fn install(sdk_path: &Path, android_sdk_path: &Path) -> Result<()> { if sdk_path.exists() { println!("{} FTC SDK already installed at: {}", "✓".green(), sdk_path.display() ); + // Make sure local.properties exists even if SDK was already installed + create_local_properties(sdk_path, android_sdk_path)?; return check_version(sdk_path); } @@ -28,11 +31,32 @@ pub fn install(sdk_path: &Path) -> Result<()> { repo.checkout_tree(&obj, None)?; repo.set_head_detached(obj.id())?; + // Create local.properties with Android SDK path + create_local_properties(sdk_path, android_sdk_path)?; + println!("{} FTC SDK installed successfully", "✓".green()); Ok(()) } +fn create_local_properties(sdk_path: &Path, android_sdk_path: &Path) -> Result<()> { + // Convert path to use forward slashes (works on both Windows and Unix) + let android_sdk_str = android_sdk_path + .display() + .to_string() + .replace("\\", "/"); + + let local_properties = format!("sdk.dir={}\n", android_sdk_str); + + let properties_path = sdk_path.join("local.properties"); + fs::write(&properties_path, local_properties) + .context("Failed to create local.properties")?; + + println!("{} Created local.properties with Android SDK path", "✓".green()); + + Ok(()) +} + fn check_version(sdk_path: &Path) -> Result<()> { let repo = Repository::open(sdk_path)?;