如果找到某个文件,如何产生构建错误
如果在当前目录中找到一个或多个与特定模式匹配的文件,我想生成构建错误。
为了说明这一点,我的 make 文件目标当前如下所示:
generate-java:
swig -c++ -java interface.i
swig
实用程序为它在 C++ 源代码中遇到的每个 C++ 类生成 Java 类。但是,如果它遇到未找到定义的 C++ 类的使用,它将生成一个虚拟类。虚拟类的名称通常类似于 SWIGTYPE_p_MyClass
。
如果发生这种情况,那么我想将其视为错误。因此,如果找到名为 SWIGTYPE_p*.java
或包含字符串 SWIGTYPE_p
的文件,那么我希望构建失败。
我想我需要将构建目标更改为这样的:
generate-java:
swig -c++ -java interface.i
find . -name "SWIGTYPE_p.*\.java" --> generate build error if found
find . -name "*\.java" | xargs grep SWIGTYPE_p --> generate build error if found
我想我需要编写一个命令,在找到字符串的情况下返回不同于零的退出状态。但是,我不知道该怎么做。有人可以帮忙吗?
I want to generate a build error if one or more files matching a certain pattern are found in the current directory.
To illustrate, my make file target currently looks like this:
generate-java:
swig -c++ -java interface.i
The swig
utility generates Java classes for each C++ class it encounters in the C++ source code. However, if it encounters usage of a C++ class that for which no definition has been found it will generate a dummy class. The dummy class typically is named something like SWIGTYPE_p_MyClass
.
If this situation occurs then I want to treat it as an error. So if a file is found that is named SWIGTYPE_p*.java
or contains the string SWIGTYPE_p
then I want the build to fail.
I think I need to change the build target to someting like this:
generate-java:
swig -c++ -java interface.i
find . -name "SWIGTYPE_p.*\.java" --> generate build error if found
find . -name "*\.java" | xargs grep SWIGTYPE_p --> generate build error if found
I think I need to compose a command that returns an exit status different from zero in case the string is found. However, I don't know how to do this. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 shell 的
test
命令来测试find
命令的输出是否为空。如果 find 返回某些内容,这将发出失败状态 (!=0)。You can use the
test
command of the shell to test whether the output of yourfind
command is empty. This will emit a fail status (!=0) if find returns something.一种可能的方法是使用
wc
对从find
返回的文件进行计数,如果计数大于零,则使用您选择的错误号调用 exit。< br>例如,您的规则可以是:
如果找到任何文件,make 将退出错误
make: *** [generate-java] Error 3
您可以选择退出错误代码,因为您选择的数量和 echo 语句也取决于您的选择。
One of the possible ways could be to just count the files returned from
find
usingwc
and if the count is greater than zero call exit with the error number of your choice.For instance your rule could be:
If there are any file found make will exit the error as
make: *** [generate-java] Error 3
You can have the exit error code as the number of your choice and echo statement is again a matter of your choice.