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 113dae2b2..70d7bed1e 100644 --- a/lib/omnibus/builder.rb +++ b/lib/omnibus/builder.rb @@ -296,6 +296,41 @@ def compiler_safe_path(*pieces) # @!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", " build") && (rhel? || centos?) + command << " -ldflags=-linkmode=external" + end + + shellout!("#{bin} #{command}", options) + end + end + expose :go + + # + # @!endgroup + # -------------------------------------------------- + # # @!group Ruby DSL methods # 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)