Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new DSL for GO to builder #1032

Merged
merged 4 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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