-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
166 lines (143 loc) · 5.37 KB
/
Makefile
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Copyright (c) 2021-2023 Koji Hasegawa.
# This software is released under the MIT License.
PROJECT_HOME?=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR?=$(PROJECT_HOME)/Build
LOG_DIR?=$(PROJECT_HOME)/Logs
UNITY_VERSION?=$(shell grep 'm_EditorVersion:' $(PROJECT_HOME)/ProjectSettings/ProjectVersion.txt | grep -o -E '\d{4}\.[1-4]\.\d+[abfp]\d+')
# Code Coverage report filter (comma separated)
# see: https://docs.unity3d.com/Packages/com.unity.testtools.codecoverage@1.2/manual/CoverageBatchmode.html
EMBEDDED_PACKAGE_ASSEMBLIES?=$(shell echo $(shell find ./Packages -name "*.asmdef" | sed -e s/.*\\//\+/ | sed -e s/\\.asmdef// | sed -e s/^.*\\.Tests//) | sed -e s/\ /,/g)
COVERAGE_ASSEMBLY_FILTERS?=+<assets>,$(EMBEDDED_PACKAGE_ASSEMBLIES),-GeneratedTests,-*.Tests
# -nographics` option
ifdef NOGRAPHICS
NOGRAPHICS=-nographics
endif
# -testCategory option. see https://docs.unity3d.com/Packages/com.unity.test-framework@1.3/manual/reference-command-line.html#testcategory
ifdef CATEGORY
TEST_CATEGORY=-testCategory "$(CATEGORY)"
else
TEST_CATEGORY=-testCategory "!IgnoreCI;!Integration"
endif
# -testFilter option. see https://docs.unity3d.com/Packages/com.unity.test-framework@1.3/manual/reference-command-line.html#testfilter
ifdef FILTER
TEST_FILTER=-testFilter "$(FILTER)"
endif
# -assemblyNames option. see https://docs.unity3d.com/Packages/com.unity.test-framework@1.3/manual/reference-command-line.html#assemblynames
ifdef ASSEMBLY
ASSEMBLY_NAMES=-assemblyNames "$(ASSEMBLY)"
endif
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
UNITY_HOME=/Applications/Unity/HUB/Editor/$(UNITY_VERSION)/Unity.app/Contents
UNITY?=$(UNITY_HOME)/MacOS/Unity
UNITY_YAML_MERGE?=$(UNITY_HOME)/Tools/UnityYAMLMerge
STANDALONE_PLAYER=StandaloneOSX
endif
ifeq ($(UNAME), Linux) # not test yet
UNITY_HOME=$HOME/Unity/Hub/Editor/<version>
UNITY?=$(UNITY_HOME)/Unity
UNITY_YAML_MERGE?=$(UNITY_HOME)/ # unknown
STANDALONE_PLAYER=StandaloneLinux64
endif
define base_arguments
-projectPath $(PROJECT_HOME) \
-logFile $(LOG_DIR)/$(TEST_PLATFORM).log
endef
define test_arguments
-batchmode \
$(NOGRAPHICS) \
-silent-crashes \
-stackTraceLogType Full \
-runTests \
$(TEST_CATEGORY) \
$(TEST_FILTER) \
$(ASSEMBLY_NAMES) \
-testPlatform $(TEST_PLATFORM) \
-testResults $(LOG_DIR)/$(TEST_PLATFORM)-results.xml \
-testHelperJUnitResults $(LOG_DIR)/$(TEST_PLATFORM)-junit-results.xml \
-testHelperScreenshotDirectory $(LOG_DIR)/Screenshots
endef
define test
$(eval TEST_PLATFORM=$1)
mkdir -p $(LOG_DIR)
$(UNITY) \
$(call base_arguments) \
$(call test_arguments)
endef
define cover
$(eval TEST_PLATFORM=$1)
mkdir -p $(LOG_DIR)
$(UNITY) \
$(call base_arguments) \
$(call test_arguments) \
--burst-disable-compilation \
-debugCodeOptimization \
-enableCodeCoverage \
-coverageResultsPath $(LOG_DIR) \
-coverageOptions 'generateAdditionalMetrics;generateTestReferences;dontClear;assemblyFilters:$(COVERAGE_ASSEMBLY_FILTERS)'
endef
define cover_report
mkdir -p $(LOG_DIR)
$(UNITY) \
$(call base_arguments) \
-batchmode \
-quit \
-enableCodeCoverage \
-coverageResultsPath $(LOG_DIR) \
-coverageOptions 'generateHtmlReport;generateAdditionalMetrics;generateAdditionalReports;assemblyFilters:$(COVERAGE_ASSEMBLY_FILTERS)'
endef
.PHONY: usage
usage:
@echo "Tasks:"
@echo " clean: Clean Build and Logs directories in created project."
@echo " setup_unityyamlmerge: Setup UnityYAMLMerge as mergetool in .git/config."
@echo " open: Open this project in Unity editor."
@echo " test_editmode: Run Edit Mode tests."
@echo " test_playmode: Run Play Mode tests."
@echo " cover_report: Create code coverage HTML report."
@echo " test: Run test_editmode, test_playmode, and cover_report. Recommended to use with '-k' option."
@echo " test_standalone_player: Run Play Mode tests on standalone player."
@echo " test_android: Run Play Mode tests on Android device."
@echo " test_ios: Run Play Mode tests on iOS device."
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
rm -rf $(LOG_DIR)
.PHONY: setup_unityyamlmerge
setup_unityyamlmerge:
git config --local merge.tool "unityyamlmerge"
git config --local mergetool.unityyamlmerge.trustExitCode false
git config --local mergetool.unityyamlmerge.cmd '$(UNITY_YAML_MERGE) merge -p "$$BASE" "$$REMOTE" "$$LOCAL" "$$MERGED"'
.PHONY: open
open:
mkdir -p $(LOG_DIR)
$(UNITY) $(call base_arguments) &
.PHONY: test_editmode
test_editmode:
$(call cover,editmode)
.PHONY: test_playmode
test_playmode:
$(call cover,playmode)
.PHONY: cover_report
cover_report:
$(call cover_report)
# Run Edit Mode and Play Mode tests with coverage and html-report by code coverage package.
# If you run this target with the `-k` option, if the Edit/Play Mode test fails,
# it will run through to Html report generation and return an exit code indicating an error.
.PHONY: test
test: test_editmode test_playmode cover_report
# Run Play Mode tests on standalone player
# Run test because code coverage package is not support run on standalone player.
.PHONY: test_standalone_player
test_standalone_player:
$(call test,$(STANDALONE_PLAYER))
# Run Play Mode tests on Android device
# Run test because code coverage package is not support run on standalone player.
.PHONY: test_android
test_android:
$(call test,Android)
# Run Play Mode tests on iOS device
# Run test because code coverage package is not support run on standalone player.
.PHONY: test_ios
test_ios:
$(call test,iOS)