in samcli/lib/build/build_strategy.py [0:0]
def build_single_function_definition(self, build_definition: FunctionBuildDefinition) -> Dict[str, str]:
"""
Build the unique definition and then copy the artifact to the corresponding function folder
"""
function_build_results = {}
LOG.info(
"Building codeuri: %s runtime: %s architecture: %s functions: %s",
build_definition.codeuri,
build_definition.runtime,
build_definition.architecture,
build_definition.get_resource_full_paths(),
)
# build into one of the functions from this build definition
single_full_path = build_definition.get_full_path()
single_build_dir = build_definition.get_build_dir(self._build_dir)
LOG.debug("Building to following folder %s", single_build_dir)
# we should create a copy and pass it down, otherwise additional env vars like LAMBDA_BUILDERS_LOG_LEVEL
# will make cache invalid all the time
container_env_vars = deepcopy(build_definition.env_vars)
# when a function is passed here, it is ZIP function, codeuri and runtime are not None
result = self._build_function(
build_definition.get_function_name(),
build_definition.codeuri, # type: ignore
build_definition.imageuri,
build_definition.packagetype,
build_definition.runtime, # type: ignore
build_definition.architecture,
build_definition.get_handler_name(),
single_build_dir,
build_definition.metadata,
container_env_vars,
build_definition.dependencies_dir if self._cached else None,
build_definition.download_dependencies,
)
function_build_results[single_full_path] = result
# copy results to other functions
if build_definition.packagetype == ZIP:
for function in build_definition.functions:
if function.full_path != single_full_path:
# for zip function we need to refer over the result
# artifacts directory which have built as the action above
if is_experimental_enabled(ExperimentalFlag.BuildPerformance):
LOG.debug(
"Using previously build shared location %s for function %s", result, function.full_path
)
function_build_results[function.full_path] = result
else:
# for zip function we need to copy over the artifacts
# artifacts directory will be created by the builder
artifacts_dir = function.get_build_dir(self._build_dir)
LOG.debug("Copying artifacts from %s to %s", single_build_dir, artifacts_dir)
osutils.copytree(single_build_dir, artifacts_dir)
function_build_results[function.full_path] = artifacts_dir
elif build_definition.packagetype == IMAGE:
for function in build_definition.functions:
if function.full_path != single_full_path:
# for image function, we just need to copy the image tag
function_build_results[function.full_path] = result
return function_build_results