在makefile中未设置环境变量
我想在Makefile中触发单元测试和集成测试,我当前的实现是这样的:
I want to trigger unit test and integration test in a Makefile, my current implementation is like this:
all: unittest integration
unittest:
$(ECHO) @echo 'Running unittest'
@unset TYPE
@nosetests
integration:
$(ECHO) @echo 'Running integration test'
@export TYPE=integration
@nosetests
我在设置环境变量时遇到问题,当我运行 make Integration
时,不会设置 TYPE
环境变量,如果我使用 export TYPE = integration
手动设置环境变量,那么我运行 make unittest
时,环境变量将不被设置。
but I'm having problems with setting environment variables, when I run make integration
, the TYPE
environment variable would not be set, if I set the environment variable manually with export TYPE=integration
, then I run make unittest
, the environment variable would not be unset. How to solve this?
配方中的每个命令都在单独的shell中运行。运行导出类型
的外壳程序立即退出;然后在新的实例中运行下一个命令,该实例当然没有此设置。
Each command in a recipe is run in a separate shell. The shell which runs export TYPE
immediately exits; then the next command is run in a new, fresh instance, which of course does not have this setting.
shell具有在以下时间段内设置变量的特定语法:一个命令;
The shell has specific syntax for setting a variable for the duration of one command; use that.
all: unittest integration
unittest:
echo 'Running unittest'
TYPE= nosetests
integration:
echo 'Running integration test'
TYPE=integration nosetests
顺便说一句,您不应该对自己的变量使用大写;这些名称保留供系统使用。
Incidentally, you should not use upper case for your own variables; these names are reserved for system use.