问题描述
我已经创建了 SConstruct 来安装 systemd 用户服务,但是当我尝试 scons uninstall
时,临时服务文件被创建,这不应该发生。
import os
PATH_WD = os.path.abspath(os.curdir)
env = Environment(
SUBSTFILESUFFIX = '.service',SUBST_DICT = { '{{PATH_ROOT}}' : os.path.dirname(PATH_WD) },ENV = {
'DBUS_SESSION_BUS_ADDRESS' : os.environ['DBUS_SESSION_BUS_ADDRESS'],'XDG_RUNTIME_DIR' : os.environ['XDG_RUNTIME_DIR']
}
)
INSTALLED = env.Install(
target = os.path.expanduser('~/.config/systemd/user/'),source = [
env.Substfile('service1'),env.Substfile('service2'),]
)
env.AddPostAction(INSTALLED,env.Action('systemctl --user daemon-reload'))
Alias('install',INSTALLED)
NoClean(INSTALLED)
Command('uninstall',INSTALLED,Delete(INSTALLED))
Default('install')
解决方法
SCons 构建器调用是节点之间关系的语句。您已通过调用 "uninstall"
构建器将目标 INSTALLED
与源 Command
相关联。所以为了“构建”这个目标,你需要源,源是通过调用 Install
构建器返回的节点列表。因此,Install
必须在 uninstall
发生之前发生。您是否有理由不希望在这里使用 SCons 的干净功能?要查看此内容,请尝试:scons --tree=all,linedraw -n uninstall
第二次尝试..
这是一个简单的例子,应该对你有用..
env=Environment()
prog=env.Program('main.c')
Default(prog)
installed_prog = env.Install('install_dir',prog)
Alias('install',installed_prog)
NoClean(installed_prog)
# You don't have to specify targets to Alias.. so it won't
# try to build those before executing the Action
Alias('uninstall',action=Delete(installed_prog))
AlwaysBuild('uninstall')