// cell update [] - Update packages from remote sources // // Usage: // cell update Update all packages in shop // cell update . Update current directory package // cell update Update a specific package // // Options: // --build Run build after updating // --target Target platform for build (requires --build) // --follow-links Update link targets instead of origins var shop = use('internal/shop') var build = use('build') var fd = use('fd') var target_pkg = null var run_build = false var target_triple = null var follow_links = false // Parse arguments for (var i = 0; i < args.length; i++) { if (args[i] == '--help' || args[i] == '-h') { log.console("Usage: cell update [] [options]") log.console("") log.console("Update packages from remote sources.") log.console("") log.console("Options:") log.console(" --build Run build after updating") log.console(" --target Target platform for build (requires --build)") log.console(" --follow-links Update link targets instead of origins") $stop() } else if (args[i] == '--build') { run_build = true } else 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] == '--follow-links') { follow_links = true } else if (!starts_with(args[i], '-')) { target_pkg = args[i] // Resolve relative paths to absolute paths if (target_pkg == '.' || starts_with(target_pkg, './') || starts_with(target_pkg, '../') || fd.is_dir(target_pkg)) { var resolved = fd.realpath(target_pkg) if (resolved) { target_pkg = resolved } } } } // Default target if building if (run_build && !target_triple) { target_triple = build.detect_host_target() } var link = use('link') function update_and_fetch(pkg) { var lock = shop.load_lock() var old_entry = lock[pkg] var old_commit = old_entry ? old_entry.commit : null // Handle follow-links option var effective_pkg = pkg if (follow_links) { var link_target = link.get_target(pkg) if (link_target) { effective_pkg = link_target log.console(" Following link: " + pkg + " -> " + effective_pkg) } } var new_entry = shop.update(effective_pkg) if (new_entry) { if (new_entry.commit) { var old_str = old_commit ? text(old_commit, 0, 8) : "(new)" log.console(" " + effective_pkg + " " + old_str + " -> " + text(new_entry.commit, 0, 8)) shop.fetch(effective_pkg) } else { // Local package - just ensure symlink is correct log.console(" " + effective_pkg + " (local)") } shop.extract(effective_pkg) shop.build_package_scripts(effective_pkg) return effective_pkg } return null } var updated_packages = [] if (target_pkg) { var updated = update_and_fetch(target_pkg) if (updated) { updated_packages.push(updated) log.console("Updated " + target_pkg + ".") } else { log.console(target_pkg + " is up to date.") } } else { var packages = shop.list_packages() var pkg_count = packages.length log.console("Checking for updates (" + text(pkg_count) + " package" + (pkg_count == 1 ? "" : "s") + ")...") for (var i = 0; i < packages.length; i++) { var pkg = packages[i] if (pkg == 'core') continue var updated = update_and_fetch(pkg) if (updated) { updated_packages.push(updated) } } if (updated_packages.length > 0) { log.console("Updated " + text(updated_packages.length) + " package" + (updated_packages.length == 1 ? "" : "s") + ".") } else { log.console("All packages are up to date.") } } // Run build if requested if (run_build && updated_packages.length > 0) { log.console("") log.console("Building updated packages...") for (var pkg of updated_packages) { try { var lib = build.build_dynamic(pkg, target_triple, 'release') if (lib) { log.console(" Built: " + lib) } } catch (e) { log.error(" Failed to build " + pkg + ": " + e) } } } $stop()