From 315f83ae11f73548398f7b60fe3e5b8787f8396d Mon Sep 17 00:00:00 2001 From: Slawek Figiel Date: Thu, 23 Nov 2023 17:16:57 +0100 Subject: [PATCH] [#1169] Move and rename the function, add comment --- rakelib/20_build.rake | 37 ++++++++++++++++++++++++++++++++----- rakelib/40_dist.rake | 27 ++------------------------- rakelib/90_hooks.rake | 2 +- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/rakelib/20_build.rake b/rakelib/20_build.rake index cfb1550a6..d140bb9c1 100644 --- a/rakelib/20_build.rake +++ b/rakelib/20_build.rake @@ -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. @@ -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 diff --git a/rakelib/40_dist.rake b/rakelib/40_dist.rake index 38c9b1a77..f1010909c 100644 --- a/rakelib/40_dist.rake +++ b/rakelib/40_dist.rake @@ -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? @@ -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", @@ -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", diff --git a/rakelib/90_hooks.rake b/rakelib/90_hooks.rake index fc913ca5e..9d23e7edc 100644 --- a/rakelib/90_hooks.rake +++ b/rakelib/90_hooks.rake @@ -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/",