reduce dups
This commit is contained in:
121
update.ce
121
update.ce
@@ -1,30 +1,28 @@
|
||||
// cell update [<locator>] - Update packages from remote sources
|
||||
//
|
||||
// Usage:
|
||||
// cell update Update all packages in shop
|
||||
// cell update Update all packages
|
||||
// cell update . Update current directory package
|
||||
// cell update <locator> Update a specific package
|
||||
//
|
||||
// Options:
|
||||
// --build Run build after updating
|
||||
// --target <triple> Target platform for build (requires --build)
|
||||
// --target <triple> 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 build = use('build')
|
||||
var fd = use('fd')
|
||||
var os = use('os')
|
||||
var link = use('link')
|
||||
|
||||
var target_pkg = null
|
||||
var run_build = false
|
||||
var target_triple = null
|
||||
var follow_links = false
|
||||
var git_pull = false
|
||||
var i = 0
|
||||
var resolved = null
|
||||
var updated = 0
|
||||
var packages = null
|
||||
|
||||
// Parse arguments
|
||||
for (i = 0; i < length(args); i++) {
|
||||
if (args[i] == '--help' || args[i] == '-h') {
|
||||
log.console("Usage: cell update [<locator>] [options]")
|
||||
@@ -32,13 +30,10 @@ for (i = 0; i < length(args); i++) {
|
||||
log.console("Update packages from remote sources.")
|
||||
log.console("")
|
||||
log.console("Options:")
|
||||
log.console(" --build Run build after updating")
|
||||
log.console(" --target <triple> Target platform for build (requires --build)")
|
||||
log.console(" --target <triple> Target platform for build")
|
||||
log.console(" --follow-links Update link targets instead of origins")
|
||||
log.console(" --git Run git pull on local packages")
|
||||
$stop()
|
||||
} else if (args[i] == '--build') {
|
||||
run_build = true
|
||||
} else if (args[i] == '--target' || args[i] == '-t') {
|
||||
if (i + 1 < length(args)) {
|
||||
target_triple = args[++i]
|
||||
@@ -52,33 +47,22 @@ for (i = 0; i < length(args); i++) {
|
||||
git_pull = 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)) {
|
||||
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()
|
||||
}
|
||||
if (target_pkg)
|
||||
target_pkg = shop.resolve_locator(target_pkg)
|
||||
|
||||
var link = use('link')
|
||||
|
||||
function update_and_fetch(pkg) {
|
||||
function update_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 effective_pkg = pkg
|
||||
var link_target = null
|
||||
var info = shop.resolve_package_info(pkg)
|
||||
var new_entry = null
|
||||
var old_str = null
|
||||
|
||||
// Handle follow-links option
|
||||
if (follow_links) {
|
||||
link_target = link.get_target(pkg)
|
||||
if (link_target) {
|
||||
@@ -87,80 +71,47 @@ function update_and_fetch(pkg) {
|
||||
}
|
||||
}
|
||||
|
||||
// For local packages with --git, pull first
|
||||
if (git_pull && info == 'local' && fd.is_dir(effective_pkg + '/.git')) {
|
||||
log.console(" " + effective_pkg + " (git pull)")
|
||||
os.system('git -C "' + effective_pkg + '" pull')
|
||||
}
|
||||
|
||||
// Check for update (sets lock entry if changed)
|
||||
new_entry = shop.update(effective_pkg)
|
||||
|
||||
if (new_entry) {
|
||||
if (new_entry.commit) {
|
||||
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 - run git pull if requested
|
||||
if (git_pull && fd.is_dir(effective_pkg + '/.git')) {
|
||||
log.console(" " + effective_pkg + " (git pull)")
|
||||
os.system('git -C "' + effective_pkg + '" pull')
|
||||
} else {
|
||||
log.console(" " + effective_pkg + " (local)")
|
||||
}
|
||||
}
|
||||
shop.extract(effective_pkg)
|
||||
shop.build_package_scripts(effective_pkg)
|
||||
return effective_pkg
|
||||
if (new_entry && new_entry.commit) {
|
||||
old_str = old_commit ? text(old_commit, 0, 8) : "(new)"
|
||||
log.console(" " + effective_pkg + " " + old_str + " -> " + text(new_entry.commit, 0, 8))
|
||||
}
|
||||
return null
|
||||
|
||||
// Sync: fetch, extract, build
|
||||
shop.sync(effective_pkg, {target: target_triple})
|
||||
|
||||
return new_entry
|
||||
}
|
||||
|
||||
var updated_packages = []
|
||||
|
||||
var updated = null
|
||||
var packages = null
|
||||
var pkg_count = 0
|
||||
var pkg = null
|
||||
if (target_pkg) {
|
||||
updated = update_and_fetch(target_pkg)
|
||||
if (updated) {
|
||||
push(updated_packages, updated)
|
||||
if (update_one(target_pkg)) {
|
||||
log.console("Updated " + target_pkg + ".")
|
||||
} else {
|
||||
log.console(target_pkg + " is up to date.")
|
||||
}
|
||||
} else {
|
||||
packages = shop.list_packages()
|
||||
pkg_count = length(packages)
|
||||
log.console("Checking for updates (" + text(pkg_count) + " package" + (pkg_count == 1 ? "" : "s") + ")...")
|
||||
log.console("Checking for updates (" + text(length(packages)) + " packages)...")
|
||||
|
||||
for (i = 0; i < length(packages); i++) {
|
||||
pkg = packages[i]
|
||||
if (pkg == 'core') continue
|
||||
arrfor(packages, function(pkg) {
|
||||
if (pkg == 'core') return
|
||||
if (update_one(pkg))
|
||||
updated = updated + 1
|
||||
})
|
||||
|
||||
updated = update_and_fetch(pkg)
|
||||
if (updated) {
|
||||
push(updated_packages, updated)
|
||||
}
|
||||
}
|
||||
|
||||
if (length(updated_packages) > 0) {
|
||||
log.console("Updated " + text(length(updated_packages)) + " package" + (length(updated_packages) == 1 ? "" : "s") + ".")
|
||||
if (updated > 0) {
|
||||
log.console("Updated " + text(updated) + " package(s).")
|
||||
} else {
|
||||
log.console("All packages are up to date.")
|
||||
}
|
||||
}
|
||||
|
||||
// Run build if requested
|
||||
if (run_build && length(updated_packages) > 0) {
|
||||
log.console("")
|
||||
log.console("Building updated packages...")
|
||||
|
||||
arrfor(updated_packages, function(pkg) {
|
||||
var _build = function() {
|
||||
var lib = build.build_dynamic(pkg, target_triple, 'release')
|
||||
if (lib)
|
||||
log.console(" Built: " + lib)
|
||||
} disruption {
|
||||
log.error(" Failed to build " + pkg)
|
||||
}
|
||||
_build()
|
||||
})
|
||||
}
|
||||
|
||||
$stop()
|
||||
|
||||
Reference in New Issue
Block a user