From 9caae4029bc6339cfda0f548557e8f0d428debbf Mon Sep 17 00:00:00 2001 From: Michael Maslanka Date: Tue, 3 Aug 2021 15:18:51 -0500 Subject: [PATCH 1/3] Create go DSL in builder Signed-off-by: Michael Maslanka --- lib/omnibus/builder.rb | 35 +++++++++++++++++++++++++++++++++++ spec/unit/builder_spec.rb | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/lib/omnibus/builder.rb b/lib/omnibus/builder.rb index 113dae2b2..dc5db0523 100644 --- a/lib/omnibus/builder.rb +++ b/lib/omnibus/builder.rb @@ -292,6 +292,41 @@ def compiler_safe_path(*pieces) end expose :compiler_safe_path + # + # @!endgroup + # -------------------------------------------------- + + # + # @!group Go DSL methods + # + # The following DSL methods are available from within build blocks and + # expose Go DSL methods. + # -------------------------------------------------- + + # + # Execute the given Go command or script against the embedded Go. + # + # @example + # go 'build -o hello' + # + # @param (see #command) + # @return (see #command) + # + def go(command, options = {}) + build_commands << BuildCommand.new("go `#{command}'") do + bin = embedded_bin("go") + + # Check if we are building a go binary and then check if we are on + # Red Hat or CentOS so we build the binary properly with a build-id + if command.start_with? "build" && (rhel? || centos?) + command << " -ldflags=-linkmode=external" + end + + shellout!("#{bin} #{command}", options) + end + end + expose :go + # # @!endgroup # -------------------------------------------------- diff --git a/spec/unit/builder_spec.rb b/spec/unit/builder_spec.rb index 1565c0d65..4b87c9c8c 100644 --- a/spec/unit/builder_spec.rb +++ b/spec/unit/builder_spec.rb @@ -39,6 +39,12 @@ def run_build_command end end + describe "#go" do + it "is a DSL method" do + expect(subject).to have_exposed_method(:go) + end + end + describe "#ruby" do it "is a DSL method" do expect(subject).to have_exposed_method(:ruby) From 8748bd034e97d1f95695908fb0ec71959a19bae0 Mon Sep 17 00:00:00 2001 From: Michael Maslanka Date: Tue, 3 Aug 2021 16:22:15 -0500 Subject: [PATCH 2/3] Add extra build argument with start_with Signed-off-by: Michael Maslanka --- lib/omnibus/builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/omnibus/builder.rb b/lib/omnibus/builder.rb index dc5db0523..c152f23c6 100644 --- a/lib/omnibus/builder.rb +++ b/lib/omnibus/builder.rb @@ -318,7 +318,7 @@ def go(command, options = {}) # Check if we are building a go binary and then check if we are on # Red Hat or CentOS so we build the binary properly with a build-id - if command.start_with? "build" && (rhel? || centos?) + if command.start_with?("build", " build") && (rhel? || centos?) command << " -ldflags=-linkmode=external" end From c2e9aa28d64bee3a3506c078b438927db6d58230 Mon Sep 17 00:00:00 2001 From: Michael Maslanka Date: Wed, 4 Aug 2021 07:59:04 -0500 Subject: [PATCH 3/3] Update Readme for new DSL Signed-off-by: Michael Maslanka --- README.md | 1 + lib/omnibus/builder.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d7096369..abf7d47fe 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ DSL Method | Description `patch` | Apply a patch from disk `workers` | The maximum number of builders `windows_safe_path` | Format the path to be safe for shelling out on Windows +`go` | Execute the code as the embedded Go `ruby` | Execute the code as the embedded Ruby `gem` | Execute the code as the embedded Rubygems `bundle` | Execute the code as the embedded Bundler diff --git a/lib/omnibus/builder.rb b/lib/omnibus/builder.rb index c152f23c6..70d7bed1e 100644 --- a/lib/omnibus/builder.rb +++ b/lib/omnibus/builder.rb @@ -292,7 +292,7 @@ def compiler_safe_path(*pieces) end expose :compiler_safe_path - # + # # @!endgroup # --------------------------------------------------