我有一个带有多个git的Makefile,我需要克隆它,我使用了下面的方法
clone:
git clone https://github.company.corp/dev-wi/ws-led.git
git clone https://github.company.corp/dev-wi/tools-extension.git
git clone https://github.company.corp/dev-wi/javt-ra.git当下面的代码工作时,我想在循环中对列表中的所有repos执行类似的操作
build:
cd ws-led; \
docker build -t ws-led .
cd tools-extension; \
docker build -t tools-extension .
...对于每个回购我需要更改dir和运行码头建设,我想避免重复这样做。我知道我需要在/dev-wi/之后提取字符串,因为这是我需要运行docker的repo目录。既然我有很多回购,我怎么能轻易做到呢?
但是,我尝试使用子集,但是我也有git命令(在克隆中),所以它不工作,有什么想法吗?
我已经创建了一个新的makefile,并且只使用这段代码(和tools-extension是同一个级别的makefile中的文件夹)
repos := ws-led tools-extension
.PHONY: all
all: $(patsubst%,%/docker-build.log,$(repos))
%/docker-build.log: %/.git
cd $*; docker build -t $* . >&2 | tee docker-build.logI得到错误:
make: Nothing to be done forall‘
我在这里错过了什么?
我试着简化它,但是删除git,并且假设文件夹(repo)存在于makefile的同一级别上
更新
Im将makefile更改为根下
proj
- ws-led
— Dockerfile
-tools-ext
—Dockerfile
-Makefile我试着做以下几点
all: pre docker-build
.PHONY: pre docker-build
repos := ws-led tools-ext
pre:
$(patsubst %,%docker-build,$(repos))
docker-build:pre
cd $*; docker build -t $* . >&2 | tee docker-build当我运行时,我得到了以下错误
ws-leddocker-build ws-leddocker-build
make: ws-leddocker-build: No such file or directory有什么想法吗?
发布于 2020-02-12 12:09:17
循环通常是你想避免的事情。相反,为每个回购声明一系列目标。
repos := ws-led tools-extension javt-ra
.PHONY: all clone
all: $(patsubst %,%/.built,$(repos))
clone: $(patsubst %,%/.git,$(repos))
%/.built: %/.git
cd $*; docker build -t $* .
touch $@
%/.git:
git clone https://github.company.corp/dev-wi/$*.git.built标志文件有点麻烦,可以用更有用的东西代替,比如来自docker build的输出。
all: $(patsubst %,%/docker-build.log,$(repos))
%/docker-build.log: %/.git
cd $*; docker build -t $* . >&2 | tee docker-build.log我们通常试图避免循环的原因是允许make正确地完成其主要工作--避免在目标已经更新时重新运行命令。因此,例如,如果您只更改了ws-led,您就不想强迫其他两个也重新构建。
尽管如此,$(patsubst ...)是一个排序循环;它基本上遍历repos并在每个循环周围创建一小块文本。没有patsubst,我们可以编写
all: ws-led/.built tools-extension/.built javt-ra/.built它简单地说,为了使all,我们需要做这三个;然后
%/.built: %/.git他说,对于任何匹配模式的东西,它都依赖于后面的/.git的相同的茎。因此,在一个空目录中,make会发现
要制作to,则需要制作ws-led/.git;f 124H 125以生成ws-led/.git,我们需要to。
git克隆https://github.company.corp/dev-wi/ws-led.git
- then once this prerequisite is satisfied,光盘ws-领导;码头建设-t ws-领导。触摸ws-引导/.构建
- to make `tools-extension/.built`, we need to make `tools-extension/.git`;
- to make `tools-extension/.git`, we need togit克隆https://github.company.corp/dev-wi/tools-extension.git
..。等。
将来,当make发现ws-led比ws-led/.built新时,它将再次构建它;但如果不是,它将得出结论,不需要为其他目标做任何工作,等等。这就是我们如何避免不必要地构建东西的方法;但它显然需要Makefile适当地包含每个相关依赖项的形式化。(在这种情况下,理想情况下,您希望有一种方法来了解Git上游何时发生了变化,并且需要由本地Makefile提取一些东西;如果本地Git克隆没有收到任何更新,那么这只是将所有事情视为已完成的事情。)
https://stackoverflow.com/questions/60185422
复制相似问题