// cell update [] - Update packages from remote sources // // Usage: // cell update Update all packages // cell update . Update current directory package // cell update Update a specific package // // Options: // --target Target platform for build // --follow-links Update link targets instead of origins // --git Run git pull on local packages before updating var shop = use('internal/shop') var fd = use('fd') var os = use('internal/os') var link = use('link') var target_pkg = null var target_triple = null var follow_links = false var git_pull = false var i = 0 var packages = null var run = function() { for (i = 0; i < length(args); 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(" --target Target platform for build") log.console(" --follow-links Update link targets instead of origins") log.console(" --git Run git pull on local packages") return } else if (args[i] == '--target' || args[i] == '-t') { if (i + 1 < length(args)) { target_triple = args[++i] } else { log.error('--target requires a triple') return } } else if (args[i] == '--follow-links') { follow_links = true } else if (args[i] == '--git') { git_pull = true } else if (!starts_with(args[i], '-')) { target_pkg = args[i] } } if (target_pkg) target_pkg = shop.resolve_locator(target_pkg) if (target_pkg) { update_single(target_pkg) } else { update_all() } } function check_one(pkg) { var effective_pkg = pkg var link_target = null var lock = shop.load_lock() var old_entry = lock[pkg] var old_commit = old_entry ? old_entry.commit : null var info = shop.resolve_package_info(pkg) var new_entry = null if (follow_links) { link_target = link.get_target(pkg) if (link_target) { effective_pkg = link_target } } if (git_pull && info == 'local' && fd.is_dir(effective_pkg + '/.git')) { log.build(" " + effective_pkg + " (git pull)") os.system('git -C "' + effective_pkg + '" pull') } new_entry = shop.update(effective_pkg) return { pkg: pkg, effective: effective_pkg, old_commit: old_commit, new_entry: new_entry, changed: new_entry != null && new_entry.commit != null } } function sync_one(effective_pkg) { shop.sync(effective_pkg, {target: target_triple}) } function update_single(pkg) { var result = check_one(pkg) var old_str = null if (result.changed) { old_str = result.old_commit ? text(result.old_commit, 0, 8) : "(new)" log.console("==> Upgrading " + result.effective) log.console(" " + old_str + " -> " + text(result.new_entry.commit, 0, 8)) log.console("==> Syncing " + result.effective) sync_one(result.effective) log.console("Updated " + result.effective + ".") } else { log.console(pkg + " is up to date.") } } function update_all() { var results = [] var changed = [] var result = null packages = shop.list_packages() log.console("Checking for updates...") arrfor(packages, function(pkg) { if (pkg == 'core') return result = check_one(pkg) results[] = result if (result.changed) changed[] = result }) if (length(changed) == 0) { log.console("All packages are up to date.") return } log.console("==> Upgrading " + text(length(changed)) + " outdated package" + (length(changed) != 1 ? "s" : "") + ":") arrfor(changed, function(r) { var old_str = r.old_commit ? text(r.old_commit, 0, 8) : "(new)" log.console(" " + r.effective + " " + old_str + " -> " + text(r.new_entry.commit, 0, 8)) }) arrfor(changed, function(r) { log.console("==> Syncing " + r.effective) sync_one(r.effective) }) log.console("Updated " + text(length(changed)) + " package(s).") } run() $stop()