Skip to content

Commit f40c0ae

Browse files
authored
Merge pull request #111 from awslabs/develop
0.3.0 release
2 parents 7151aaa + a58cfa6 commit f40c0ae

File tree

12 files changed

+87
-31
lines changed

12 files changed

+87
-31
lines changed

aws_lambda_builders/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
22
AWS Lambda Builder Library
33
"""
4-
__version__ = '0.2.1'
5-
RPC_PROTOCOL_VERSION = "0.2"
4+
__version__ = '0.3.0'
5+
RPC_PROTOCOL_VERSION = "0.3"

aws_lambda_builders/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def main(): # pylint: disable=too-many-statements
133133
executable_search_paths=params.get('executable_search_paths', None),
134134
runtime=params["runtime"],
135135
optimizations=params["optimizations"],
136-
options=params["options"])
136+
options=params["options"],
137+
mode=params.get('mode', None))
137138

138139
# Return a success response
139140
response = _success_response(request_id, artifacts_dir)

aws_lambda_builders/builder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, language, dependency_manager, application_framework, supporte
5656
LOG.debug("Found workflow '%s' to support capabilities '%s'", self.selected_workflow_cls.NAME, self.capability)
5757

5858
def build(self, source_dir, artifacts_dir, scratch_dir, manifest_path,
59-
runtime=None, optimizations=None, options=None, executable_search_paths=None):
59+
runtime=None, optimizations=None, options=None, executable_search_paths=None, mode=None):
6060
"""
6161
Actually build the code by running workflows
6262
@@ -93,6 +93,10 @@ def build(self, source_dir, artifacts_dir, scratch_dir, manifest_path,
9393
:type executable_search_paths: list
9494
:param executable_search_paths:
9595
Additional list of paths to search for executables required by the workflow.
96+
97+
:type mode: str
98+
:param mode:
99+
Optional, Mode the build should produce
96100
"""
97101

98102
if not os.path.exists(scratch_dir):
@@ -105,7 +109,8 @@ def build(self, source_dir, artifacts_dir, scratch_dir, manifest_path,
105109
runtime=runtime,
106110
optimizations=optimizations,
107111
options=options,
108-
executable_search_paths=executable_search_paths)
112+
executable_search_paths=executable_search_paths,
113+
mode=mode)
109114

110115
return workflow.run()
111116

aws_lambda_builders/workflow.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
Capability = namedtuple('Capability', ["language", "dependency_manager", "application_framework"])
2626

2727

28+
class BuildMode(object):
29+
30+
DEBUG = "debug"
31+
RELEASE = "release"
32+
33+
2834
# TODO: Move sanitize out to its own class.
2935
def sanitize(func):
3036
"""
@@ -119,7 +125,8 @@ def __init__(self,
119125
runtime=None,
120126
executable_search_paths=None,
121127
optimizations=None,
122-
options=None):
128+
options=None,
129+
mode=BuildMode.RELEASE):
123130
"""
124131
Initialize the builder with given arguments. These arguments together form the "public API" that each
125132
build action must support at the minimum.
@@ -157,6 +164,10 @@ def __init__(self,
157164
:type executable_search_paths: list
158165
:param executable_search_paths:
159166
Optional, Additional list of paths to search for executables required by the workflow.
167+
168+
:type mode: str
169+
:param mode:
170+
Optional, Mode the build should produce
160171
"""
161172

162173
self.source_dir = source_dir
@@ -167,6 +178,7 @@ def __init__(self,
167178
self.optimizations = optimizations
168179
self.options = options
169180
self.executable_search_paths = executable_search_paths
181+
self.mode = mode
170182

171183
# Actions are registered by the subclasses as they seem fit
172184
self.actions = []

aws_lambda_builders/workflows/dotnet_clipackage/actions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77

88
from aws_lambda_builders.actions import BaseAction, Purpose, ActionFailedError
9+
from aws_lambda_builders.workflow import BuildMode
910
from .utils import OSUtils
1011
from .dotnetcli import DotnetCLIExecutionError
1112

@@ -49,12 +50,13 @@ class RunPackageAction(BaseAction):
4950
DESCRIPTION = "Execute the `dotnet lambda package` command."
5051
PURPOSE = Purpose.COMPILE_SOURCE
5152

52-
def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, os_utils=None):
53+
def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, os_utils=None):
5354
super(RunPackageAction, self).__init__()
5455
self.source_dir = source_dir
5556
self.subprocess_dotnet = subprocess_dotnet
5657
self.artifacts_dir = artifacts_dir
5758
self.options = options
59+
self.mode = mode
5860
self.os_utils = os_utils if os_utils else OSUtils()
5961

6062
def execute(self):
@@ -66,6 +68,10 @@ def execute(self):
6668

6769
arguments = ['lambda', 'package', '--output-package', zipfullpath]
6870

71+
if self.mode and self.mode.lower() == BuildMode.DEBUG:
72+
LOG.debug("Debug build requested: Setting configuration to Debug")
73+
arguments += ["--configuration", "Debug"]
74+
6975
if self.options is not None:
7076
for key in self.options:
7177
if str.startswith(key, "-"):

aws_lambda_builders/workflows/dotnet_clipackage/workflow.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self,
2626
scratch_dir,
2727
manifest_path,
2828
runtime=None,
29+
mode=None,
2930
**kwargs):
3031

3132
super(DotnetCliPackageWorkflow, self).__init__(
@@ -34,13 +35,18 @@ def __init__(self,
3435
scratch_dir,
3536
manifest_path,
3637
runtime=runtime,
38+
mode=mode,
3739
**kwargs)
3840

3941
options = kwargs["options"] if "options" in kwargs else {}
4042
subprocess_dotnetcli = SubprocessDotnetCLI(os_utils=OSUtils())
4143
dotnetcli_install = GlobalToolInstallAction(subprocess_dotnet=subprocess_dotnetcli)
4244

43-
dotnetcli_deployment = RunPackageAction(source_dir, subprocess_dotnet=subprocess_dotnetcli, artifacts_dir=artifacts_dir, options=options)
45+
dotnetcli_deployment = RunPackageAction(source_dir,
46+
subprocess_dotnet=subprocess_dotnetcli,
47+
artifacts_dir=artifacts_dir,
48+
options=options,
49+
mode=mode)
4450
self.actions = [
4551
dotnetcli_install,
4652
dotnetcli_deployment,

aws_lambda_builders/workflows/java_gradle/gradle_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def validated_binary_path(self):
4343
def _get_major_version(self, gradle_path):
4444
vs = self._get_jvm_string(gradle_path)
4545
if vs:
46-
m = re.search(r'JVM:\s+(\d.*)', vs)
46+
m = re.search(r'JVM:\s+([\d\.]+)', vs)
4747
version = m.group(1).split('.')
4848
# For Java 8 or earlier, version strings begin with 1.{Major Version}
4949
if version[0] == '1':

aws_lambda_builders/workflows/java_maven/maven_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def validated_binary_path(self):
4343
def _get_major_version(self, maven_path):
4444
vs = self._get_jvm_string(maven_path)
4545
if vs:
46-
m = re.search(r'Java version:\s+(\d.*)', vs)
46+
m = re.search(r'Java version:\s+([\d\.]+)', vs)
4747
version = m.group(1).split('.')
4848
# For Java 8 or earlier, version strings begin with 1.{Major Version}
4949
if version[0] == '1':

tests/unit/test_builder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ def __init__(self,
7979
runtime=None,
8080
optimizations=None,
8181
options=None,
82-
executable_search_paths=None):
82+
executable_search_paths=None,
83+
mode=None):
8384
super(MyWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path,
8485
runtime=runtime, optimizations=optimizations, options=options,
85-
executable_search_paths=executable_search_paths)
86+
executable_search_paths=executable_search_paths, mode=mode)
8687

8788
# Don't load any other workflows. The above class declaration will automatically load the workflow into registry
8889
builder = LambdaBuilder(self.lang, self.lang_framework, self.app_framework, supported_workflows=[])
@@ -121,11 +122,11 @@ def test_with_mocks(self, scratch_dir_exists, get_workflow_mock, importlib_mock,
121122

122123
builder.build("source_dir", "artifacts_dir", "scratch_dir", "manifest_path",
123124
runtime="runtime", optimizations="optimizations", options="options",
124-
executable_search_paths="executable_search_paths")
125+
executable_search_paths="executable_search_paths", mode=None)
125126

126127
workflow_cls.assert_called_with("source_dir", "artifacts_dir", "scratch_dir", "manifest_path",
127128
runtime="runtime", optimizations="optimizations", options="options",
128-
executable_search_paths="executable_search_paths")
129+
executable_search_paths="executable_search_paths", mode=None)
129130
workflow_instance.run.assert_called_once()
130131
os_mock.path.exists.assert_called_once_with("scratch_dir")
131132
if scratch_dir_exists:

tests/unit/workflows/dotnet_clipackage/test_actions.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@ class TestGlobalToolInstallAction(TestCase):
1414
def setUp(self, MockSubprocessDotnetCLI):
1515
self.subprocess_dotnet = MockSubprocessDotnetCLI.return_value
1616

17-
def test_global_tool_install(self):
17+
def tearDown(self):
1818
self.subprocess_dotnet.reset_mock()
1919

20+
def test_global_tool_install(self):
2021
action = GlobalToolInstallAction(self.subprocess_dotnet)
2122
action.execute()
2223
self.subprocess_dotnet.run.assert_called_once_with(['tool', 'install', '-g', 'Amazon.Lambda.Tools'])
2324

2425
def test_global_tool_update(self):
25-
self.subprocess_dotnet.reset_mock()
26-
2726
self.subprocess_dotnet.run.side_effect = [DotnetCLIExecutionError(message="Already Installed"), None]
2827
action = GlobalToolInstallAction(self.subprocess_dotnet)
2928
action.execute()
3029
self.subprocess_dotnet.run.assert_any_call(['tool', 'install', '-g', 'Amazon.Lambda.Tools'])
3130
self.subprocess_dotnet.run.assert_any_call(['tool', 'update', '-g', 'Amazon.Lambda.Tools'])
3231

3332
def test_global_tool_update_failed(self):
34-
self.subprocess_dotnet.reset_mock()
35-
3633
self.subprocess_dotnet.run.side_effect = [DotnetCLIExecutionError(message="Already Installed"),
3734
DotnetCLIExecutionError(message="Updated Failed")]
3835
action = GlobalToolInstallAction(self.subprocess_dotnet)
@@ -50,27 +47,28 @@ def setUp(self, MockSubprocessDotnetCLI, MockOSUtils):
5047
self.artifacts_dir = os.path.join('/artifacts_dir')
5148
self.scratch_dir = os.path.join('/scratch_dir')
5249

53-
def test_build_package(self):
50+
def tearDown(self):
5451
self.subprocess_dotnet.reset_mock()
5552

53+
def test_build_package(self):
54+
mode = "Release"
55+
5656
options = {}
57-
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, self.os_utils)
57+
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, mode,
58+
self.os_utils)
5859

5960
action.execute()
6061

61-
if platform.system().lower() == 'windows':
62-
zipFilePath = '/artifacts_dir\\source_dir.zip'
63-
else:
64-
zipFilePath = '/artifacts_dir/source_dir.zip'
62+
zipFilePath = os.path.join('/', 'artifacts_dir', 'source_dir.zip')
6563

6664
self.subprocess_dotnet.run.assert_called_once_with(['lambda', 'package', '--output-package', zipFilePath],
6765
cwd='/source_dir')
6866

6967
def test_build_package_arguments(self):
70-
self.subprocess_dotnet.reset_mock()
71-
68+
mode = "Release"
7269
options = {"--framework": "netcoreapp2.1"}
73-
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, self.os_utils)
70+
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, mode,
71+
self.os_utils)
7472

7573
action.execute()
7674

@@ -84,10 +82,25 @@ def test_build_package_arguments(self):
8482
cwd='/source_dir')
8583

8684
def test_build_error(self):
87-
self.subprocess_dotnet.reset_mock()
85+
mode = "Release"
8886

8987
self.subprocess_dotnet.run.side_effect = DotnetCLIExecutionError(message="Failed Package")
9088
options = {}
91-
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, self.os_utils)
89+
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, mode,
90+
self.os_utils)
9291

9392
self.assertRaises(ActionFailedError, action.execute)
93+
94+
def test_debug_configuration_set(self):
95+
mode = "Debug"
96+
options = None
97+
action = RunPackageAction(self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, mode,
98+
self.os_utils)
99+
100+
zipFilePath = os.path.join('/', 'artifacts_dir', 'source_dir.zip')
101+
102+
action.execute()
103+
104+
self.subprocess_dotnet.run.assert_called_once_with(
105+
['lambda', 'package', '--output-package', zipFilePath, '--configuration', 'Debug'],
106+
cwd='/source_dir')

0 commit comments

Comments
 (0)