【发布时间】:2021-02-18 00:03:58
【问题描述】:
我正在尝试构建一个多层 Python SAM(AWS 无服务器应用程序模型)应用程序。
没什么花哨的,但它有一些依赖项,使用pipenv 管理。
SAM 有一个sam build 命令,它在幕后使用make。
我有一个看起来像这样的Makefile:
# Empty build target for "sam build". Why?
# 1. "sam build Layers" works
# 2. "sam build" for the main function doesn't (it tries to use pip and crashes)
# With this empty target the main build is skipped and only the layers are built, which is enough.
build-Function: ;
build-Layers:
bash pip-install.sh "$(ARTIFACTS_DIR)"
pip-install.sh 看起来像这样:
#!/bin/bash
ARTIFACTS_DIR="${1}"
set -eu
# Detect Cygwin: https://stackoverflow.com/a/20691293/1320143
uname="$(uname -s)"
if [[ "${uname}" =~ "Cygwin" ]]
then
# AWS SAM for Windows passes a Windows path Cygwin tools (make, etc.) don't understand.
ARTIFACTS_DIR="$(cygpath -u "${ARTIFACTS_DIR}")"
fi
PROJECT_PATH="$(echo "${ARTIFACTS_DIR}" | sed 's@/.aws-sam.*@@')"
PIPFILE_PATH="$(echo "${ARTIFACTS_DIR}" | sed 's@/.aws-sam.*@/../Pipfile.lock@' | xargs readlink -f)"
mkdir -p "${ARTIFACTS_DIR}/python"
# We're using pipenv, which does not use requirements.txt.
# requirements.txt is used by SAM to automatically package and deploy layers (dependencies).
# To avoid dependency/version duplication, we extract the info from the pipenv info.
jq -r '.default | to_entries[] | .key + .value.version' "${PIPFILE_PATH}" > requirements.txt
# For debugging purposes.
ls -lha
python -m pip install -r "${PROJECT_PATH}/requirements.txt" -t "${ARTIFACTS_DIR}/python"
重要的是这个项目使用pipenv来管理依赖,而不是pip,SAM使用make作为构建工具,但是之后它只有pip扩展。这个脚本基本上创建了一个pip理解的依赖列表,然后pip将所有依赖下载到一个文件夹中,然后打包成一个大层。
主要问题是调试。
我已经看到由于某些(恕我直言)原因make 隐藏了它启动的 shell 脚本的输出。据说make可以被骗显示出来,用这个:See output of shell script in Makefile
我已经尝试过了,但它不起作用。我运行sam build Layers,我只看到sam 输出。我试过--debug,同样的事情。
有没有办法显示该输出?我希望能够在make/sam build 上下文中调试脚本,因为我不明白我遇到的一些错误????
【问题讨论】:
-
"make" 不会隐藏它启动的 shell 脚本的输出。如果输出没有显示,它已被重定向到别处。
-
... 这将是正在使用的 makefile 或运行
make的程序的函数。 -
嗯,这就是我在这里的原因,这不是严格意义上的
make问题,它也是sam build问题。 makefile 不会重定向任何内容,它启动的脚本也不会重定向。所以在我看来一定是sam build,我只是想看看有没有办法避免这种情况。 -
@Jens 那么你如何解释这个答案呢?查看投票最多的答案:stackoverflow.com/a/11021891/1320143 根据测试,make 绝对不会显示脚本的命令输出,也不会发生任何重定向。你必须不遗余力地改变它,并将输出 redirect 到 stderr 才能真正看到它。
-
@oblio 解释是
$(shell xxx)不是制造的东西。这是一个 GNU 制造的东西,专门设计用于扩展为命令的输出。根据定义,这不能去终端。
标签: python makefile aws-lambda aws-serverless aws-lambda-layers