-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (122 loc) · 5.64 KB
/
Makefile
File metadata and controls
144 lines (122 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# ==============================================================================
# Makefile for Project Automation
#
# This Makefile automates tasks such as XDR generation, testing,
# code quality checks, and packaging.
# ==============================================================================
# ==============================================================================
# Phony Targets Declaration
# Declare all targets that do not represent actual files to ensure they
# are always executed and to improve 'make' performance.
# ==============================================================================
.PHONY: default unit-test full-unit-test integration-test package clean \
pre-commit type-check replace-xdr-keywords xdr-generate xdr \
xdr-clean xdr-update xdr-generator-test xdr-generator-update-snapshots
# ==============================================================================
# Configuration Variables
# Define key project-specific variables for easier management.
# ==============================================================================
# XDR (External Data Representation) files list
XDRS = xdr/Stellar-SCP.x \
xdr/Stellar-contract-config-setting.x \
xdr/Stellar-contract-env-meta.x \
xdr/Stellar-contract-meta.x \
xdr/Stellar-contract-spec.x \
xdr/Stellar-contract.x \
xdr/Stellar-exporter.x \
xdr/Stellar-internal.x \
xdr/Stellar-ledger-entries.x \
xdr/Stellar-ledger.x \
xdr/Stellar-overlay.x \
xdr/Stellar-transaction.x \
xdr/Stellar-types.x
# Stellar XDR definitions repository commit hash
XDR_COMMIT = cff714a5ebaaaf2dac343b3546c2df73f0b7a36e
# Command prefix for running Python tools with uv
UV_RUN_CMD = uv run --frozen --all-extras
# ==============================================================================
# Platform-Specific Commands
# Adjust commands based on the operating system (e.g., 'sed' differences).
# ==============================================================================
ifeq ($(shell uname), Darwin)
SED_INPLACE := sed -i ''
# Use find -exec with \; for macOS sed due to argument parsing differences
REPLACE_KEYWORD_COMMAND := find xdr -type f -exec $(SED_INPLACE) 's/from;/from_;/g' {} +
REPLACE_DOCS := $(SED_INPLACE) '/stellar_sdk\.xdr/,$$d' docs/en/api.rst
else
SED_INPLACE := sed -i
# Use find -exec with {} \; for Linux/GNU sed
REPLACE_KEYWORD_COMMAND := find xdr -type f -exec $(SED_INPLACE) 's/from;/from_;/g' {} \;
REPLACE_DOCS := $(SED_INPLACE) '/stellar_sdk\.xdr/,$$d' docs/en/api.rst
endif
# ==============================================================================
# Default Target
# No action by default, encourages explicit target execution.
# ==============================================================================
default: ;
# ==============================================================================
# Test Automation
# Targets for running various levels of tests with coverage.
# ==============================================================================
unit-test:
$(UV_RUN_CMD) pytest -v -s -rs tests --cov --cov-report=html
full-unit-test:
$(UV_RUN_CMD) pytest -v -s -rs tests --runslow --cov --cov-report=html
integration-test:
$(UV_RUN_CMD) pytest -v -s -rs tests --runslow --integration --cov=./ --cov-report=xml
# ==============================================================================
# Build & Clean Targets
# Manage project packaging and cleanup of build artifacts.
# ==============================================================================
package:
uv build
clean:
find . -name \*.pyc -delete
rm -rf coverage.xml .coverage dist htmlcov stellar_sdk.egg-info tests/.mypy_cache tests/.pytest_cache docs/en/_build
# ==============================================================================
# Code Quality Checks
# Targets for running pre-commit hooks and type checkers.
# ==============================================================================
pre-commit:
$(UV_RUN_CMD) pre-commit run --all-file
type-check:
$(UV_RUN_CMD) pyright
$(UV_RUN_CMD) mypy -p stellar_sdk -p tests -p examples
# ==============================================================================
# XDR Generation & Management
# Targets for fetching, generating, and cleaning XDR-related files.
# ==============================================================================
replace-xdr-keywords:
$(REPLACE_KEYWORD_COMMAND)
xdr-generate: $(XDRS) replace-xdr-keywords
@echo "--- Generating XDR Python files ---"
$(REPLACE_KEYWORD_COMMAND)
docker run -it --rm -v $(PWD):/wd -w /wd ruby:3.4 /bin/bash -c '\
cd xdr-generator && \
bundle install --quiet && \
bundle exec ruby generate.rb'
@echo "--- Updating XDR API documentation ---"
$(REPLACE_DOCS)
$(UV_RUN_CMD) python docs/gen_xdr_api.py >> docs/en/api.rst
@echo "--- Running pre-commit hooks ---"
$(MAKE) pre-commit
xdr/%.x:
@echo "--- Fetching $@ ---"
curl -Lsf -o $@ https://raw.githubusercontent.com/stellar/stellar-xdr/$(XDR_COMMIT)/$(@F)
xdr-generator-test:
@echo "--- Running xdr-generator snapshot tests ---"
docker run --rm -v $(PWD):/wd -w /wd ruby:3.4 /bin/bash -c '\
cd xdr-generator && \
bundle install --quiet && \
bundle exec ruby test/generator_snapshot_test.rb'
xdr-generator-update-snapshots:
@echo "--- Updating xdr-generator snapshots ---"
docker run --rm -v $(PWD):/wd -w /wd ruby:3.4 /bin/bash -c '\
cd xdr-generator && \
bundle install --quiet && \
UPDATE_SNAPSHOTS=1 bundle exec ruby test/generator_snapshot_test.rb'
xdr-clean:
@echo "--- Cleaning XDR files ---"
rm -f xdr/*.x stellar_sdk/xdr/*.py || true
xdr-update: xdr-clean xdr-generate
@echo "--- XDR update complete ---"