Skip to content

Commit

Permalink
feat(ref): allow overriding git SHA
Browse files Browse the repository at this point in the history
This allows building old commits for a specified branch, as if you had
built it when the specified commit was the latest commit on the branch.
  • Loading branch information
jimeh committed Aug 20, 2020
1 parent 9dab919 commit eebda4d
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions build-emacs-for-macos
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ require 'date'
require 'etc'
require 'fileutils'
require 'json'
require 'net/http'
require 'optparse'
require 'pathname'
require 'uri'

def err(msg = nil)
warn("ERROR: #{msg}") if msg
Expand All @@ -15,8 +17,7 @@ end

class Build
DOWNLOAD_URL = 'https://github.com/emacs-mirror/emacs/tarball/%s'
LATEST_URL = 'https://api.github.com/repos/' \
'emacs-mirror/emacs/commits?sha=%s'
LATEST_URL = 'https://api.github.com/repos/emacs-mirror/emacs/commits/%s'
NATIVE_COMP_REF_REGEXP = %r{^feature/native-comp}.freeze

attr_reader :root_dir
Expand Down Expand Up @@ -313,15 +314,19 @@ class Build
end

def meta
@meta ||= begin
response = `curl "#{LATEST_URL % ref}" 2>/dev/null`
meta = JSON.parse(response).first
return @meta if @meta

{
sha: meta['sha'],
date: Date.parse(meta['commit']['committer']['date'])
}
end
url = format(LATEST_URL, (options[:git_sha] || ref))
commit = JSON.parse(http_get(url))

@meta = {
sha: commit['sha'],
date: Date.parse(commit['commit']['committer']['date'])
}
end

def http_get(url)
Net::HTTP.get(URI.parse(url))
end

def run_cmd(*args)
Expand Down Expand Up @@ -538,6 +543,11 @@ if __FILE__ == $PROGRAM_NAME
Options:
DOC

opts.on('--git-sha=SHA', 'Override detected git SHA of specified branch ' \
'allowing builds of old commits') do |v|
cli_options[:git_sha] = v
end

opts.on('-j', '--parallel COUNT',
'Compile using COUNT parallel processes ' \
"(detected: #{cli_options[:parallel]})") do |v|
Expand Down

0 comments on commit eebda4d

Please sign in to comment.