Skip to content

Commit cf13a17

Browse files
sigmamslipper
andauthored
build: migrate op-node and op-proposer to just (ethereum-optimism#13042)
* build(just): factor out flags code This will enable making use of JUSTFLAGS in the main Makefile for migrated targets. * fix(just): parallel support For some unclear reason runs in CI environment are invalid (they generate some "empty" calls to the private target). Sidestep the issue for now. * build(just): add more helpers - VERSION_META variable - go_generate target * build(op-proposer): migrate build to just * build(op-node): migrate build to just * fix(build): rewire just-migrated targets --------- Co-authored-by: Matthew Slipper <[email protected]>
1 parent 2bbfd5d commit cf13a17

File tree

11 files changed

+130
-137
lines changed

11 files changed

+130
-137
lines changed

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# provide JUSTFLAGS for just-backed targets
2+
include ./just/flags.mk
3+
14
COMPOSEFLAGS=-d
25
ITESTS_L2_HOST=http://localhost:9545
36
BEDROCK_TAGS_REMOTE?=origin
@@ -94,7 +97,7 @@ submodules: ## Updates git submodules
9497

9598

9699
op-node: ## Builds op-node binary
97-
make -C ./op-node op-node
100+
just $(JUSTFLAGS) ./op-node/op-node
98101
.PHONY: op-node
99102

100103
generate-mocks-op-node: ## Generates mocks for op-node
@@ -106,11 +109,11 @@ generate-mocks-op-service: ## Generates mocks for op-service
106109
.PHONY: generate-mocks-op-service
107110

108111
op-batcher: ## Builds op-batcher binary
109-
make -C ./op-batcher op-batcher
112+
just $(JUSTFLAGS) ./op-batcher/op-batcher
110113
.PHONY: op-batcher
111114

112115
op-proposer: ## Builds op-proposer binary
113-
make -C ./op-proposer op-proposer
116+
just $(JUSTFLAGS) ./op-proposer/op-proposer
114117
.PHONY: op-proposer
115118

116119
op-challenger: ## Builds op-challenger binary

just/default.just

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set shell := ["bash", "-c"]
22

3-
PARALLEL := num_cpus()
3+
PARALLEL_JOBS := num_cpus()
44

5-
MAP_JUST := "/usr/bin/env -S parallel --shebang --jobs " + PARALLEL + " --colsep ' ' -r " + just_executable()
5+
# TODO: this fails in CI for some reason
6+
MAP_JUST := "/usr/bin/env -S parallel --shebang --jobs " + PARALLEL_JOBS + " --colsep ' ' -r " + just_executable()

just/deprecated.mk

+8-26
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
11
ifeq (, $(shell which tput))
22
# CI environment typically does not support tput.
33
banner-style = $1
4+
else ifeq (, $(TERM))
5+
# Terminal type not set, so tput would fail.
6+
banner-style = $1
47
else
58
# print in bold red to bring attention.
69
banner-style = $(shell tput bold)$(shell tput setaf 1)$1$(shell tput sgr0)
710
endif
811

9-
# Variable assignments can affect the semantic of the make targets.
10-
# Typical use-case: setting VERSION in a release build, since CI
11-
# doesn't preserve the git environment.
12-
#
13-
# We need to translate:
14-
# "make target VAR=val" to "just VAR=val target"
15-
#
16-
# MAKEFLAGS is a string of the form:
17-
# "abc --foo --bar=baz -- VAR1=val1 VAR2=val2", namely:
18-
# - abc is the concatnation of all short flags
19-
# - --foo and --bar=baz are long options,
20-
# - -- is the separator between flags and variable assignments,
21-
# - VAR1=val1 and VAR2=val2 are variable assignments
22-
#
23-
# Goal: ignore all CLI flags, keep only variable assignments.
24-
#
25-
# First remove the short flags at the beginning, or the first long-flag,
26-
# or if there is no flag at all, the -- separator (which then makes the
27-
# next step a noop). If there's no flag and no variable assignment, the
28-
# result is empty anyway, so the wordlist call is safe (everything is a noop).
29-
tmp-flags = $(wordlist 2,$(words $(MAKEFLAGS)),$(MAKEFLAGS))
30-
# Then remove all long options, including the -- separator, if needed. That
31-
# leaves only variable assignments.
32-
just-flags = $(patsubst --%,,$(tmp-flags))
12+
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
13+
include $(SELF_DIR)/flags.mk
3314

3415
define make-deprecated-target
3516
$1:
3617
@echo
37-
@printf %s\\n '$(call banner-style,"make $1 $(just-flags)" is deprecated. Please use "just $(just-flags) $1" instead.)'
18+
@printf %s\\n '$(call banner-style,Deprecated make call: make $1 $(JUSTFLAGS))'
19+
@printf %s\\n '$(call banner-style,Consider using just instead: just $(JUSTFLAGS) $1)'
3820
@echo
39-
just $(just-flags) $1
21+
just $(JUSTFLAGS) $1
4022
endef
4123

4224
$(foreach element,$(DEPRECATED_TARGETS),$(eval $(call make-deprecated-target,$(element))))

just/flags.mk

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Variable assignments can affect the semantic of the make targets.
2+
# Typical use-case: setting VERSION in a release build, since CI
3+
# doesn't preserve the git environment.
4+
#
5+
# We need to translate:
6+
# "make target VAR=val" to "just VAR=val target"
7+
#
8+
# MAKEFLAGS is a string of the form:
9+
# "abc --foo --bar=baz -- VAR1=val1 VAR2=val2", namely:
10+
# - abc is the concatnation of all short flags
11+
# - --foo and --bar=baz are long options,
12+
# - -- is the separator between flags and variable assignments,
13+
# - VAR1=val1 and VAR2=val2 are variable assignments
14+
#
15+
# Goal: ignore all CLI flags, keep only variable assignments.
16+
#
17+
# First remove the short flags at the beginning, or the first long-flag,
18+
# or if there is no flag at all, the -- separator (which then makes the
19+
# next step a noop). If there's no flag and no variable assignment, the
20+
# result is empty anyway, so the wordlist call is safe (everything is a noop).
21+
tmp-flags := $(wordlist 2,$(words $(MAKEFLAGS)),$(MAKEFLAGS))
22+
# Then remove all long options, including the -- separator, if needed. That
23+
# leaves only variable assignments.
24+
JUSTFLAGS := $(patsubst --%,,$(tmp-flags))

just/git.just

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ VERSION := shell('if [ -z "$1" ]; then
2424
else
2525
echo $1
2626
fi', _PREFERRED_TAG, _LAST_TAG)
27+
28+
VERSION_META := ""

just/go.just

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ go_test SELECTOR *FLAGS:
2525

2626
[private]
2727
go_fuzz FUZZ TIME='10s' PKG='': (go_test PKG _EXTRALDFLAGS "-fuzztime" TIME "-fuzz" FUZZ "-run" "NOTAREALTEST")
28+
29+
[private]
30+
go_generate SELECTOR *FLAGS:
31+
go generate -v {{FLAGS}} {{SELECTOR}}

op-batcher/justfile

+10-9
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ batcher_fuzz_task FUZZ TIME='10s': (go_fuzz FUZZ TIME "./batcher")
2424

2525
# Run fuzzing tests
2626
fuzz:
27-
#!{{MAP_JUST}} batcher_fuzz_task
28-
FuzzChannelConfig_CheckTimeout
29-
FuzzDurationZero
30-
FuzzDurationTimeoutMaxChannelDuration
31-
FuzzDurationTimeoutZeroMaxChannelDuration
32-
FuzzChannelCloseTimeout
33-
FuzzChannelZeroCloseTimeout
34-
FuzzSeqWindowClose
35-
FuzzSeqWindowZeroTimeoutClose
27+
printf "%s\n" \
28+
"FuzzChannelConfig_CheckTimeout" \
29+
"FuzzDurationZero" \
30+
"FuzzDurationTimeoutMaxChannelDuration" \
31+
"FuzzDurationTimeoutZeroMaxChannelDuration" \
32+
"FuzzChannelCloseTimeout" \
33+
"FuzzChannelZeroCloseTimeout" \
34+
"FuzzSeqWindowClose" \
35+
"FuzzSeqWindowZeroTimeoutClose" \
36+
| parallel -j {{PARALLEL_JOBS}} {{just_executable()}} batcher_fuzz_task {}

op-node/Makefile

+2-64
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,3 @@
1-
GITCOMMIT ?= $(shell git rev-parse HEAD)
2-
GITDATE ?= $(shell git show -s --format='%ct')
3-
# Find the github tag that points to this commit. If none are found, set the version string to "untagged"
4-
# Prioritizes release tag, if one exists, over tags suffixed with "-rc"
5-
VERSION ?= $(shell tags=$$(git tag --points-at $(GITCOMMIT) | grep '^op-node/' | sed 's/op-node\///' | sort -V); \
6-
preferred_tag=$$(echo "$$tags" | grep -v -- '-rc' | tail -n 1); \
7-
if [ -z "$$preferred_tag" ]; then \
8-
if [ -z "$$tags" ]; then \
9-
echo "untagged"; \
10-
else \
11-
echo "$$tags" | tail -n 1; \
12-
fi \
13-
else \
14-
echo $$preferred_tag; \
15-
fi)
1+
DEPRECATED_TARGETS := op-node clean test fuzz generate-mocks readme
162

17-
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
18-
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
19-
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/op-node/version.Version=$(VERSION)
20-
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/op-node/version.Meta=$(VERSION_META)
21-
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"
22-
23-
# Use the old Apple linker to workaround broken xcode - https://github.com/golang/go/issues/65169
24-
ifeq ($(shell uname),Darwin)
25-
FUZZLDFLAGS := -ldflags=-extldflags=-Wl,-ld_classic
26-
endif
27-
28-
op-node:
29-
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) CGO_ENABLED=0 go build -v $(LDFLAGS) -o ./bin/op-node ./cmd/main.go
30-
31-
clean:
32-
rm bin/op-node
33-
34-
test:
35-
go test -v ./...
36-
37-
fuzz:
38-
printf "%s\n" \
39-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzL1InfoBedrockRoundTrip ./rollup/derive" \
40-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzL1InfoEcotoneRoundTrip ./rollup/derive" \
41-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzL1InfoAgainstContract ./rollup/derive" \
42-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzUnmarshallLogEvent ./rollup/derive" \
43-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzParseFrames ./rollup/derive" \
44-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzFrameUnmarshalBinary ./rollup/derive" \
45-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzBatchRoundTrip ./rollup/derive" \
46-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzDeriveDepositsRoundTrip ./rollup/derive" \
47-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzDeriveDepositsBadVersion ./rollup/derive" \
48-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzParseL1InfoDepositTxDataValid ./rollup/derive" \
49-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzParseL1InfoDepositTxDataBadLength ./rollup/derive" \
50-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzRejectCreateBlockBadTimestamp ./rollup/driver" \
51-
"go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz FuzzDecodeDepositTxDataToL1Info ./rollup/driver" \
52-
| parallel -j 8 {}
53-
54-
generate-mocks:
55-
go generate ./...
56-
57-
readme:
58-
doctoc README.md
59-
60-
.PHONY: \
61-
op-node \
62-
clean \
63-
test \
64-
fuzz \
65-
readme
3+
include ../just/deprecated.mk

op-node/justfile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import '../just/go.just'
2+
3+
# Build ldflags string
4+
_LDFLAGSSTRING := "'" + trim(
5+
"-X main.GitCommit=" + GITCOMMIT + " " + \
6+
"-X main.GitDate=" + GITDATE + " " + \
7+
"-X github.com/ethereum-optimism/optimism/op-node/version.Version=" + VERSION + " " + \
8+
"-X github.com/ethereum-optimism/optimism/op-node/version.Meta=" + VERSION_META + " " + \
9+
"") + "'"
10+
11+
BINARY := "./bin/op-node"
12+
13+
# Build op-node binary
14+
op-node: (go_build BINARY "./cmd" "-ldflags" _LDFLAGSSTRING)
15+
16+
# Clean build artifacts
17+
clean:
18+
rm -f {{BINARY}}
19+
20+
# Run tests
21+
test: (go_test "./...")
22+
23+
# Generate mocks
24+
generate-mocks: (go_generate "./...")
25+
26+
# Update readme
27+
readme:
28+
doctoc README.md
29+
30+
[private]
31+
node_fuzz_task FUZZ TIME='10s': (go_fuzz FUZZ TIME "./rollup/derive")
32+
33+
# Run fuzz tests
34+
fuzz:
35+
printf "%s\n" \
36+
"FuzzL1InfoBedrockRoundTrip" \
37+
"FuzzL1InfoEcotoneRoundTrip" \
38+
"FuzzL1InfoAgainstContract" \
39+
"FuzzUnmarshallLogEvent" \
40+
"FuzzParseFrames" \
41+
"FuzzFrameUnmarshalBinary" \
42+
"FuzzBatchRoundTrip" \
43+
"FuzzDeriveDepositsRoundTrip" \
44+
"FuzzDeriveDepositsBadVersion" \
45+
"FuzzParseL1InfoDepositTxDataValid" \
46+
"FuzzParseL1InfoDepositTxDataBadLength" \
47+
"FuzzRejectCreateBlockBadTimestamp" \
48+
"FuzzDecodeDepositTxDataToL1Info" \
49+
| parallel -j {{PARALLEL_JOBS}} {{just_executable()}} node_fuzz_task {}

op-proposer/Makefile

+2-33
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
GITCOMMIT ?= $(shell git rev-parse HEAD)
2-
GITDATE ?= $(shell git show -s --format='%ct')
3-
# Find the github tag that points to this commit. If none are found, set the version string to "untagged"
4-
# Prioritizes release tag, if one exists, over tags suffixed with "-rc"
5-
VERSION ?= $(shell tags=$$(git tag --points-at $(GITCOMMIT) | grep '^op-proposer/' | sed 's/op-proposer\///' | sort -V); \
6-
preferred_tag=$$(echo "$$tags" | grep -v -- '-rc' | tail -n 1); \
7-
if [ -z "$$preferred_tag" ]; then \
8-
if [ -z "$$tags" ]; then \
9-
echo "untagged"; \
10-
else \
11-
echo "$$tags" | tail -n 1; \
12-
fi \
13-
else \
14-
echo $$preferred_tag; \
15-
fi)
1+
DEPRECATED_TARGETS := op-proposer clean test
162

17-
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
18-
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
19-
LDFLAGSSTRING +=-X main.Version=$(VERSION)
20-
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"
21-
22-
op-proposer:
23-
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) CGO_ENABLED=0 go build -v $(LDFLAGS) -o ./bin/op-proposer ./cmd
24-
25-
clean:
26-
rm bin/op-proposer
27-
28-
test:
29-
go test -v ./...
30-
31-
.PHONY: \
32-
clean \
33-
op-proposer \
34-
test
3+
include ../just/deprecated.mk

op-proposer/justfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import '../just/go.just'
2+
3+
# Build ldflags string
4+
_LDFLAGSSTRING := "'" + trim(
5+
"-X main.GitCommit=" + GITCOMMIT + " " + \
6+
"-X main.GitDate=" + GITDATE + " " + \
7+
"-X main.Version=" + VERSION + " " + \
8+
"") + "'"
9+
10+
BINARY := "./bin/op-proposer"
11+
12+
# Build op-proposer binary
13+
op-proposer: (go_build BINARY "./cmd" "-ldflags" _LDFLAGSSTRING)
14+
15+
# Clean build artifacts
16+
clean:
17+
rm -f {{BINARY}}
18+
19+
# Run tests
20+
test: (go_test "./...")

0 commit comments

Comments
 (0)