// cell install - Install a package to the shop // // Usage: // cell install Install a package and its dependencies // cell install . Install current directory package // // Options: // --target Build for target platform // --refresh Refresh floating refs before locking // --dry-run Show what would be installed var shop = use('internal/shop') var build = use('build') var pkg = use('package') var fd = use('fd') if (args.length < 1) { log.console("Usage: cell install [options]") log.console("") log.console("Options:") log.console(" --target Build for target platform") log.console(" --refresh Refresh floating refs before locking") log.console(" --dry-run Show what would be installed") $stop() } var locator = null var target_triple = null var refresh = false var dry_run = false for (var i = 0; i < args.length; i++) { if (args[i] == '--target' || args[i] == '-t') { if (i + 1 < args.length) { target_triple = args[++i] } else { log.error('--target requires a triple') $stop() } } else if (args[i] == '--refresh') { refresh = true } else if (args[i] == '--dry-run') { dry_run = true } else if (args[i] == '--help' || args[i] == '-h') { log.console("Usage: cell install [options]") log.console("") log.console("Install a package and its dependencies to the shop.") log.console("") log.console("Options:") log.console(" --target Build for target platform") log.console(" --refresh Refresh floating refs before locking") log.console(" --dry-run Show what would be installed") $stop() } else if (!args[i].startsWith('-')) { locator = args[i] } } if (!locator) { log.console("Usage: cell install ") $stop() } // Resolve relative paths to absolute paths // Local paths like '.' or '../foo' need to be converted to absolute paths if (locator == '.' || locator.startsWith('./') || locator.startsWith('../') || fd.is_dir(locator)) { var resolved = fd.realpath(locator) if (resolved) { locator = resolved } } // Default target if (!target_triple) { target_triple = build.detect_host_target() } log.console("Installing " + locator + "...") // Gather all packages that will be installed var packages_to_install = [] var skipped_packages = [] var visited = {} function gather_packages(pkg_locator) { if (visited[pkg_locator]) return visited[pkg_locator] = true // Check if this is a local path that doesn't exist if (pkg_locator.startsWith('/') && !fd.is_dir(pkg_locator)) { skipped_packages.push(pkg_locator) log.console(" Skipping missing local package: " + pkg_locator) return } packages_to_install.push(pkg_locator) // Try to read dependencies try { // For packages not yet extracted, we need to update and extract first to read deps var lock = shop.load_lock() if (!lock[pkg_locator]) { if (!dry_run) { var update_result = shop.update(pkg_locator) if (update_result) { shop.extract(pkg_locator) } else { // Update failed - package might not be fetchable log.console("Warning: Could not fetch " + pkg_locator) return } } } else { // Package is in lock, ensure it's extracted if (!dry_run) { shop.extract(pkg_locator) } } var deps = pkg.dependencies(pkg_locator) if (deps) { for (var alias in deps) { var dep_locator = deps[alias] gather_packages(dep_locator) } } } catch (e) { // Package might not have dependencies or cell.toml issue if (!dry_run) { log.console(`Warning: Could not read dependencies for ${pkg_locator}: ${e.message}`) } } } // Gather all packages gather_packages(locator) if (dry_run) { log.console("Would install:") for (var p of packages_to_install) { var lock = shop.load_lock() var exists = lock[p] != null log.console(" " + p + (exists ? " (already installed)" : "")) } if (skipped_packages.length > 0) { log.console("") log.console("Would skip (missing local paths):") for (var p of skipped_packages) { log.console(" " + p) } } $stop() } // Install each package function install_package(pkg_locator) { // Update lock entry shop.update(pkg_locator) // Extract/symlink the package shop.extract(pkg_locator) // Build scripts shop.build_package_scripts(pkg_locator) // Build C code try { build.build_dynamic(pkg_locator, target_triple, 'release') } catch (e) { // Not all packages have C code } } for (var p of packages_to_install) { log.console(" Installing " + p + "...") install_package(p) } var summary = "Installed " + text(packages_to_install.length) + " package(s)." if (skipped_packages.length > 0) { summary += " Skipped " + text(skipped_packages.length) + " missing local path(s)." } log.console(summary) $stop()