Skip to content

Commit

Permalink
feat:Add Go Modules Debug Build Flags (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
awood45 authored Jan 21, 2020
1 parent 24f0aca commit 1e63b82
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion aws_lambda_builders/workflows/dotnet_clipackage/actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Actions for Ruby dependency resolution with Bundler
Actions for .NET dependency resolution with CLI Package
"""

import os
Expand Down
10 changes: 8 additions & 2 deletions aws_lambda_builders/workflows/go_modules/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import logging

from aws_lambda_builders.workflow import BuildMode

LOG = logging.getLogger(__name__)

Expand All @@ -18,7 +19,7 @@ class GoModulesBuilder(object):

LANGUAGE = "go"

def __init__(self, osutils, binaries):
def __init__(self, osutils, binaries, mode=BuildMode.RELEASE):
"""Initialize a GoModulesBuilder.
:type osutils: :class:`lambda_builders.utils.OSUtils`
Expand All @@ -30,6 +31,7 @@ def __init__(self, osutils, binaries):
"""
self.osutils = osutils
self.binaries = binaries
self.mode = mode

def build(self, source_dir_path, output_path):
"""Builds a go project onto an output path.
Expand All @@ -44,7 +46,11 @@ def build(self, source_dir_path, output_path):
env.update(self.osutils.environ)
env.update({"GOOS": "linux", "GOARCH": "amd64"})
runtime_path = self.binaries[self.LANGUAGE].binary_path
cmd = [runtime_path, "build", "-o", output_path, source_dir_path]
cmd = [runtime_path, "build"]
if self.mode and self.mode.lower() == BuildMode.DEBUG:
LOG.debug("Debug build requested: Setting configuration to Debug")
cmd += ["-gcflags='all=-N -l'"]
cmd += ["-o", output_path, source_dir_path]

p = self.osutils.popen(cmd, cwd=source_dir_path, env=env, stdout=self.osutils.pipe, stderr=self.osutils.pipe)
out, err = p.communicate()
Expand Down
6 changes: 4 additions & 2 deletions aws_lambda_builders/workflows/go_modules/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class GoModulesWorkflow(BaseWorkflow):

CAPABILITY = Capability(language="go", dependency_manager="modules", application_framework=None)

def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs):
def __init__(
self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, mode=None, **kwargs
):

super(GoModulesWorkflow, self).__init__(
source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs
Expand All @@ -29,7 +31,7 @@ def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtim

output_path = osutils.joinpath(artifacts_dir, handler)

builder = GoModulesBuilder(osutils, binaries=self.binaries)
builder = GoModulesBuilder(osutils, binaries=self.binaries, mode=mode)
self.actions = [GoModulesBuildAction(source_dir, output_path, builder)]

def get_validators(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/workflows/go_modules/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ def test_raises_BuilderError_with_err_text_if_retcode_is_not_0(self):
with self.assertRaises(BuilderError) as raised:
self.under_test.build("source_dir", "output_path")
self.assertEqual(raised.exception.args[0], "Builder Failed: some error text")

def test_debug_configuration_set(self):
self.under_test = GoModulesBuilder(self.osutils, self.binaries, "Debug")
self.under_test.build("source_dir", "output_path")
self.osutils.popen.assert_called_with(
["/path/to/go", "build", "-gcflags='all=-N -l'", "-o", "output_path", "source_dir"],
cwd="source_dir",
env={"GOOS": "linux", "GOARCH": "amd64"},
stderr="PIPE",
stdout="PIPE",
)

0 comments on commit 1e63b82

Please sign in to comment.