Skip to content

Commit

Permalink
[#1169] Move and rename the function, add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
fivitti committed Nov 24, 2023
1 parent c19022f commit 315f83a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
37 changes: 32 additions & 5 deletions rakelib/20_build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
# This file is responsible for building (compiling)
# the binaries and other artifacts (docs, bundles).

# Returns the conventional architecture name based on the target architecture
# of the Golang binaries. The architecture is specified by the STORK_GOARCH and
# (optionally) STORK_GOARM environment variables. If they are not set, the
# current architecture is used.
#
# Note that if the 32-bit ARM version is provided in the STORK_GOARM variable,
# the architecture from the STORK_GOARCH or the current architecture is not
# validated to be 32-bit.
def get_target_go_arch()
arch = ENV["STORK_GOARCH"] || ARCH
arm_version_raw = ENV["STORK_GOARM"]
if !arm_version_raw.nil?
arm_version = arm_version_raw.to_i
# The above architecture suffixes were not tested on BSD systems.
# They may not be suitable for this operating system family.
case arm_version
when 0
fail "STORK_GOARM must be a number, got: #{arm_version_raw}"
when 5
arch = "armel"
when 6..7
arch = "armhf"
when 8
puts "STORK_GOARM is ignored for 64-bit ARM (armv8)"
else
fail "Unsupported STORK_GOARM value: #{arm_version_raw}"
end
end
arch
end

# Defines the operating system and architecture combination guard for a file
# task. This guard allows file tasks to depend on the os and architecture used
# to build the Go binaries.
Expand All @@ -15,12 +46,8 @@
# If it is not set, it is not used. It does not affect to `arm64`.
# The function accepts a task to be guarded.
def add_go_os_arch_guard(task_name)
arch = ENV["STORK_GOARCH"] || ARCH
arch = get_target_go_arch()

if !ENV["STORK_GOARM"].nil?
arch = "#{arch}-armv#{ENV["STORK_GOARM"]}"
end

os = ENV["STORK_GOOS"]
if os.nil?
case OS
Expand Down
27 changes: 2 additions & 25 deletions rakelib/40_dist.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ text.each_line do |line|
end
STORK_VERSION = stork_version

def get_arch()
arch = ENV["STORK_GOARCH"] || ARCH
arm_version_raw = ENV["STORK_GOARM"]
if !arm_version_raw.nil?
arm_version = arm_version_raw.to_i
# The above architecture suffixes were not tested on BSD systems.
# They may not be suitable for this operating system family.
case arm_version
when 0
fail "STORK_GOARM must be a number, got: #{arm_version_raw}"
when 5
arch = "armel"
when 6..7
arch = "armhf"
when 8
puts "STORK_GOARCH is ignored for 64-bit ARM (armv8)"
else
fail "Unsupported STORK_GOARM value: #{arm_version_raw}"
end
end
arch
end

def get_pkg_type()
# Read environment variable
if !ENV["PKG_TYPE"].nil?
Expand Down Expand Up @@ -169,7 +146,7 @@ file AGENT_PACKAGE_STUB_FILE => [FPM, MAKE, GCC, agent_dist_dir, pkgs_dir] + age
"-n", "isc-stork-agent",
"-s", "dir",
"-t", pkg_type,
"-a", get_arch(),
"-a", get_target_go_arch(),
"-v", "#{STORK_VERSION}.#{TIMESTAMP}",
"--after-install", "../../etc/hooks/#{pkg_type}/isc-stork-agent.postinst",
"--after-remove", "../../etc/hooks/#{pkg_type}/isc-stork-agent.postrm",
Expand Down Expand Up @@ -287,7 +264,7 @@ file SERVER_PACKAGE_STUB_FILE => [FPM, MAKE, GCC, server_dist_dir, pkgs_dir] + s
"-n", "isc-stork-server",
"-s", "dir",
"-t", pkg_type,
"-a", get_arch(),
"-a", get_target_go_arch(),
"-v", "#{STORK_VERSION}.#{TIMESTAMP}",
"--after-install", "../../etc/hooks/#{pkg_type}/isc-stork-server.postinst",
"--after-remove", "../../etc/hooks/#{pkg_type}/isc-stork-server.postrm",
Expand Down
2 changes: 1 addition & 1 deletion rakelib/90_hooks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace :hook do
"-C", hook_directory,
"-n", "isc-stork-#{kind}-hook-#{hook_name}",
"-t", pkg_type,
"-a", get_arch(),
"-a", get_target_go_arch(),
"-v", "#{STORK_VERSION}.#{TIMESTAMP}",
"--license", "MPL 2.0",
"--url", "https://gitlab.isc.org/isc-projects/stork/",
Expand Down

0 comments on commit 315f83a

Please sign in to comment.