Skip to content

Commit

Permalink
Tune Makefile, allow running targets in parallel across modules (open…
Browse files Browse the repository at this point in the history
…-telemetry#4908)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Feb 23, 2022
1 parent c9c2531 commit 89016d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
48 changes: 22 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,44 @@ all-modules:

.PHONY: gomoddownload
gomoddownload:
@$(MAKE) for-all CMD="$(GOCMD) mod download"
@$(MAKE) for-all-target TARGET="moddownload"

.PHONY: gotest
gotest:
@$(MAKE) for-all CMD="make test test-unstable"
@$(MAKE) for-all-target TARGET="test test-unstable"

.PHONY: gobenchmark
gobenchmark:
@$(MAKE) for-all CMD="make benchmark"
@$(MAKE) for-all-target TARGET="benchmark"

.PHONY: gotest-with-cover
gotest-with-cover:
@$(MAKE) for-all CMD="make test-with-cover"
@$(MAKE) for-all-target TARGET="test-with-cover"
$(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt

.PHONY: goporto
goporto:
@$(MAKE) for-all CMD="make porto"
porto -w --include-internal ./

.PHONY: golint
golint:
@$(MAKE) for-all CMD="make lint lint-unstable"
@$(MAKE) for-all-target TARGET="lint lint-unstable"

.PHONY: goimpi
goimpi:
@$(MAKE) for-all CMD="make impi"
@$(MAKE) for-all-target TARGET="impi"

.PHONY: gofmt
gofmt:
@$(MAKE) for-all CMD="make fmt"
@$(MAKE) for-all-target TARGET="fmt"

.PHONY: gotidy
gotidy:
$(MAKE) for-all CMD="rm -fr go.sum"
$(MAKE) for-all CMD="$(GOCMD) mod tidy -compat=1.17"
@$(MAKE) for-all-target TARGET="tidy"

.PHONY: gogenerate
gogenerate:
$(MAKE) for-all CMD="$(GOCMD) generate ./..."
@$(MAKE) for-all-target TARGET="generate"

.PHONY: addlicense
addlicense:
Expand Down Expand Up @@ -147,15 +146,13 @@ install-tools:
run: otelcorecol
./bin/otelcorecol_$(GOOS)_$(GOARCH) --config ${RUN_CONFIG} ${RUN_ARGS}

.PHONY: for-all
for-all:
@echo "running $${CMD} in root"
@$${CMD}
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
done
GOMODULES = $(ALL_MODULES) $(PWD)
.PHONY: $(GOMODULES)
MODULEDIRS = $(GOMODULES:%=for-all-target-%)
.PHONY: for-all-target
for-all-target: $(MODULEDIRS)
$(MODULEDIRS):
$(MAKE) -C $(@:for-all-target-%=%) $(TARGET)

.PHONY: check-component
check-component:
Expand Down Expand Up @@ -309,13 +306,12 @@ gensemconv:
.PHONY: check-contrib
check-contrib:
@echo Setting contrib at $(CONTRIB_PATH) to use this core checkout
make -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit -replace go.opentelemetry.io/collector=$(CURDIR)"
make -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit -replace go.opentelemetry.io/collector/model=$(CURDIR)/model"
make -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod tidy -go=1.16"
make -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod tidy -go=1.17"
make -C $(CONTRIB_PATH) test
@$(MAKE) -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit -replace go.opentelemetry.io/collector=$(CURDIR)"
@$(MAKE) -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit -replace go.opentelemetry.io/collector/model=$(CURDIR)/model"
@$(MAKE) -C $(CONTRIB_PATH) -j2 gotidy
@$(MAKE) -C $(CONTRIB_PATH) test
@echo Restoring contrib to no longer use this core checkout
make -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit -dropreplace go.opentelemetry.io/collector"
@$(MAKE) -C $(CONTRIB_PATH) for-all CMD="$(GOCMD) mod edit -dropreplace go.opentelemetry.io/collector"

# List of directories where certificates are stored for unit tests.
CERT_DIRS := localhost|""|config/configgrpc/testdata \
Expand Down
15 changes: 12 additions & 3 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ fmt:
gofmt -w -s ./
goimports -w -local go.opentelemetry.io/collector ./

.PHONY: tidy
tidy:
rm -fr go.sum
$(GOCMD) mod tidy -compat=1.17

.PHONY: lint
lint:
$(LINT) run --allow-parallel-runners
Expand All @@ -39,10 +44,14 @@ lint:
lint-unstable:
$(LINT) run --allow-parallel-runners --build-tags enable_unstable

.PHONY: porto
porto:
porto -w --include-internal ./
.PHONY: generate
generate:
$(GOCMD) generate ./...

.PHONY: impi
impi:
@$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal ./...

.PHONY: moddownload
moddownload:
$(GOCMD) mod download

0 comments on commit 89016d2

Please sign in to comment.