Skip to content

Commit 9caec42

Browse files
Merge branch 'develop'
2 parents 826e4ef + 09115ee commit 9caec42

File tree

11 files changed

+126
-8
lines changed

11 files changed

+126
-8
lines changed

.github/workflows/pr-labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
github-token: ${{secrets.GITHUB_TOKEN}}
2323
script: |
24-
const maintainers = ['jfuss', 'c2tarun', 'hoffa', 'awood45', 'CoshUS', 'aahung', 'hawflau', 'mndeveci', 'ssenchenko', 'wchengru', 'mingkun2020', 'qingchm', 'moelasmar', 'xazhao', 'mildaniel', 'marekaiv', 'torresxb1']
24+
const maintainers = ['jfuss', 'hoffa', 'awood45', 'aahung', 'hawflau', 'mndeveci', 'ssenchenko', 'qingchm', 'moelasmar', 'xazhao', 'mildaniel', 'marekaiv', 'torresxb1', 'lucashuy', 'hnnasit', 'sriram-mv']
2525
if (maintainers.includes(context.payload.sender.login)) {
2626
github.rest.issues.addLabels({
2727
issue_number: context.issue.number,

aws_lambda_builders/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""
22
AWS Lambda Builder Library
33
"""
4-
__version__ = "1.19.0"
4+
5+
# Changing version will trigger a new release!
6+
# Please make the version change as the last step of your development.
7+
__version__ = "1.20.0"
58
RPC_PROTOCOL_VERSION = "0.3"

aws_lambda_builders/workflows/go_modules/builder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GoModulesBuilder(object):
2121

2222
LANGUAGE = "go"
2323

24-
def __init__(self, osutils, binaries, mode=BuildMode.RELEASE, architecture=X86_64):
24+
def __init__(self, osutils, binaries, mode=BuildMode.RELEASE, architecture=X86_64, trim_go_path=False):
2525
"""Initialize a GoModulesBuilder.
2626
2727
:type osutils: :class:`lambda_builders.utils.OSUtils`
@@ -33,11 +33,15 @@ def __init__(self, osutils, binaries, mode=BuildMode.RELEASE, architecture=X86_6
3333
3434
:type architecture: str
3535
:param architecture: name of the type of architecture
36+
37+
:type trim_go_path: bool
38+
:param trim_go_path: should go build use -trimpath flag
3639
"""
3740
self.osutils = osutils
3841
self.binaries = binaries
3942
self.mode = mode
4043
self.goarch = get_goarch(architecture)
44+
self.trim_go_path = trim_go_path
4145

4246
def build(self, source_dir_path, output_path):
4347
"""Builds a go project onto an output path.
@@ -53,6 +57,9 @@ def build(self, source_dir_path, output_path):
5357
env.update({"GOOS": "linux", "GOARCH": self.goarch})
5458
runtime_path = self.binaries[self.LANGUAGE].binary_path
5559
cmd = [runtime_path, "build"]
60+
if self.trim_go_path:
61+
LOG.debug("Trimpath requested: Setting go build configuration to -trimpath")
62+
cmd += ["-trimpath"]
5663
if self.mode and self.mode.lower() == BuildMode.DEBUG:
5764
LOG.debug("Debug build requested: Setting configuration to Debug")
5865
cmd += ["-gcflags", "all=-N -l"]

aws_lambda_builders/workflows/go_modules/workflow.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ def __init__(
2828

2929
options = kwargs.get("options") or {}
3030
handler = options.get("artifact_executable_name", None)
31+
trim_go_path = options.get("trim_go_path", False)
3132

3233
output_path = osutils.joinpath(artifacts_dir, handler)
3334

34-
builder = GoModulesBuilder(osutils, binaries=self.binaries, mode=mode, architecture=self.architecture)
35+
builder = GoModulesBuilder(
36+
osutils, binaries=self.binaries, mode=mode, architecture=self.architecture, trim_go_path=trim_go_path
37+
)
3538
self.actions = [GoModulesBuildAction(source_dir, output_path, builder)]
3639

3740
def get_validators(self):

aws_lambda_builders/workflows/python_pip/workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtim
109109
# folder
110110
if self.dependencies_dir and self.combine_dependencies:
111111
# when copying downloaded dependencies back to artifacts folder, don't exclude anything
112-
if is_experimental_build_improvements_enabled(self.experimental_flags):
112+
# symlinking python dependencies is disabled for now since it is breaking sam local commands
113+
if False and is_experimental_build_improvements_enabled(self.experimental_flags):
113114
self.actions.append(LinkSourceAction(self.dependencies_dir, artifacts_dir))
114115
else:
115116
self.actions.append(CopySourceAction(self.dependencies_dir, artifacts_dir))

tests/integration/workflows/go_modules/test_go.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from aws_lambda_builders.exceptions import WorkflowFailedError
1414

1515
from tests.integration.workflows.go_modules.utils import get_executable_arch
16+
from tests.integration.workflows.go_modules.utils import get_md5_hexdigest
1617

1718

1819
class TestGoWorkflow(TestCase):
@@ -112,6 +113,71 @@ def test_builds_arm64_architecture(self):
112113
options={"artifact_executable_name": "no-deps-main-arm64"},
113114
architecture="arm64",
114115
)
115-
116116
pathname = Path(self.artifacts_dir, "no-deps-main-arm64")
117117
self.assertEqual(get_executable_arch(pathname), "AArch64")
118+
119+
def test_builds_with_trimpath(self):
120+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps")
121+
built_trimpath = self.builder.build(
122+
source_dir,
123+
self.artifacts_dir,
124+
self.scratch_dir,
125+
os.path.join(source_dir, "go.mod"),
126+
runtime=self.runtime,
127+
options={"artifact_executable_name": "no-deps-main-trimpath", "trim_go_path": True},
128+
architecture="x86_64",
129+
)
130+
pathname = Path(self.artifacts_dir, "no-deps-main-trimpath")
131+
self.assertEqual(get_executable_arch(pathname), "x64")
132+
133+
def test_builds_without_trimpath_are_not_equal(self):
134+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps")
135+
built_no_trimpath = self.builder.build(
136+
source_dir,
137+
self.artifacts_dir,
138+
self.scratch_dir,
139+
os.path.join(source_dir, "go.mod"),
140+
runtime=self.runtime,
141+
options={"artifact_executable_name": "no-deps-main", "trim_go_path": False},
142+
architecture="x86_64",
143+
)
144+
145+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps-copy")
146+
built_no_trimpath_copy = self.builder.build(
147+
source_dir,
148+
self.artifacts_dir,
149+
self.scratch_dir,
150+
os.path.join(source_dir, "go.mod"),
151+
runtime=self.runtime,
152+
options={"artifact_executable_name": "no-deps-main-copy", "trim_go_path": False},
153+
architecture="x86_64",
154+
)
155+
pathname = Path(self.artifacts_dir, "no-deps-main")
156+
pathnameOfCopy = Path(self.artifacts_dir, "no-deps-main-copy")
157+
self.assertNotEqual(get_md5_hexdigest(pathname), get_md5_hexdigest(pathnameOfCopy))
158+
159+
def test_builds_with_trimpath_are_equal(self):
160+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps")
161+
built_with_trimpath = self.builder.build(
162+
source_dir,
163+
self.artifacts_dir,
164+
self.scratch_dir,
165+
os.path.join(source_dir, "go.mod"),
166+
runtime=self.runtime,
167+
options={"artifact_executable_name": "no-deps-main", "trim_go_path": True},
168+
architecture="x86_64",
169+
)
170+
171+
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps-copy")
172+
built_with_trimpath_copy = self.builder.build(
173+
source_dir,
174+
self.artifacts_dir,
175+
self.scratch_dir,
176+
os.path.join(source_dir, "go.mod"),
177+
runtime=self.runtime,
178+
options={"artifact_executable_name": "no-deps-main-copy", "trim_go_path": True},
179+
architecture="x86_64",
180+
)
181+
pathname = Path(self.artifacts_dir, "no-deps-main")
182+
pathnameOfCopy = Path(self.artifacts_dir, "no-deps-main-copy")
183+
self.assertEqual(get_md5_hexdigest(pathname), get_md5_hexdigest(pathnameOfCopy))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module github.com/awslabs/aws-lambda-builders
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package main
2+
3+
func main() {
4+
}

tests/integration/workflows/go_modules/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from elftools.elf.elffile import ELFFile
2+
import hashlib
23

34

45
def get_executable_arch(path):
@@ -18,3 +19,22 @@ def get_executable_arch(path):
1819
with open(str(path), "rb") as f:
1920
e = ELFFile(f)
2021
return e.get_machine_arch()
22+
23+
24+
def get_md5_hexdigest(path):
25+
"""
26+
Returns the hexdigest of a binary
27+
28+
Parameters
29+
----------
30+
path : str
31+
path to the Go binaries generated
32+
33+
Returns
34+
-------
35+
str
36+
Hex digest of the binaries
37+
"""
38+
with open(str(path), "rb") as f:
39+
hashed = hashlib.md5(f.read())
40+
return hashed.hexdigest()

tests/unit/workflows/go_modules/test_builder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ def test_debug_configuration_set(self):
6161
stdout="PIPE",
6262
)
6363

64+
def test_trimpath_configuration_set(self):
65+
self.under_test = GoModulesBuilder(self.osutils, self.binaries, "release", "x86_64", True)
66+
self.under_test.build("source_dir", "output_path")
67+
self.osutils.popen.assert_called_with(
68+
["/path/to/go", "build", "-trimpath", "-o", "output_path", "source_dir"],
69+
cwd="source_dir",
70+
env={"GOOS": "linux", "GOARCH": "amd64"},
71+
stderr="PIPE",
72+
stdout="PIPE",
73+
)
74+
6475
def test_debug_configuration_set_with_arm_architecture(self):
6576
self.under_test = GoModulesBuilder(self.osutils, self.binaries, "Debug", "arm64")
6677
self.under_test.build("source_dir", "output_path")

0 commit comments

Comments
 (0)