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

feat:Add Go Modules Debug Build Flags #145

Merged
merged 4 commits into from
Jan 21, 2020
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
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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that BuildMode.DEBUG is always lower? I would suggest to make it BuildMode.DEBUG.lower() as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following a pattern from the .NET builder, so the aws_lambda_builders/workflow.py::BuildMode enum values are contracted to be lower case, but input is not.

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",
)