|
1 | | -.PHONY: all |
| 1 | +.PHONY: all build build-dotnet6 build-dotnet-framework clean clean-build precommit restore test test-dotnet6 test-dotnet-framework run-examples help |
| 2 | + |
| 3 | +# Determine the operating system |
| 4 | +OS := $(shell uname) |
| 5 | + |
| 6 | +# Set the default .NET version to .NET 6.0 |
| 7 | +DOTNET_VERSION := net6.0 |
| 8 | +TEST_LOGGER_OPTIONS := --logger "console;verbosity=detailed" |
| 9 | + |
| 10 | +# Windows-specific settings |
| 11 | +# This tests if "NT" is in the OS string, which would indicate Windows. |
| 12 | +ifneq (,$(findstring NT,$(OS))) |
| 13 | + BUILD_TARGETS := build-dotnet6 build-dotnet-framework |
| 14 | + TEST_TARGETS := test-dotnet6 test-dotnet-framework |
| 15 | +else |
| 16 | + BUILD_TARGETS := build-dotnet6 |
| 17 | + TEST_TARGETS := test-dotnet6 |
| 18 | +endif |
| 19 | + |
| 20 | +# Enable gRPC-Web if requested |
| 21 | +GRPC_WEB_FLAG := |
| 22 | +ifeq ($(GRPC_WEB), true) |
| 23 | + GRPC_WEB_FLAG := -p:DefineConstants=USE_GRPC_WEB |
| 24 | +endif |
| 25 | + |
2 | 26 | ## Generate sync unit tests, format, lint, and test |
3 | 27 | all: precommit |
4 | 28 |
|
5 | 29 |
|
6 | | -.PHONY: build |
7 | | -## Build project |
8 | | -build: |
9 | | - @dotnet build |
| 30 | +## Build the project (conditioned by OS) |
| 31 | +build: ${BUILD_TARGETS} |
| 32 | + |
| 33 | + |
| 34 | +## Build the project for .NET 6.0 |
| 35 | +build-dotnet6: |
| 36 | + @echo "Building the project for .NET 6.0..." |
| 37 | + @dotnet build -f ${DOTNET_VERSION} ${GRPC_WEB_FLAG} |
| 38 | + |
10 | 39 |
|
| 40 | +## Build the project on .NET Framework |
| 41 | +build-dotnet-framework: |
| 42 | + @echo "Building the project for .NET Framework 4.62..." |
| 43 | + @dotnet build -f net462 ${GRPC_WEB_FLAG} |
11 | 44 |
|
12 | | -.PHONY: clean |
13 | 45 | ## Remove build files |
14 | 46 | clean: |
| 47 | + @echo "Cleaning build artifacts..." |
15 | 48 | @dotnet clean |
16 | 49 |
|
17 | 50 |
|
18 | | -.PHONY: clean-build |
19 | 51 | ## Build project |
20 | | -clean-build: clean restore build |
| 52 | +clean-build: clean restore ${BUILD_TARGETS} |
21 | 53 |
|
22 | 54 |
|
23 | | -.PHONY: precommit |
24 | 55 | ## Run clean-build and test as a step before committing. |
25 | 56 | precommit: clean-build test |
26 | 57 |
|
27 | 58 |
|
28 | | -.PHONY: restore |
29 | 59 | ## Sync dependencies |
30 | 60 | restore: |
| 61 | + @echo "Restoring dependencies..." |
31 | 62 | @dotnet restore |
32 | 63 |
|
33 | 64 |
|
34 | | -.PHONY: test |
35 | | -## Run unit and integration tests |
36 | | -test: |
37 | | - @dotnet test |
| 65 | +## Run unit and integration tests (conditioned by OS) |
| 66 | +test: ${TEST_TARGETS} |
38 | 67 |
|
39 | 68 |
|
40 | | -.PHONY: test-net6 |
41 | 69 | ## Run unit and integration tests on the .NET 6.0 runtime |
42 | | -test-net6: |
43 | | - @dotnet test -f net6.0 |
| 70 | +test-dotnet6: |
| 71 | + @echo "Running tests on .NET 6.0..." |
| 72 | + @dotnet test ${TEST_LOGGER_OPTIONS} -f ${DOTNET_VERSION} |
44 | 73 |
|
45 | 74 |
|
46 | | -.PHONY: test-net-framework |
47 | | -## Run unit and integration tests on the .NET Framework runtime |
48 | | -test-net-framework: |
49 | | - @dotnet test -f net462 |
| 75 | +## Run unit and integration tests on the .NET Framework runtime (Windows only) |
| 76 | +test-dotnet-framework: |
| 77 | + @echo "Running tests on .NET Framework 4.62 (Windows only)..." |
| 78 | + @dotnet test ${TEST_LOGGER_OPTIONS} -f net462 |
50 | 79 |
|
51 | 80 |
|
52 | | -.PHONY: run-examples |
53 | 81 | ## Run example applications and snippets |
54 | 82 | run-examples: |
55 | 83 | @dotnet run --project examples/MomentoApplication |
56 | 84 | @dotnet run --project examples/DocExampleApis |
57 | 85 |
|
58 | 86 | # See <https://gist.github.com/klmr/575726c7e05d8780505a> for explanation. |
59 | | -.PHONY: help |
60 | 87 | help: |
61 | 88 | @echo "$$(tput bold)Available rules:$$(tput sgr0)";echo;sed -ne"/^## /{h;s/.*//;:d" -e"H;n;s/^## //;td" -e"s/:.*//;G;s/\\n## /---/;s/\\n/ /g;p;}" ${MAKEFILE_LIST}|LC_ALL='C' sort -f|awk -F --- -v n=$$(tput cols) -v i=19 -v a="$$(tput setaf 6)" -v z="$$(tput sgr0)" '{printf"%s%*s%s ",a,-i,$$1,z;m=split($$2,w," ");l=n-i;for(j=1;j<=m;j++){l-=length(w[j])+1;if(l<= 0){l=n-i-length(w[j])-1;printf"\n%*s ",-i," ";}printf"%s ",w[j];}printf"\n";}'|more $(shell test $(shell uname) == Darwin && echo '-Xr') |
0 commit comments