【问题标题】:How to show message before and after building targets in SCons如何在 SCons 中构建目标之前和之后显示消息
【发布时间】:2015-02-19 09:42:32
【问题描述】:

我必须将 Makefile 项目转换为 SCons,但我遇到了一些问题。让我们假设一个 make 文件如下:

.PHONY : clean all
all : test_1 test_2

clean :
      rm -rf *.o
test_1 : 
      @echo "---------------Test_1 Build Started-------------------"
      g++ -std=gnu++11 test_1.cpp -o target_1
      @echo "---------------Test_1 Build Finished-------------------"
test_2 :
      @echo "---------------Test_2 Build Started-------------------"
      g++ -std=gnu++11 test_2.cpp -o target_2
      @echo "---------------Test_2 Build Finished-------------------"

在这里,如果我运行 Makefile,它将首先运行 test_1,然后运行 ​​test_2。通过@echo,我们可以打印构建所在的每个步骤。 Scons 的问题是,Scons 首先读取所有脚本并打印消息(如果有)。然后它开始构建目标。这意味着

print "---------------Test_1 Build Started-------------------"
test_1 = env.Program(source = 'test_1.cpp', target = 'target_1')
print "---------------Test_1 Build Finished-------------------"

print "---------------Test_2 Build Started-------------------"
test_2 = env.Program(source = 'test_2.cpp', target = 'target_2')
print "---------------Test_2 Build Finished-------------------"

不会按预期工作。首先它将打印所有消息,然后开始构建。如何创建我在 Makefile 中所做的确切场景?

此外,使用 Makefile 我只能通过运行“make test_1”或“make test_2”来运行一个块。我怎样才能在 Scons 中做到这一点?提前致谢:)

注意:使用别名可以在 Scons 中完成,但如果我使用别名,例如

env.Alias('test_1', test_1)

并运行“scons test_1”,它可以构建目标,但“scons -c”不会删除目标。有没有更好的方法来做到这一点?

【问题讨论】:

  • 在这种情况下,您希望回答上述三个问题中的哪一个?如果您能向我们展示您当前状态的 SConstruct,将会有所帮助。
  • 基本上我这里有两个问题。如何在构建之前和之后显示消息以及如何从命令行构建特定节点。

标签: build makefile scons


【解决方案1】:

您可以像这样使用AddPostActionAddPreAction

def pre_action(target, source, env):
    print("$TARGET build started")

AddPreAction(test_1, pre_action)

【讨论】:

    【解决方案2】:

    要回答有关从命令行构建特定目标的问题,只需在命令行中指定它:

    scons test_1.o -> builds test_1.o and anything it depends on
    scons target_1 -> builds target_1 and anything it depends on
    

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 1970-01-01
      • 2015-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      相关资源
      最近更新 更多