Compare commits

...

11 Commits

Author SHA1 Message Date
Alhadis
6efa18e071 Force removal when replacing old grammar modules 2018-04-15 19:44:24 +10:00
Alhadis
573b158250 Fix various syntax and logic errors 2018-04-15 19:18:50 +10:00
Alhadis
f810d7fe7d Store and revert changes made to vendor/README.md 2018-04-14 05:11:47 +10:00
Alhadis
741bb6a76b Fix #4056: Ungraceful UX when add-grammar fails 2018-04-14 04:01:32 +10:00
Alhadis
e7f72cd528 Revert every commit made while sleep-deprived
JFC, I have no sense of boundaries when exhausted.

Reverts: 6669270e84 [CRAP: part Ⅱ]
Reverts: 13f83372a2 [@vmg decides]
Reverts: 4fadaf80e0 [CRAP: part Ⅰ]

... which are all moot points, since this is a topic-branch that's being
squash-merged, and this commit exists only for @lildude's sick amusement
(and the off-chance parts of it are worth salvaging).
2018-04-14 03:24:55 +10:00
Alhadis
6669270e84 Commit in-progress work to request sanity check 2018-04-13 22:54:18 +10:00
Alhadis
f34c741c29 Merge branch 'master' into script-fixes 2018-04-12 21:24:34 +10:00
Alhadis
28ba2bc93d Merge branch 'master' into script-fixes 2018-04-12 19:14:00 +10:00
Alhadis
4fadaf80e0 Begin refactoring classes used by add-grammar 2018-04-12 19:01:10 +10:00
Alhadis
d2f2f91a89 add-grammar: use abspath when caching license file
Fixes breakage caused by passing a relative dependency path to licensed.
2018-04-09 14:12:11 +10:00
Alhadis
13f83372a2 add-grammar: avoid running Docker by default 2018-04-09 13:24:48 +10:00

View File

@@ -43,24 +43,32 @@ def log(msg)
puts msg if $verbose
end
$aborted = false
def command(*args)
log "$ #{args.join(' ')}"
output, status = Open3.capture2e(*args)
if !status.success?
output.each_line do |line|
log " > #{line}"
end
output = output.each_line { |line| " > #{line}" }
unless $aborted
$aborted = true
warn "Command failed. Aborting."
raise output
else
warn output
exit 1
end
end
end
usage = """Usage:
usage = <<~EOH
Usage:
#{$0} [-v|--verbose] [--replace grammar] url
Examples:
#{$0} https://github.com/Alhadis/language-roff
#{$0} --replace sublime-apl https://github.com/Alhadis/language-apl
"""
EOH
$replace = nil
$verbose = true
@@ -81,41 +89,71 @@ $url = ARGV[0]
# No URL? Print a usage message and bail.
unless $url
warn usage
exit 1;
exit 1
end
# Exit early if docker isn't installed or running.
log "Checking docker is installed and running"
# Flags to track which changes should be reverted on an error
$gitmodules = File.read("#{ROOT}/.gitmodules")
$git_config = File.read("#{ROOT}/.git/config")
$vendor_list = File.read("#{ROOT}/vendor/README.md")
def restore_configs
File.write("#{ROOT}/.gitmodules", $gitmodules)
File.write("#{ROOT}/.git/config", $git_config)
end
begin
# Exit early if Docker isn't installed or running.
log "Checking Docker is installed and running"
command('docker', 'ps')
# Ensure the given URL is an HTTPS link
parts = parse_url $url
https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
repo_new = "vendor/grammars/#{parts[:repo]}"
repo_old = parse_submodule($replace) if $replace
$https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
$repo_new = "vendor/grammars/#{parts[:repo]}"
$repo_old = parse_submodule($replace) if $replace
Dir.chdir(ROOT)
if repo_old
log "Deregistering: #{repo_old}"
command('git', 'submodule', 'deinit', repo_old)
command('git', 'rm', '-rf', repo_old)
if $repo_old
log "Deregistering: #{$repo_old}"
command('git', 'submodule', 'deinit', '-f', $repo_old)
command('git', 'rm', '-rf', $repo_old)
command('script/grammar-compiler', 'update', '-f')
end
log "Registering new submodule: #{repo_new}"
command('git', 'submodule', 'add', '-f', https, repo_new)
command('script/grammar-compiler', 'add', repo_new)
log "Registering new submodule: #{$repo_new}"
command('git', 'submodule', 'add', '-f', $https, $repo_new)
command('script/grammar-compiler', 'add', $repo_new)
log "Confirming license"
if repo_old
if $repo_old
command('script/licensed')
else
repo_new = File.absolute_path(repo_new)
command('script/licensed', '--module', repo_new)
repo_abs = File.absolute_path($repo_new)
command('script/licensed', '--module', repo_abs)
end
log "Updating grammar documentation in vendor/README.md"
command('bundle', 'exec', 'rake', 'samples')
command('script/sort-submodules')
command('script/list-grammars')
rescue => ex
log ex
if $repo_new
`git reset HEAD .gitmodules #{$repo_new}`
`git checkout -- vendor/licenses`
`rm -rf #{$repo_new}`
`rm -rf .git/modules/#{$repo_new}/`
restore_configs()
end
if $repo_old
`rm -rf #{$repo_old}`
`git submodule add -f "#{$https}", "#{$repo_old}"`
restore_configs()
end
File.write("#{ROOT}/vendor/README.md", $vendor_list)
`git reset HEAD vendor/licenses`
`git checkout -- vendor/licenses`
exit 1
end