Skip to content

Commit

Permalink
Merge pull request #1032 from chef/mimaslanka/add-go-builder
Browse files Browse the repository at this point in the history
Add new DSL for GO to builder
  • Loading branch information
tas50 authored Aug 10, 2021
2 parents 62bf487 + ff21ad5 commit d0d8367
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions lib/omnibus/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d0d8367

Please sign in to comment.