mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
package.rb: Accept environment variables and options in system function (#6538)
* system (#4) * Update const.rb * Update package.rb * Update package.rb * Bump version Co-authored-by: Cassandra Watergate <55339220+saltedcoffii@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Defines common constants used in different parts of crew
|
||||
|
||||
CREW_VERSION = '1.20.0'
|
||||
CREW_VERSION = '1.20.2'
|
||||
|
||||
ARCH_ACTUAL = `uname -m`.chomp
|
||||
# This helps with virtualized builds on aarch64 machines
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
require 'package_helpers'
|
||||
|
||||
class Package
|
||||
property :description, :homepage, :version, :license, :compatibility, :binary_url, :binary_sha256, :source_url, :source_sha256, :git_branch, :git_hashtag, :is_fake
|
||||
property :description, :homepage, :version, :license, :compatibility,
|
||||
:binary_url, :binary_sha256, :source_url, :source_sha256,
|
||||
:git_branch, :git_hashtag, :is_fake
|
||||
|
||||
class << self
|
||||
attr_reader :is_fake
|
||||
@@ -152,39 +154,39 @@ class Package
|
||||
# 3. The value of `nproc`.strip
|
||||
# See lib/const.rb for more details
|
||||
|
||||
if @in_build == true
|
||||
nproc = ''
|
||||
nproc_opt = ''
|
||||
args.each do |arg|
|
||||
params = arg.split(/\W+/)
|
||||
params.each do |param|
|
||||
if param.match(/j(\d)+/)
|
||||
nproc_opt = param
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
nproc = "#{CREW_NPROC}" if nproc_opt == ''
|
||||
if args[0] == "make"
|
||||
# modify ["make", "args", ...] into ["make", "-j#{nproc}", "args", ...]
|
||||
args.insert(1, "-j#{nproc}") if nproc != ''
|
||||
if @opt_verbose then
|
||||
args.insert(1, "V=1")
|
||||
else
|
||||
args.insert(1, "V=0")
|
||||
end
|
||||
elsif args.length == 1
|
||||
# modify ["make args..."] into ["make -j#{nproc} args..."]
|
||||
args[0].gsub!(/^make /, "make -j#{nproc} ") if nproc != ''
|
||||
if @opt_verbose then
|
||||
args[0].gsub!(/^make /, "make V=1 ")
|
||||
else
|
||||
args[0].gsub!(/^make /, "make V=0 ")
|
||||
end
|
||||
end
|
||||
# extract command arguments
|
||||
cmd_args = args.select {|arg| arg.is_a?(String) } .join(' ')
|
||||
|
||||
# extract env variables (if provided)
|
||||
env_options = if args[0].is_a?(Hash)
|
||||
# merge CREW_ENV_OPTIONS and given env variables
|
||||
CREW_ENV_OPTIONS.scan(/\b(.+?)=(.+)\b/).to_h.merge(args[0])
|
||||
else
|
||||
# return CREW_ENV_OPTIONS in hash
|
||||
CREW_ENV_OPTIONS.scan(/\b(.+?)=(.+)\b/).to_h
|
||||
end
|
||||
|
||||
# extract Kernel.system options (if provided)
|
||||
system_options = if args[-1].is_a?(Hash)
|
||||
{ exception: true }.merge(args[-1])
|
||||
else
|
||||
{ exception: true }
|
||||
end
|
||||
|
||||
# add -j arg to build commands
|
||||
cmd_args.sub(/\b(?<=make)(?=\b)/, " -j#{CREW_NPROC}") unless cmd_args =~ /-j\s*\d+/
|
||||
|
||||
begin
|
||||
# use bash instead of /bin/sh
|
||||
Kernel.system env_options,
|
||||
'bash', '-e', '-c',
|
||||
cmd_args, # ensure the command is passed first
|
||||
system_options # pass Kernel.system options (all args after command) then
|
||||
rescue => e
|
||||
exitstatus = $?.exitstatus
|
||||
# print failed line number and error message
|
||||
puts "#{e.backtrace[1]}: #{e.message}".orange
|
||||
raise InstallError.new("`#{cmd_args.join(' ')}` exited with #{exitstatus}")
|
||||
end
|
||||
Kernel.system(*args)
|
||||
exitstatus = $?.exitstatus
|
||||
raise InstallError.new("`#{args.join(" ")}` exited with #{exitstatus}") unless exitstatus == 0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user