6
6
import logging
7
7
8
8
from collections import namedtuple
9
+ from enum import Enum
9
10
10
11
from aws_lambda_builders .binary_path import BinaryPath
11
12
from aws_lambda_builders .path_resolver import PathResolver
@@ -37,6 +38,21 @@ class BuildMode(object):
37
38
RELEASE = "release"
38
39
39
40
41
+ class BuildInSourceSupport (Enum ):
42
+ """
43
+ Enum to define a workflow's support for building in source.
44
+ """
45
+
46
+ # can't build in source directory (e.g. only able to build in temporary or artifacts directories)
47
+ NOT_SUPPORTED = [False ]
48
+
49
+ # can build in source directory but not required to
50
+ OPTIONALLY_SUPPORTED = [False , True ]
51
+
52
+ # only able to build in source directory and not somewhere else
53
+ EXCLUSIVELY_SUPPORTED = [True ]
54
+
55
+
40
56
# TODO: Move sanitize out to its own class.
41
57
def sanitize (func ): # pylint: disable=too-many-statements
42
58
"""
@@ -124,6 +140,15 @@ def __new__(mcs, name, bases, class_dict):
124
140
if not isinstance (cls .CAPABILITY , Capability ):
125
141
raise ValueError ("Workflow '{}' must register valid capabilities" .format (cls .NAME ))
126
142
143
+ # All workflows must define valid default and supported values for build in source
144
+ if (
145
+ not isinstance (cls .BUILD_IN_SOURCE_SUPPORT , BuildInSourceSupport )
146
+ or cls .BUILD_IN_SOURCE_BY_DEFAULT not in cls .BUILD_IN_SOURCE_SUPPORT .value
147
+ ):
148
+ raise ValueError (
149
+ "Workflow '{}' must define valid default and supported values for build in source" .format (cls .NAME )
150
+ )
151
+
127
152
LOG .debug ("Registering workflow '%s' with capability '%s'" , cls .NAME , cls .CAPABILITY )
128
153
DEFAULT_REGISTRY [cls .CAPABILITY ] = cls
129
154
@@ -148,6 +173,12 @@ class BaseWorkflow(object, metaclass=_WorkflowMetaClass):
148
173
# Optional list of manifests file/folder names supported by this workflow.
149
174
SUPPORTED_MANIFESTS = []
150
175
176
+ # Whether the workflow builds in source by default, each workflow should define this.
177
+ # (some workflows build in temporary or artifact directories by default)
178
+ BUILD_IN_SOURCE_BY_DEFAULT = None
179
+ # Support for building in source, each workflow should define this.
180
+ BUILD_IN_SOURCE_SUPPORT = None
181
+
151
182
def __init__ (
152
183
self ,
153
184
source_dir ,
@@ -229,7 +260,18 @@ def __init__(
229
260
self .architecture = architecture
230
261
self .is_building_layer = is_building_layer
231
262
self .experimental_flags = experimental_flags if experimental_flags else []
263
+
232
264
self .build_in_source = build_in_source
265
+ if build_in_source not in self .BUILD_IN_SOURCE_SUPPORT .value :
266
+ # only show warning if an unsupported value was explicitly passed in
267
+ if build_in_source is not None :
268
+ LOG .warning (
269
+ 'Workflow %s does not support value "%s" for building in source. Using default value "%s".' ,
270
+ self .NAME ,
271
+ build_in_source ,
272
+ self .BUILD_IN_SOURCE_BY_DEFAULT ,
273
+ )
274
+ self .build_in_source = self .BUILD_IN_SOURCE_BY_DEFAULT
233
275
234
276
# Actions are registered by the subclasses as they seem fit
235
277
self .actions = []
0 commit comments