问题描述
我想创建一个 bazel gen-rule 来创建一个包含当前 git commit hash 的头文件:
#include <stdio.h>
int main()
{
int amount,n100,n50,n20,n10,n5,n2,n1;
printf("Input the amount: \n");
scanf("%i",&amount);
n100 = amount / 100;
n50 = (amount % 100) / 50;
n20 = (int)(n50 % (amount % 100)) / 20;
n10 = (int)(n20 % (n50 % (amount % 100))) / 10;
n5 = (int)(n10 % (n20 % (n50 % (amount % 100)))) / 5;
n2 = (int)(n5 % (n10 % (n20 % (n50 % (amount % 100))))) / 2;
n1 = (int)(n2 % (n5 % (n10 % (n20 % (n50 % (amount % 100)))))) / 1;
printf("%i Note(s) of 100.00\n",n100);
printf("%i Note(s) of 50.00\n",n50);
printf("%i Note(s) of 20.00\n",n20);
printf("%i Note(s) of 10.00\n",n10);
printf("%i Note(s) of 5.00\n",n5);
printf("%i Note(s) of 2.00\n",n2);
printf("%i Note(s) of 1.00\n",n1);
return 0;
}
到目前为止,我还没有测试过 linux 版本 (cmd),但只在 windows (cmd_ps) 上测试过并且它可以工作,但问题是当 powershell 执行时,它不在工作区目录中(这是我的 git 根目录)。我需要将 # Generate "version_info.h"
cc_library(
name = "version_info",srcs = [],hdrs = ["version_info.h"],visibility = ["//visibility:private"],)
VERSION_INFO_H_BASH = """
#ifndef VERSION_INFO_H_
#define VERSION_INFO_H_
#define COMMIT_HASH "%s"
#endif // VERSION_INFO_H_
"""
VERSION_INFO_H_PS = """
#ifndef VERSION_INFO_H_
#define VERSION_INFO_H_
#define COMMIT_HASH "{0}"
#endif // VERSION_INFO_H_
"""
genrule(
name = "generate_version_info",outs = ["version_info.h"],cmd_ps = ("cd what_comes_here; @'%s'@ -f \"$$(git.exe rev-parse HEAD)\" | Out-File $(OUTS)" % VERSION_INFO_H_PS),cmd = ("cd what_comes_here"; printf '%s' \"$$(git rev-parse HEAD)\ > $(OUTS)" % VERSION_INFO_H_BASH),)
替换为第一个 cd 到我工作区的根目录吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)