Skip to content

Commit 28279fd

Browse files
committed
More readable Makefile, Package.swift and add Scripts
1 parent fd172cf commit 28279fd

File tree

4 files changed

+159
-291
lines changed

4 files changed

+159
-291
lines changed

Makefile

Lines changed: 47 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,56 @@
11
#!make
2-
3-
# Maintanence
4-
# The path and implemenet for OPENAPI_PATH.
5-
# The pattern and implemenet for TAG_NAMES.
6-
7-
# Special-Targets #
2+
# Special-Targets
83
# https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
9-
.DEFAULT_GOAL := install
10-
OPENAPI_PATH := Submodule/github/rest-api-description/descriptions/api.github.com/api.github.com.yaml
11-
TAG_NAMES := $(shell yq -r '.tags[].name' $(OPENAPI_PATH))
12-
SUBDIRS := $(addprefix Sources/, $(TAG_NAMES))
13-
SWIFT_FILES := $(addsuffix /Client.swift, $(SUBDIRS))
14-
.SECONDARY : $(%.yml)
15-
16-
%/openapi.yml: $(OPENAPI_PATH)
17-
@mkdir -p "$(@D)"
18-
@ln -sf ../../$(OPENAPI_PATH) $@
19-
@git add $@
20-
@echo "::debug:: make $@"
21-
22-
%/openapi-generator-config.yml: $(OPENAPI_PATH)
23-
@mkdir -p "$(@D)"
24-
@tag_name=$(shell basename $(shell dirname $@)); \
25-
echo "generate:" > $@; \
26-
echo " - types" >> $@; \
27-
echo " - client" >> $@; \
28-
echo "" >> $@; \
29-
echo "filter:" >> $@; \
30-
echo " tags:" >> $@; \
31-
echo " - $$tag_name" >> $@; \
32-
echo "" >> $@; \
33-
echo "accessModifier: public" >> $@; \
34-
echo "" >> $@;
35-
@git add $@
36-
@echo "::debug:: make $@"
374

38-
%/Client.swift: %/openapi.yml %/openapi-generator-config.yml
39-
mint run apple/swift-openapi-generator generate $(@D)/openapi.yml \
40-
--config $(@D)/openapi-generator-config.yml \
41-
--output-directory $(@D)
42-
@git add $(@D)
43-
@git commit -m "[Make] Generate $(@D)/*.swift" >/dev/null \
44-
&& echo "::notice:: make $@" \
45-
|| true
46-
47-
.PHONY: install-$(OPENAPI_PATH)
48-
install-$(OPENAPI_PATH):
5+
# Variables
6+
.DEFAULT_GOAL := install
7+
OPENAPI_PATH := Submodule/github/rest-api-description/descriptions/api.github.com/api.github.com.yaml
8+
FILTERED_NAMES := $(shell yq -r '.tags[].name' $(OPENAPI_PATH))
9+
SOURCE_DIRS := $(addprefix Sources/, $(FILTERED_NAMES))
10+
11+
# Helper
12+
.SILENT: commit
13+
.PHONY: commit
14+
commit:
15+
git add "$(file)"
16+
git commit -m "[Make] Update $(file)" >/dev/null \
17+
&& echo "::notice:: make $(file)\n" \
18+
|| true;
19+
touch "$(file)";
20+
21+
# Create sources
22+
%/openapi-generator-config.yml:
23+
mkdir -p "$(@D)"; \
24+
tag_name=$(shell basename $(shell dirname $@)); \
25+
swift Scripts/GeneratorConfigBuilder.swift $$tag_name
26+
27+
%/Client.swift: %/openapi-generator-config.yml $(OPENAPI_PATH)
28+
mint run apple/swift-openapi-generator generate "$(OPENAPI_PATH)" \
29+
--config "$(@D)/openapi-generator-config.yml" \
30+
--output-directory "$(@D)";
31+
@rm "$(@D)/openapi-generator-config.yml";
32+
@echo ;
33+
34+
Sources/%: Sources/%/Client.swift
35+
@$(MAKE) commit file="$@"
36+
37+
# Update openapi specification if needed
38+
Submodule:
4939
ifdef GITHUB_ACTIONS ## https://docs.github.com/en/actions/learn-github-actions/variables
50-
@touch $(OPENAPI_PATH)
51-
@echo "::notice:: make $@"
40+
@touch "$(OPENAPI_PATH)"
5241
else
53-
git submodule update --recursive --remote
54-
@git add Submodule
55-
@git commit -m "[Make] Bump$$(git submodule status Submodule/github/rest-api-description)" >/dev/null \
56-
&& touch $(OPENAPI_PATH) \
57-
&& echo "::notice:: make $@" \
58-
|| true
42+
@git submodule update --recursive --remote
43+
@$(MAKE) commit file="$@"
44+
@touch "$(OPENAPI_PATH)"
5945
endif
6046

61-
.PHONY: install-$(SWIFT_FILES)
62-
install-$(SWIFT_FILES): $(SWIFT_FILES)
63-
swift PackageBuilder.swift
64-
git add Package.swift
65-
@git commit -m "[Make] Generate Package.swift" >/dev/null \
66-
&& echo "::notice:: make $@" \
67-
|| true
68-
69-
install: install-$(OPENAPI_PATH) install-$(SWIFT_FILES)
70-
@echo "::notice:: make $@"
71-
72-
# XCFrameworks:
73-
# mint run giginet/Scipio create . \
74-
# --static \
75-
# --embed-debug-symbols \
76-
# --support-simulators
77-
# @touch $@
78-
# @echo "::notice:: make $@"
79-
#
80-
# %.zip: %.xcframework
81-
# @zip -qr "$@" "$<"
82-
# @rm -rf "$<"
83-
# @git add "$@"
84-
# @echo "::debug:: make $@"
85-
#
86-
# install-zips: XCFrameworks
87-
# @$(MAKE) $(shell echo XCFrameworks/*.xcframework | sed 's/\.xcframework/\.zip/g');
88-
# @git commit -m "[Make] Modify xcframework zips" || true
89-
# @echo "::notice:: make $@"
90-
91-
.PHONY: update-to-date
92-
update-to-date:
93-
touch $(OPENAPI_PATH)
94-
touch Sources/**/openapi-generator-config.yml
95-
touch Sources/**/openapi.yml
96-
touch Sources/**/Client.swift
47+
# Update Package.swift
48+
.DELETE_ON_ERROR: $(SOURCE_DIRS)
49+
Package.swift: $(SOURCE_DIRS)
50+
swift Scripts/PackageBuilder.swift
51+
@$(MAKE) commit file="$@"
9752

98-
# docs: ## Need env GITHUB_PAGES is created as 'true'
99-
# swift package --allow-writing-to-directory $@ generate-documentation \
100-
# --disable-indexing \
101-
# --transform-for-static-hosting \
102-
# --hosting-base-path github-rest-api-swift-openapi;
103-
# sh Script/setupDocsHtml.sh
53+
# Install
54+
.PHONY: Submodule
55+
install: Submodule Package.swift
10456

105-
.PHONY: help
106-
.SILENT: help
107-
help:
108-
echo -----------------------------------------------------------------------
109-
awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-14s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
110-
echo -----------------------------------------------------------------------

0 commit comments

Comments
 (0)