Skip to content

Commit 5634fe5

Browse files
committed
fix: set environment variables in addition to current
Why is this change necessary? * On Windows, certain env variables are required for functioning of binaries within the Makefile How does it address the issue? * pass current environmental variables along with new ones over to the subprocess runner. What side effects does this change have? * None
1 parent 37a7bd1 commit 5634fe5

File tree

13 files changed

+32
-10
lines changed

13 files changed

+32
-10
lines changed

aws_lambda_builders/workflows/provided_make/actions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Action to build a specific Makefile target
33
"""
44

5+
import os
56
import logging
67

78
from aws_lambda_builders.actions import BaseAction, Purpose, ActionFailedError
@@ -57,10 +58,10 @@ def execute(self):
5758
self.osutils.makedirs(self.artifacts_dir)
5859

5960
try:
61+
current_env = os.environ.copy()
62+
current_env.update({"ARTIFACTS_DIR": self.artifacts_dir})
6063
self.subprocess_make.run(
61-
["build-{logical_id}".format(logical_id=self.build_logical_id)],
62-
env={"ARTIFACTS_DIR": self.artifacts_dir},
63-
cwd=self.scratch_dir,
64+
["build-{logical_id}".format(logical_id=self.build_logical_id)], env=current_env, cwd=self.scratch_dir,
6465
)
6566
except MakeExecutionError as ex:
6667
raise ActionFailedError(str(ex))

aws_lambda_builders/workflows/provided_make/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, osutils, make_exe=None):
4040

4141
if make_exe is None:
4242
if osutils.is_windows():
43-
make_exe = "make.cmd"
43+
make_exe = "make.exe"
4444
else:
4545
make_exe = "make"
4646

tests/functional/workflows/provided_make/test_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ def test_popen_runs_a_process_and_returns_outcome(self):
2626
def test_popen_can_accept_cwd_and_env(self):
2727

2828
testdata_dir = os.path.join(os.path.dirname(__file__), "..", "..", "testdata")
29+
env = os.environ.copy()
30+
env.update({"SOME_ENV": "SOME_VALUE"})
2931

3032
p = self.osutils.popen(
31-
[sys.executable, "cwd.py"],
32-
stdout=self.osutils.pipe,
33-
stderr=self.osutils.pipe,
34-
env=os.environ.copy().update({"SOME_ENV": "SOME_VALUE"}),
35-
cwd=testdata_dir,
33+
[sys.executable, "cwd.py"], stdout=self.osutils.pipe, stderr=self.osutils.pipe, env=env, cwd=testdata_dir,
3634
)
3735

3836
out, err = p.communicate()

tests/integration/workflows/provided_make/test_provided_make.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
from aws_lambda_builders.builder import LambdaBuilder
88
from aws_lambda_builders.exceptions import WorkflowFailedError
9+
from aws_lambda_builders.workflows.provided_make.utils import OSUtils
910

1011

1112
class TestProvidedMakeWorkflow(TestCase):
1213
"""
1314
Verifies that `provided_make` workflow works by building a Lambda that requires Numpy
1415
"""
1516

16-
TEST_DATA_FOLDER = os.path.join(os.path.dirname(__file__), "testdata", "makefile-present")
17+
MAKEFILE_DIRECTORY = "makefile-windows" if OSUtils().is_windows() else "makefile-unix"
18+
TEST_DATA_FOLDER = os.path.join(os.path.dirname(__file__), "testdata", MAKEFILE_DIRECTORY)
1719

1820
def setUp(self):
1921
self.source_dir = self.TEST_DATA_FOLDER
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build-HelloWorldFunction:
2+
copy *.py $(ARTIFACTS_DIR)
3+
copy requirements-requests.txt $(ARTIFACTS_DIR)
4+
python -m pip install -r requirements-requests.txt -t $(ARTIFACTS_DIR)
5+
rmdir $(ARTIFACTS_DIR)\\bin /s /q

tests/integration/workflows/provided_make/testdata/makefile-windows/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import requests
2+
3+
4+
def lambda_handler(event, context):
5+
# Just return the requests version.
6+
return "{}".format(requests.__version__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.23.0

tests/unit/workflows/provided_make/test_actions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from unittest import TestCase
24
from mock import patch
35

@@ -7,6 +9,13 @@
79

810

911
class TestProvidedMakeAction(TestCase):
12+
def setUp(self):
13+
self.original_env = os.environ
14+
os.environ = {}
15+
16+
def tearDown(self):
17+
os.environ = self.original_env
18+
1019
@patch("aws_lambda_builders.workflows.provided_make.utils.OSUtils")
1120
@patch("aws_lambda_builders.workflows.provided_make.make.SubProcessMake")
1221
def test_call_makefile_target(self, OSUtilMock, SubprocessMakeMock):

0 commit comments

Comments
 (0)