in samcli/commands/build/build_context.py [0:0]
def run(self):
"""Runs the building process by creating an ApplicationBuilder."""
template_dict = get_template_data(self._template_file)
template_transform = template_dict.get("Transform", "")
is_sam_template = isinstance(template_transform, str) and template_transform.startswith("AWS::Serverless")
if is_sam_template:
SamApiProvider.check_implicit_api_resource_ids(self.stacks)
try:
builder = ApplicationBuilder(
self.get_resources_to_build(),
self.build_dir,
self.base_dir,
self.cache_dir,
self.cached,
self.is_building_specific_resource,
manifest_path_override=self.manifest_path_override,
container_manager=self.container_manager,
mode=self.mode,
parallel=self._parallel,
container_env_var=self._container_env_var,
container_env_var_file=self._container_env_var_file,
build_images=self._build_images,
combine_dependencies=not self._create_auto_dependency_layer,
)
except FunctionNotFound as ex:
raise UserException(str(ex), wrapped_from=ex.__class__.__name__) from ex
try:
build_result = builder.build()
artifacts = build_result.artifacts
stack_output_template_path_by_stack_path = {
stack.stack_path: stack.get_output_template_path(self.build_dir) for stack in self.stacks
}
for stack in self.stacks:
modified_template = builder.update_template(
stack,
artifacts,
stack_output_template_path_by_stack_path,
)
output_template_path = stack.get_output_template_path(self.build_dir)
if self._create_auto_dependency_layer:
LOG.debug("Auto creating dependency layer for each function resource into a nested stack")
nested_stack_manager = NestedStackManager(
self._stack_name, self.build_dir, stack.location, modified_template, build_result
)
modified_template = nested_stack_manager.generate_auto_dependency_layer_stack()
move_template(stack.location, output_template_path, modified_template)
click.secho("\nBuild Succeeded", fg="green")
# try to use relpath so the command is easier to understand, however,
# under Windows, when SAM and (build_dir or output_template_path) are
# on different drive, relpath() fails.
root_stack = SamLocalStackProvider.find_root_stack(self.stacks)
out_template_path = root_stack.get_output_template_path(self.build_dir)
try:
build_dir_in_success_message = os.path.relpath(self.build_dir)
output_template_path_in_success_message = os.path.relpath(out_template_path)
except ValueError:
LOG.debug("Failed to retrieve relpath - using the specified path as-is instead")
build_dir_in_success_message = self.build_dir
output_template_path_in_success_message = out_template_path
msg = self.gen_success_msg(
build_dir_in_success_message,
output_template_path_in_success_message,
os.path.abspath(self.build_dir) == os.path.abspath(DEFAULT_BUILD_DIR),
)
click.secho(msg, fg="yellow")
except (
UnsupportedRuntimeException,
BuildError,
BuildInsideContainerError,
UnsupportedBuilderLibraryVersionError,
ContainerBuildNotSupported,
InvalidBuildGraphException,
) as ex:
click.secho("\nBuild Failed", fg="red")
# Some Exceptions have a deeper wrapped exception that needs to be surfaced
# from deeper than just one level down.
deep_wrap = getattr(ex, "wrapped_from", None)
wrapped_from = deep_wrap if deep_wrap else ex.__class__.__name__
raise UserException(str(ex), wrapped_from=wrapped_from) from ex