利用PowerShell来辅助Borg管理Emacs依赖
2022-01-16 • 预计阅读时间 2 分钟
2022-01-16 • 预计阅读时间 2 分钟
在使用Emacs
的过程中肯定会涉及各种包的管理.最近把包管理换成了Borg。由于自己主要是在Windows
下面使用,官方基于Makefile
的一些脚本用起来就比较尴尬了.所以用Powershell
写了一些辅助的脚本.主要是方便在初始化以后批量更新脚本和编译.
该脚本参考官方的borg.sh
.用来更新和检查各个submodule
.
$hive_remote = git config -f .gitmodules borg.collective
$toplevel = git rev-parse --show-toplevel
$gitModules = (git submodule--helper list) -replace '[ |\t]', ',' | ConvertFrom-Csv -Header mode, sha1, stage, path
foreach ($module in $gitModules) {
if (Test-Path $module.path) {
$name = git submodule--helper name $module.path
write-host "--- [$name] ---" ""
$url = git config -f .gitmodules submodule.$name.url
if (-not(Test-Path "$($module.path)/.git")) {
git submodule--helper clone --name $name --path $($module.path) --url $url
}
## multi remote
$lstRemote = (git config -f .gitmodules --get-all submodule.$name.remote) -replace '[ |\t]', ',' | ConvertFrom-Csv -Header remote, remote_url
foreach ($item in $lstRemote) {
if (-not(Test-Path "$($module.path)/.git")) {
echo "git submodule--helper clone --name $name --path $($module.path) --url $url"
git remote rename origin $item.remote
}
else {
Set-Location $module.path
git remote add $item.remote $item.remote_url
git fetch $item.remote
Set-Location $toplevel
}
if (Test-Path "$($module.path)/.git" ) {
Set-Location $module.path
if ($item.remote -eq $hive_remote){
if (Test-Path "$toplevel/.hive-maint" ) {
git config remote.pushDefault $item.remote
}else{
$branch=git rev-parse --abbrev-ref HEAD
if($branch -ne ""){
git config branch.master.remote $item.remote
}
}
}else{
git config remote.pushDefault $item.remote
}
Set-Location $toplevel
}
}
## check result
if (Test-Path "$($module.path)/.git" ) {
Set-Location $module.path
git reset --hard $module.sha1
if ($LASTEXITCODE -ne 0) {
write-host "futile: Checkout of $($module.sha1) into submodule path $($module.path) failed"
git reset --hard HEAD
exit 1
}
Set-Location $toplevel
}
else {
write-host "futile: Clone of any remote into submodule path $($module.path) failed"
exit 1
}
}
}
包含了两个参数bootstrap
和build
.用来初始化和编译脚本并生成autoloads
# -*- mode: powershell; coding: utf-8; -*-
$buildtype=$args[0]
$EMACS="emacs.exe"
$EMACS_ARGU="-Q --batch"
$BORG_ARGU="-L ~\.emacs.d\lib\borg\ --load borg --funcall borg-elpa-initialize"
$SILENCIO ='--load subr-x --eval (setq byte-compile-warnings ''(not docstrings)) --eval (fset ''original-message (symbol-function ''message)) --eval (fset ''message (lambda (format &rest args) (unless (or (equal format "pcase-memoize: equal first branch, yet different") (equal format "Not registering prefix \\"%s\\" from %s. Affects: %S") (and (stringp (car args)) (string-match-p "Scraping files for" (car args)))) (apply ''original-message format args))))'
function build-drons {
$lstmodule = git config -f .gitmodules --name-only --get-regexp '^submodule\..*\.path$'
$index =1
foreach ($module in $lstmodule) {
if (!$module.contains(".el")){
$moduleName = $module.split(".")[1]
write-host $index "/" $lstmodule.count
$hasbuild = (Get-ChildItem ".\lib\$moduleName\*-autoloads.el" -Recurse).count
if($hasbuild -eq 0){
write-host "building $moduleName ★★★★★★★★★"
$borgBuild = '(borg-build \"'+$moduleName+'\")'
emacs.exe -Q --batch -L ~\.emacs.d\lib\borg\ --load borg --funcall borg-initialize --eval $borgBuild
}else{
write-host $moduleName"was build"
}
}
$index++
}
}
function build-init{
emacs.exe -Q --batch $SILENCIO -L ~\.emacs.d\lib\borg\ --load borg --funcall borg-initialize --funcall borg-batch-rebuild
emacs.exe -Q --batch --eval '(require ''comp nil t)' -L ~\.emacs.d\lib\borg\ --load borg --eval '(borg-build \"ace-link\")'
}
if($buildtype -eq "bootstrap"){
write-host "=== Running 'git submodule init' ==="
git submodule init
write-host "=== Running 'borg.ps1' ==="
.\borg.ps1
}
if ($buildtype -eq "build"){
build-init
}