From 1130412d95a383e2f2ce63f3c6667d932d5bec09 Mon Sep 17 00:00:00 2001 From: ewa Date: Sun, 25 Jan 2026 21:49:25 +0300 Subject: [PATCH] Update Makefile Changelog: feat(makefile): Add colored help menu for command listing. sec(env): Enforce .env check and OP_COMMIT validation; abort on failure. chore(logs): Add @echo lines for better execution transparency. style(fmt): Add make fmt command for code formatting. warn(test): specific warning message when running tests with --ffi. --- Makefile | 59 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 213932c..6dabb58 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,31 @@ -include .env +# Load environment variables from .env file if it exists +ifneq (,$(wildcard .env)) + include .env + export +endif + +# Default target: show help +.DEFAULT_GOAL := help ## -# Solidity Setup / Testing +# ----------------------------------------------------------------------------- +# Solidity Setup / Testing / DevOps +# ----------------------------------------------------------------------------- ## + +.PHONY: help +help: ## Show this help message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + .PHONY: install-foundry -install-foundry: +install-foundry: ## Install Foundry toolchain (forge, cast, anvil) + @echo "[+] Installing Foundry..." curl -L https://foundry.paradigm.xyz | bash - ~/.foundry/bin/foundryup + @echo "[!] Please verify your PATH or restart your shell to use 'forge'." .PHONY: deps -deps: clean-lib checkout-op-commit +deps: clean-lib checkout-op-commit ## Clean and re-install all Solidity dependencies + @echo "[+] Installing standard dependencies..." forge install --no-git github.com/foundry-rs/forge-std \ github.com/OpenZeppelin/openzeppelin-contracts@v4.9.3 \ github.com/OpenZeppelin/openzeppelin-contracts-upgradeable@v4.7.3 \ @@ -18,29 +34,44 @@ deps: clean-lib checkout-op-commit github.com/safe-global/safe-smart-account@v1.4.1-3 .PHONY: test -test: +test: ## Run tests (Warning: --ffi enabled, check dependencies!) + @echo "[!] Running tests with FFI enabled. Ensure you trust all dependencies." forge test --ffi -vvv +.PHONY: snapshot +snapshot: ## Generate a gas snapshot for contract methods + forge snapshot --ffi + +.PHONY: fmt +fmt: ## Format Solidity code + forge fmt + .PHONY: clean-lib -clean-lib: +clean-lib: ## Remove the lib directory + @echo "[+] Cleaning lib directory..." rm -rf lib .PHONY: checkout-op-commit -checkout-op-commit: - [ -n "$(OP_COMMIT)" ] || (echo "OP_COMMIT must be set in .env" && exit 1) - rm -rf lib/optimism - mkdir -p lib/optimism - cd lib/optimism; \ +checkout-op-commit: ## Sparse checkout specific Optimism commit defined in .env + @echo "[+] Checking out Optimism commit: $(OP_COMMIT)" + @[ -n "$(OP_COMMIT)" ] || (echo "Error: OP_COMMIT must be set in .env" && exit 1) + @rm -rf lib/optimism + @mkdir -p lib/optimism + @cd lib/optimism; \ git init; \ git remote add origin https://github.com/ethereum-optimism/optimism.git; \ git fetch --depth=1 origin $(OP_COMMIT); \ git reset --hard FETCH_HEAD .PHONY: bindings -bindings: +bindings: ## Generate Go bindings from Solidity ABIs + @echo "[+] Installing abigen (v1.15.8)..." go install github.com/ethereum/go-ethereum/cmd/abigen@v1.15.8 + @echo "[+] Building contracts..." forge build + @echo "[+] Generating Go bindings..." mkdir -p bindings abigen --abi out/BalanceTracker.sol/BalanceTracker.abi.json --pkg bindings --type BalanceTracker --out bindings/balance_tracker.go abigen --abi out/FeeDisburser.sol/FeeDisburser.abi.json --pkg bindings --type FeeDisburser --out bindings/fee_disburser.go - cd bindings && go mod tidy \ No newline at end of file + @echo "[+] Tidying Go modules..." + cd bindings && go mod tidy