【问题标题】:Ant build target to list own build targetsAnt 构建目标以列出自己的构建目标
【发布时间】:2011-09-28 16:23:39
【问题描述】:

我是 Ant 的新手。我想要以下内容:

<target name="targets" description "Lists Targets">
  [some Ant code/tasks]
</target

当我调用 ant targets 时,我希望 Ant 搜索 Ant 正在运行的当前文件中的所有目标

<target name="all" depends="doc,sca,compile,test" description="Complete build">
</target>

然后输出

[echo] all - Complete Build - Depends on: doc, sca, compile, test
[echo] doc - Builds documentation
[echo] compile - Compiles files
[echo] sca - Performs static code analysis
[echo] test - Runs unit tests - Depends on: compile
[echo] clean - Cleans a build
[echo] install - Performs an installation
[echo] targets - Lists Targets

BashMake 中,我只需要一个grep 正则表达式。以下Make 中列出了 make 目标:

noop: ;
targets:
    @$(MAKE) --print-data-base --question noop | \
     grep -v "[A-Z]:/" | \
     awk '/^[Mm]akefile:/           { next } \
         /^targets:/            { next } \
         /^noop:/           { next } \
         /^[^.%!][-A-Za-z0-9_]*:/   { print substr($$1, 1, length($$1)-1) }' | \
     sort | \
     pr --omit-pagination --width=80 --columns=4

输出:

[matt@office burning-boots-website]$ make -C ~/workspace/packages/ targets
all         diagnose        install         vca_core
clean           doc         platforms       vca_counting_line
compile         help        utils           vca_rules

如果在我的 Ant 构建脚本中有类似的东西会很好!如果 Ant 能够像 pr 那样进行良好的对齐,甚至为输出着色,那就太好了! Ant可以跨平台终端换色吗?

【问题讨论】:

标签: ant


【解决方案1】:

您可以使用ant -p(或ant -p -v 获取更多信息)。这不会列出目标依赖项,但我不认为这是一个问题:依赖项对最终用户并不重要(他们只是告诉 目标如何工作)。重要的是 目标做了什么,这就是它的描述应该是什么。

【讨论】:

  • 完美。我认为 Ant 有一种打印目标的方法,但仍在处理文档。
猜你喜欢
  • 2014-05-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 2011-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多