From 809ba256a38c9c02a5b541730e33d8bf660912af Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Mon, 20 Jan 2020 10:55:43 -0800 Subject: [PATCH 1/4] Add Go Modules Debug Build Flags Required to do IDE debugging of Go functions. --- .../workflows/dotnet_clipackage/actions.py | 2 +- aws_lambda_builders/workflows/go_modules/builder.py | 10 ++++++++-- aws_lambda_builders/workflows/go_modules/workflow.py | 4 ++-- tests/unit/workflows/go_modules/test_builder.py | 11 +++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index accaaad08..dc918fa25 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -1,5 +1,5 @@ """ -Actions for Ruby dependency resolution with Bundler +Actions for .NET dependency resolution with CLI Package """ import os diff --git a/aws_lambda_builders/workflows/go_modules/builder.py b/aws_lambda_builders/workflows/go_modules/builder.py index 38e220768..c9c3cd177 100644 --- a/aws_lambda_builders/workflows/go_modules/builder.py +++ b/aws_lambda_builders/workflows/go_modules/builder.py @@ -3,6 +3,7 @@ """ import logging +from aws_lambda_builders.workflow import BuildMode LOG = logging.getLogger(__name__) @@ -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` @@ -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. @@ -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='-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() diff --git a/aws_lambda_builders/workflows/go_modules/workflow.py b/aws_lambda_builders/workflows/go_modules/workflow.py index a80c1d65a..b148d1df4 100644 --- a/aws_lambda_builders/workflows/go_modules/workflow.py +++ b/aws_lambda_builders/workflows/go_modules/workflow.py @@ -15,7 +15,7 @@ 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 @@ -29,7 +29,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): diff --git a/tests/unit/workflows/go_modules/test_builder.py b/tests/unit/workflows/go_modules/test_builder.py index daea632c6..ab8e656d1 100644 --- a/tests/unit/workflows/go_modules/test_builder.py +++ b/tests/unit/workflows/go_modules/test_builder.py @@ -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='-N -l'", "-o", "output_path", "source_dir"], + cwd="source_dir", + env={"GOOS": "linux", "GOARCH": "amd64"}, + stderr="PIPE", + stdout="PIPE", + ) From 35bd2f63d0e84cd9ff830b46a270225d4c1bc13c Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Mon, 20 Jan 2020 14:55:07 -0800 Subject: [PATCH 2/4] Reformat with Black --- aws_lambda_builders/workflows/go_modules/workflow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/go_modules/workflow.py b/aws_lambda_builders/workflows/go_modules/workflow.py index b148d1df4..0932e81f5 100644 --- a/aws_lambda_builders/workflows/go_modules/workflow.py +++ b/aws_lambda_builders/workflows/go_modules/workflow.py @@ -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, mode=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 From feb815540d4091956075916d141e2f45224ec833 Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Tue, 21 Jan 2020 09:46:45 -0800 Subject: [PATCH 3/4] Use Go 1.10+ Debug Flag Pattern --- tests/unit/workflows/go_modules/test_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/workflows/go_modules/test_builder.py b/tests/unit/workflows/go_modules/test_builder.py index ab8e656d1..5e9b163a1 100644 --- a/tests/unit/workflows/go_modules/test_builder.py +++ b/tests/unit/workflows/go_modules/test_builder.py @@ -54,7 +54,7 @@ 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='-N -l'", "-o", "output_path", "source_dir"], + ["/path/to/go", "build", "-gcflags='all=-N -l'", "-o", "output_path", "source_dir"], cwd="source_dir", env={"GOOS": "linux", "GOARCH": "amd64"}, stderr="PIPE", From 377ad6ca7520dc3db37d05a55eaa2ec631846a86 Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Tue, 21 Jan 2020 09:54:42 -0800 Subject: [PATCH 4/4] HAVE MORE COFFEE ALEX When you update a test, try updating the appropriate code. This is why we have automated test harnesses. --- aws_lambda_builders/workflows/go_modules/builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/go_modules/builder.py b/aws_lambda_builders/workflows/go_modules/builder.py index c9c3cd177..9604c6f64 100644 --- a/aws_lambda_builders/workflows/go_modules/builder.py +++ b/aws_lambda_builders/workflows/go_modules/builder.py @@ -49,7 +49,7 @@ def build(self, source_dir_path, output_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='-N -l'"] + 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)