你可以这样做
envSelect = ARGUMENTS.get('env', "default")
if envSelect == "default":
env = Environment()
elif envSelect == "env2":
env = Environment(whatever you want to do here)
elif envSelect == "env3":
env = Environment(whatever you want to do here)
else:
env = Environment(whatever you want to do here)
使用 ARGUMENTS.get 您可以在运行命令时指定默认值,scons
否则您确实scons env=env2
希望这能回答您的问题
编辑:这是我正在处理的项目的一个片段,我想在 scons 运行时确定操作系统
import sys
import os
import glob
import subprocess
#Find the host Operating System
platform = sys.platform
if platform != "win32":
env = Environment()
else:
#Specify to compile in 32-bit mode for Visual Studio
#This is needed as Qt libraries on Windows for Visual
#Studio are 32-bit only
env = Environment(TARGET_ARCH = 'x86')
#Get Qt directory as scons argument or use default setting
if platform != "win32":
qtDir = ARGUMENTS.get('qt', '/usr/local/Trolltech/Qt-4.8.4/')
else:
qtDir = ARGUMENTS.get('qt', 'C:\\Qt\\4.8.4\\')