Skip to content

Commit 71f10c1

Browse files
Merge branch 'develop'
2 parents 9caec42 + e8116e8 commit 71f10c1

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ for:
9090
- sh: "nvm install ${nodejs_version}"
9191
- sh: "npm install [email protected] -g"
9292
- sh: "npm -v"
93+
- sh: "go version"
9394
- sh: "echo $PATH"
9495
- sh: "java --version"
9596

aws_lambda_builders/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
# Changing version will trigger a new release!
66
# Please make the version change as the last step of your development.
7-
__version__ = "1.20.0"
7+
__version__ = "1.21.0"
88
RPC_PROTOCOL_VERSION = "0.3"

aws_lambda_builders/workflows/custom_make/make.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""
22
Wrapper around calling make through a subprocess.
33
"""
4-
4+
import io
55
import logging
6+
import subprocess
7+
import shutil
8+
import threading
69

710
LOG = logging.getLogger(__name__)
811

@@ -82,14 +85,26 @@ def run(self, args, env=None, cwd=None):
8285

8386
p = self.osutils.popen(invoke_make, stdout=self.osutils.pipe, stderr=self.osutils.pipe, cwd=cwd, env=env)
8487

85-
out, err = p.communicate()
86-
87-
# Typically this type of information is logged to DEBUG, however, since the Make builder
88-
# can be different per customer's use case, it is helpful to always log the output so
89-
# developers can diagnose any issues.
90-
LOG.info(out.decode("utf8").strip())
91-
92-
if p.returncode != 0:
93-
raise MakeExecutionError(message=err.decode("utf8").strip())
94-
95-
return out.decode("utf8").strip()
88+
# Create a stdout variable that will contain the final stitched stdout result
89+
stdout = ""
90+
# Create a buffer and use a thread to gather the stderr stream into the buffer
91+
stderr_buf = io.BytesIO()
92+
stderr_thread = threading.Thread(target=shutil.copyfileobj, args=(p.stderr, stderr_buf), daemon=True)
93+
stderr_thread.start()
94+
95+
# Log every stdout line by iterating
96+
for line in p.stdout:
97+
decoded_line = line.decode("utf-8").strip()
98+
LOG.info(decoded_line)
99+
# Gather total stdout
100+
stdout += decoded_line
101+
102+
# Wait for the process to exit and stderr thread to end.
103+
return_code = p.wait()
104+
stderr_thread.join()
105+
106+
if return_code != 0:
107+
# Raise an Error with the appropriate value from the stderr buffer.
108+
raise MakeExecutionError(message=stderr_buf.getvalue().decode("utf8").strip())
109+
110+
return stdout

aws_lambda_builders/workflows/go_modules/validator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ def validate(self, runtime_path):
5252

5353
runtime_path = super(GoRuntimeValidator, self).validate(runtime_path)
5454

55-
expected_major_version = int(self.runtime.replace(self.LANGUAGE, "").split(".")[0])
56-
min_expected_minor_version = 11 if expected_major_version == 1 else 0
57-
5855
p = subprocess.Popen([runtime_path, "version"], cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5956
version_string, _ = p.communicate()
6057

6158
if p.returncode == 0:
6259
major_version, minor_version = GoRuntimeValidator.get_go_versions(version_string.decode())
63-
if major_version == expected_major_version and minor_version >= min_expected_minor_version:
60+
min_expected_major_version = 1
61+
min_expected_minor_version = 11 if major_version == 1 else 0
62+
if major_version >= min_expected_major_version and minor_version >= min_expected_minor_version:
6463
self._valid_runtime_path = runtime_path
6564
return self._valid_runtime_path
6665

tests/unit/workflows/custom_make/test_make.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
from unittest import TestCase
23
from mock import patch
34

@@ -8,11 +9,16 @@ class FakePopen:
89
def __init__(self, out=b"out", err=b"err", retcode=0):
910
self.out = out
1011
self.err = err
12+
self.stderr = io.BytesIO(err)
13+
self.stdout = [out]
1114
self.returncode = retcode
1215

1316
def communicate(self):
1417
return self.out, self.err
1518

19+
def wait(self):
20+
return self.returncode
21+
1622

1723
class TestSubprocessMake(TestCase):
1824
@patch("aws_lambda_builders.workflows.custom_make.utils.OSUtils")
@@ -67,15 +73,15 @@ def test_uses_env_and_cwd_if_supplied(self):
6773
)
6874

6975
def test_returns_popen_out_decoded_if_retcode_is_0(self):
70-
self.popen.out = b"some encoded text\n\n"
76+
self.popen.stdout = [b"some encoded text\n\n"]
7177

7278
result = self.under_test.run(["build_logical_id"])
7379

7480
self.assertEqual(result, "some encoded text")
7581

7682
def test_raises_MakeExecutionError_with_err_text_if_retcode_is_not_0(self):
7783
self.popen.returncode = 1
78-
self.popen.err = b"some error text\n\n"
84+
self.popen.stderr = io.BytesIO(b"some error text\n\n")
7985

8086
with self.assertRaises(MakeExecutionError) as raised:
8187
self.under_test.run(["build-logical_id"])

0 commit comments

Comments
 (0)