-
Notifications
You must be signed in to change notification settings - Fork 459
/
Makefile
625 lines (570 loc) · 25.8 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#
# Key targets in this makefile:
#
# make build
# Build the runtime library and plugin
# make test
# Build everything, run both plugin and library tests:
# Plugin test verifies that plugin output matches the "Reference" files
# exactly
# Library test exercises most features of the generated code
# make regenerate
# Recompile all the necessary protos
# (requires protoc in path)
#
# Caution: 'test' does not 'regenerate', so if you've made changes to the code
# generation, you'll need to do more than just 'test':
# 1. 'make build' to build the plugin
# 2. 'make regenerate' to rebuild the Swift code from protos using the new
# plugin
# 3. 'make build' again to recompile everything with the regenerated protos
# 4. 'make test' to run the test suites
#
# How to run a 'swift' executable that supports the 'swift update', 'swift build',
# 'swift test', etc commands.
SWIFT=swift
# How to run a working version of protoc. Invoke make with PROTOC=[path] to
# override this value, i.e. -
# make [TARGET] PROTOC=../protobuf/src/protoc
PROTOC=protoc
# How to run awk on your system
AWK=awk
# Installation directory
BINDIR=/usr/local/bin
# Install tool name
INSTALL=install
# Where to find a google/protobuf checkout. Defaults be being beside this
# checkout. Invoke make with GOOGLE_PROTOBUF_CHECKOUT=[PATH_TO_CHECKOUT] to
# override this value, i.e. -
# make [TARGET] GOOGLE_PROTOBUF_CHECKOUT=[PATH_TO_CHECKOUT]
GOOGLE_PROTOBUF_CHECKOUT?=../protobuf
# Helpers for the common parts of source generation.
#
# To ensure that the local version of the plugin is always used (and not a
# previously installed one), we use a custom output name (-tfiws_out).
PROTOC_GEN_SWIFT=.build/debug/protoc-gen-swift
GENERATE_SRCS_BASE=${PROTOC} --plugin=protoc-gen-tfiws=${PROTOC_GEN_SWIFT}
# Search 'Protos/SwiftProtobuf/' so the WKTs can be found (google/protobuf/*).
GENERATE_SRCS=${GENERATE_SRCS_BASE} -I Protos/SwiftProtobuf
# Where to find the Swift conformance test runner executable.
SWIFT_CONFORMANCE_PLUGIN=.build/debug/Conformance
# Where to find the conformance-test-runner. Defaults to being in your protobuf
# checkout. Invoke make with CONFORMANCE_TEST_RUNNER=[PATH_TO_BINARY] to
# override this value.
CONFORMANCE_TEST_RUNNER?=${GOOGLE_PROTOBUF_CHECKOUT}/conformance_test_runner
# Hook to pass arge to swift build|test (mainly for the CI setup)
SWIFT_BUILD_TEST_HOOK?=
# The directories within Protos/ with the exception of "upstream". Use for the
# maintenance of the 'Reference' target and test-plugin.
PROTOS_DIRS=Conformance protoc-gen-swiftTests SwiftProtobuf SwiftProtobufPluginLibrary SwiftProtobufPluginLibraryTests SwiftProtobufTests
.PHONY: \
all \
build \
check \
check-for-protobuf-checkout \
check-proto-files \
check-version-numbers \
clean \
compile-tests \
compile-tests-multimodule \
compile-tests-internalimportsbydefault \
default \
docs \
install \
pod-lib-lint \
reference \
regenerate \
regenerate-compiletests-multimodule-protos \
copy-compiletests-internalimportsbydefault-protos \
regenerate-compiletests-protos \
regenerate-conformance-protos \
regenerate-fuzz-protos \
regenerate-library-protos \
regenerate-plugin-protos \
regenerate-test-protos \
test \
test-all \
test-everything \
test-plugin \
test-runtime \
test-spm-plugin \
update-proto-files
default: build
all: build
# Builds all the targets of the package.
build:
${SWIFT} build ${SWIFT_BUILD_TEST_HOOK}
# Anything that needs the plugin should do a build.
${PROTOC_GEN_SWIFT}: build
# Does it really make sense to install a debug build, or should this be forcing
# a release build and then installing that instead?
install: build
${INSTALL} ${PROTOC_GEN_SWIFT} ${BINDIR}
clean:
swift package clean
rm -rf .build _test ${PROTOC_GEN_SWIFT} *DescriptorTestData.bin \
Performance/_generated Performance/_results Protos/mined_words.txt \
docs build
find . -name '*~' | xargs rm -f
# Build a local copy of the API documentation, using the same process used
# by cocoadocs.org.
docs:
@if which jazzy >/dev/null; then \
jazzy; \
else \
echo "Jazzy not installed, use 'gem install jazzy' or download from https://github.com/realm/jazzy"; \
fi
#
# Test the runtime and the plugin
#
# This must pass before any commit.
#
check test: build test-runtime test-plugin test-conformance check-version-numbers
# Test everything (runtime, plugin)
test-all test-everything: test
# Check the version numbers are all in sync.
check-version-numbers:
@DevTools/LibraryVersions.py --validate
#
# The Swift test suite includes unit tests for the runtime library
# and functional tests for the Swift code generated by the plugin.
#
test-runtime: build
${SWIFT} test ${SWIFT_BUILD_TEST_HOOK}
#
# Test the plugin by itself:
# * Translate every proto in Protos into Swift using local protoc-gen-swift
# * Put result in _test directory
# * Compare output with reference output in Reference directory
# * If generated output and reference output don't match exactly, fail.
#
# Of course, this will fail if you've made any changes to the generated output.
# In that case, you'll need to do the following before committing:
# * `make regenerate` to rebuild the protos used by the runtime and plugin
# * `make test-runtime` to verify that the runtime works correctly with the new changes
# * `make reference` to update the Reference directory
# * MANUALLY go through `git diff Reference` to verify that the generated Swift changed in the way you expect
# * `make clean build test` to do a final check
#
# Note: Some of these protos define the same package.(message|enum)s, so they
# can't be done in a single protoc/proto-gen-swift invoke and have to be done
# one at a time instead.
test-plugin: build ${PROTOC_GEN_SWIFT}
@rm -rf _test && mkdir -p _test/upstream
for p in `find Protos/upstream -type f -name '*.proto'`; do \
${GENERATE_SRCS_BASE} \
-I Protos/upstream \
--tfiws_out=_test/upstream $$p || exit 1; \
done
for d in ${PROTOS_DIRS}; do \
mkdir _test/$$d ; \
${GENERATE_SRCS_BASE} \
-I Protos/SwiftProtobuf \
-I Protos/SwiftProtobufPluginLibrary \
-I Protos/$$d \
--tfiws_out=_test/$$d \
`find Protos/$$d -type f -name "*.proto"` || exit 1; \
done
@mkdir -p _test/CompileTests/MultiModule
${GENERATE_SRCS} \
-I Protos/CompileTests/MultiModule \
--tfiws_opt=Visibility=Public \
--tfiws_opt=ProtoPathModuleMappings=Protos/CompileTests/MultiModule/module_mappings.pbascii \
--tfiws_out=_test/CompileTests/MultiModule \
`(find Protos/CompileTests/MultiModule -type f -name "*.proto")`
@mkdir -p _test/CompileTests/InternalImportsByDefault
${GENERATE_SRCS} \
-I Protos/CompileTests/InternalImportsByDefault \
--tfiws_opt=Visibility=Public \
--tfiws_opt=UseAccessLevelOnImports=true \
--tfiws_out=_test/CompileTests/InternalImportsByDefault \
`(find Protos/CompileTests/InternalImportsByDefault -type f -name "*.proto")`
diff -ru _test Reference
# Test the SPM plugin.
test-spm-plugin:
env PROTOC_PATH=$(shell realpath ${PROTOC}) ${SWIFT} test --package-path PluginExamples
compile-tests: \
compile-tests-multimodule \
compile-tests-internalimportsbydefault
# Test that ensures generating public into multiple modules with `import public`
# yields buildable code.
compile-tests-multimodule:
${SWIFT} test --package-path CompileTests/MultiModule
# Test that ensures that using access level modifiers on imports yields code that's buildable
# when `InternalImportsByDefault` is enabled on the module.
compile-tests-internalimportsbydefault:
env PROTOC_PATH=$(shell realpath ${PROTOC}) ${SWIFT} build --package-path CompileTests/InternalImportsByDefault
# Rebuild the reference files by running the local version of protoc-gen-swift
# against our menagerie of sample protos.
#
# If you do this, you MUST MANUALLY verify these files before checking them in,
# since the new checkin will become the new main reference.
#
# Note: Some of the upstream protos define the same package.(message|enum)s, so
# they can't be done in a single protoc/proto-gen-swift invoke and have to be
# done one at a time instead.
reference: build ${PROTOC_GEN_SWIFT}
@rm -rf Reference && mkdir -p Reference/upstream
for p in `find Protos/upstream -type f -name '*.proto'`; do \
${GENERATE_SRCS_BASE} \
-I Protos/upstream \
--tfiws_out=Reference/upstream $$p || exit 1; \
done
for d in ${PROTOS_DIRS}; do \
mkdir Reference/$$d ; \
${GENERATE_SRCS_BASE} \
-I Protos/SwiftProtobuf \
-I Protos/SwiftProtobufPluginLibrary \
-I Protos/$$d \
--tfiws_out=Reference/$$d \
`find Protos/$$d -type f -name "*.proto"` || exit 1; \
done
@mkdir -p Reference/CompileTests/MultiModule
${GENERATE_SRCS} \
-I Protos/CompileTests/MultiModule \
--tfiws_opt=Visibility=Public \
--tfiws_opt=ProtoPathModuleMappings=Protos/CompileTests/MultiModule/module_mappings.pbascii \
--tfiws_out=Reference/CompileTests/MultiModule \
`(find Protos/CompileTests/MultiModule -type f -name "*.proto")`
@mkdir -p Reference/CompileTests/InternalImportsByDefault
${GENERATE_SRCS} \
-I Protos/CompileTests/InternalImportsByDefault \
--tfiws_opt=Visibility=Public \
--tfiws_opt=UseAccessLevelOnImports=true \
--tfiws_out=Reference/CompileTests/InternalImportsByDefault \
`(find Protos/CompileTests/InternalImportsByDefault -type f -name "*.proto")`
#
# Rebuild the generated .pb.swift test files by running
# protoc over all the relevant inputs.
#
# Before running this, ensure that:
# * protoc-gen-swift is built and installed somewhere in your system PATH
# * protoc is built and installed
# * PROTOC at the top of this file is set correctly
#
regenerate: \
regenerate-library-protos \
regenerate-fuzz-protos \
regenerate-plugin-protos \
regenerate-test-protos \
regenerate-compiletests-protos \
regenerate-conformance-protos \
Sources/SwiftProtobufPluginLibrary/PluginLibEditionDefaults.swift \
Tests/protoc-gen-swiftTests/DescriptorTestData.swift \
Tests/SwiftProtobufPluginLibraryTests/DescriptorTestData.swift \
Tests/SwiftProtobufPluginLibraryTests/PluginLibTestingEditionDefaults.swift
# Rebuild just the protos included in the runtime library
# NOTE: dependencies doesn't include the source .proto files, should fix that;
# would also need to list all the outputs.
regenerate-library-protos: build ${PROTOC_GEN_SWIFT}
find Sources/SwiftProtobuf -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
--tfiws_opt=FileNaming=DropPath \
--tfiws_opt=Visibility=Public \
--tfiws_out=Sources/SwiftProtobuf \
`find Protos/SwiftProtobuf -type f -name "*.proto"`
# Rebuild just the protos used by the plugin
# NOTE: dependencies doesn't include the source .proto files, should fix that;
# would also need to list all the outputs.
regenerate-plugin-protos: build ${PROTOC_GEN_SWIFT}
find Sources/SwiftProtobufPluginLibrary -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
-I Protos/SwiftProtobufPluginLibrary \
--tfiws_opt=FileNaming=DropPath \
--tfiws_opt=Visibility=Public \
--tfiws_out=Sources/SwiftProtobufPluginLibrary \
`find Protos/SwiftProtobufPluginLibrary -type f -name "*.proto"`
# Is this based on the upstream bazel rules `compile_edition_defaults` and
# `embed_edition_defaults`.
Sources/SwiftProtobufPluginLibrary/PluginLibEditionDefaults.swift: build ${PROTOC_GEN_SWIFT} Protos/SwiftProtobuf/google/protobuf/descriptor.proto
@${PROTOC} \
--edition_defaults_out=PluginLibEditionDefaults.bin \
--edition_defaults_minimum=PROTO2 \
--edition_defaults_maximum=2023 \
-I Protos/SwiftProtobuf \
Protos/SwiftProtobuf/google/protobuf/descriptor.proto
@rm -f $@
@echo '// See Makefile how this is generated.' >> $@
@echo '// swift-format-ignore-file' >> $@
@echo 'import Foundation' >> $@
@echo 'let bundledFeatureSetDefaultBytes: [UInt8] = [' >> $@
@xxd -i < PluginLibEditionDefaults.bin >> $@
@echo ']' >> $@
# Some defaults for the testing of custom features
Tests/SwiftProtobufPluginLibraryTests/PluginLibTestingEditionDefaults.swift: build ${PROTOC_GEN_SWIFT} Protos/SwiftProtobufPluginLibraryTests/test_features.proto
@${PROTOC} \
--edition_defaults_out=PluginLibTestingEditionDefaults.bin \
--edition_defaults_minimum=PROTO2 \
--edition_defaults_maximum=2023 \
-I Protos/SwiftProtobuf \
-I Protos/SwiftProtobufPluginLibraryTests \
Protos/SwiftProtobufPluginLibraryTests/test_features.proto
@rm -f $@
@echo '// See Makefile how this is generated.' >> $@
@echo '// swift-format-ignore-file' >> $@
@echo 'import Foundation' >> $@
@echo 'let testFeatureSetDefaultBytes: [UInt8] = [' >> $@
@xxd -i < PluginLibTestingEditionDefaults.bin >> $@
@echo ']' >> $@
# Rebuild just the protos used by the tests
# NOTE: dependencies doesn't include the source .proto files, should fix that;
# would also need to list all the outputs.
regenerate-test-protos: build ${PROTOC_GEN_SWIFT} Protos/SwiftProtobufTests/generated_swift_names_enums.proto Protos/SwiftProtobufTests/generated_swift_names_enum_cases.proto Protos/SwiftProtobufTests/generated_swift_names_fields.proto Protos/SwiftProtobufTests/generated_swift_names_messages.proto
find Tests/SwiftProtobufTests -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
-I Protos/SwiftProtobufTests \
--tfiws_opt=FileNaming=DropPath \
--tfiws_out=Tests/SwiftProtobufTests \
`find Protos/SwiftProtobufTests -type f -name "*.proto"`
find Tests/SwiftProtobufPluginLibraryTests -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
-I Protos/SwiftProtobuf \
-I Protos/SwiftProtobufPluginLibrary \
-I Protos/SwiftProtobufPluginLibraryTests \
--tfiws_opt=FileNaming=DropPath \
--tfiws_out=Tests/SwiftProtobufPluginLibraryTests \
`find Protos/SwiftProtobufPluginLibraryTests -type f -name "*.proto"`
# Rebuild the protos for FuzzTesting/Sources/FuzzCommon, the file lives in the
# Protos/SwiftProtobufTests to have just one copy.
regenerate-fuzz-protos: build ${PROTOC_GEN_SWIFT}
find FuzzTesting/Sources/FuzzCommon -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
-I Protos/SwiftProtobufTests \
--tfiws_opt=FileNaming=DropPath \
--tfiws_opt=Visibility=Public \
--tfiws_out=FuzzTesting/Sources/FuzzCommon \
Protos/SwiftProtobufTests/fuzz_testing.proto
SWIFT_PLUGINLIB_DESCRIPTOR_TEST_PROTOS= \
Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_test.proto \
Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_test2.proto \
Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_test_import.proto \
Protos/SwiftProtobufPluginLibraryTests/pluginlib_descriptor_delimited.proto \
Protos/SwiftProtobufPluginLibraryTests/unittest_delimited.proto \
Protos/SwiftProtobufPluginLibraryTests/unittest_delimited_import.proto \
Protos/SwiftProtobufPluginLibrary/swift_protobuf_module_mappings.proto
Tests/SwiftProtobufPluginLibraryTests/DescriptorTestData.swift: build ${PROTOC_GEN_SWIFT} ${SWIFT_PLUGINLIB_DESCRIPTOR_TEST_PROTOS}
@${PROTOC} \
--include_imports \
--include_source_info \
--descriptor_set_out=PluginLibDescriptorTestData.bin \
-I Protos/SwiftProtobuf \
-I Protos/SwiftProtobufPluginLibrary \
-I Protos/SwiftProtobufPluginLibraryTests \
${SWIFT_PLUGINLIB_DESCRIPTOR_TEST_PROTOS}
@rm -f $@
@echo '// See Makefile how this is generated.' >> $@
@echo '// swift-format-ignore-file' >> $@
@echo 'import Foundation' >> $@
@echo 'let fileDescriptorSetBytes: [UInt8] = [' >> $@
@xxd -i < PluginLibDescriptorTestData.bin >> $@
@echo ']' >> $@
SWIFT_PLUGIN_DESCRIPTOR_TEST_PROTOS= \
Protos/protoc-gen-swiftTests/plugin_descriptor_test.proto
Tests/protoc-gen-swiftTests/DescriptorTestData.swift: build ${PROTOC_GEN_SWIFT} ${SWIFT_PLUGIN_DESCRIPTOR_TEST_PROTOS}
@${PROTOC} \
--include_imports \
--descriptor_set_out=PluginDescriptorTestData.bin \
-I Protos/protoc-gen-swiftTests \
${SWIFT_PLUGIN_DESCRIPTOR_TEST_PROTOS}
@rm -f $@
@echo '// See Makefile how this is generated.' >> $@
@echo '// swift-format-ignore-file' >> $@
@echo 'import Foundation' >> $@
@echo 'let fileDescriptorSetBytes: [UInt8] = [' >> $@
@xxd -i < PluginDescriptorTestData.bin >> $@
@echo ']' >> $@
#
# Collect a list of words that appear in the SwiftProtobuf library
# source. These are words that may cause problems for generated code.
#
# The logic here builds a word list as follows:
# = Look at every Swift source file in the library
# = Take every line with the word 'public', 'func', or 'var'
# = Remove any comments from the line.
# = Break each such line into words (stripping all punctuation)
# = Remove words that differ only in case
# = Remove anything that will cause proto parsing issues (things named "reserved")
#
# Selecting lines with 'public', 'func' or 'var' ensures we get every
# public protocol, struct, enum, or class name, as well as every
# method or property defined in a public protocol, struct, or class.
# It also gives us a large collection of Swift names.
Protos/mined_words.txt: Sources/SwiftProtobuf/*.swift
@echo Building $@
@cat $^ | \
grep -E '\b(public|func|var)\b' | \
grep -vE '\b(private|internal|fileprivate)\b' | \
sed -e 's|//.*$$||g' | \
sed -e 's/[^a-zA-Z0-9_]/ /g' | \
tr " " "\n" | \
sed -e 's/^_//' | \
sort -uf | \
grep -vE '(reserved)' | \
grep '^[a-zA-Z_]' > $@
# Build some proto files full of landmines
#
# This takes the word list Protos/mined_words.txt and uses
# it to build several proto files:
# = Build a message with one `int32` field for each word
# = Build an enum with a case for each such word
# = Build a message with a submessage named with each word
# = Build a message with an enum named with each word
#
# If the Swift compiler can actually compile the result, that suggests
# we can correctly handle every symbol in the library itself that
# might cause problems. Failures compiling this indicate weaknesses
# in protoc-gen-swift's name sanitization logic.
#
Protos/SwiftProtobufTests/generated_swift_names_fields.proto: Protos/mined_words.txt
@echo Building $@
@rm $@
@echo '// See Makefile for the logic that generates this' >> $@
@echo '// Protoc errors imply this file is being generated incorrectly' >> $@
@echo '// Swift compile errors are probably bugs in protoc-gen-swift' >> $@
@echo 'syntax = "proto3";' >> $@
@echo 'package swift_proto_testing.generated;' >> $@
@echo 'message GeneratedSwiftReservedFields {' >> $@
@cat Protos/mined_words.txt | awk 'BEGIN{n = 1} {print " int32 " $$1 " = " n ";"; n += 1 }' >> $@
@echo '}' >> $@
Protos/SwiftProtobufTests/generated_swift_names_enum_cases.proto: Protos/mined_words.txt
@echo Building $@
@rm $@
@echo '// See Makefile for the logic that generates this' >> $@
@echo '// Protoc errors imply this file is being generated incorrectly' >> $@
@echo '// Swift compile errors are probably bugs in protoc-gen-swift' >> $@
@echo 'syntax = "proto3";' >> $@
@echo 'package swift_proto_testing.generated;' >> $@
@echo 'enum GeneratedSwiftReservedEnum {' >> $@
@echo ' NONE = 0;' >> $@
@cat Protos/mined_words.txt | awk 'BEGIN{n = 1} {print " " $$1 " = " n ";"; n += 1 }' >> $@
@echo '}' >> $@
Protos/SwiftProtobufTests/generated_swift_names_messages.proto: Protos/mined_words.txt
@echo Building $@
@rm $@
@echo '// See Makefile for the logic that generates this' >> $@
@echo '// Protoc errors imply this file is being generated incorrectly' >> $@
@echo '// Swift compile errors are probably bugs in protoc-gen-swift' >> $@
@echo 'syntax = "proto3";' >> $@
@echo 'package swift_proto_testing.generated;' >> $@
@echo 'message GeneratedSwiftReservedMessages {' >> $@
@cat Protos/mined_words.txt | awk '{print " message " $$1 " { int32 " $$1 " = 1; }"}' >> $@
@echo '}' >> $@
Protos/SwiftProtobufTests/generated_swift_names_enums.proto: Protos/mined_words.txt
@echo Building $@
@rm $@
@echo '// See Makefile for the logic that generates this' >> $@
@echo '// Protoc errors imply this file is being generated incorrectly' >> $@
@echo '// Swift compile errors are probably bugs in protoc-gen-swift' >> $@
@echo 'syntax = "proto3";' >> $@
@echo 'package swift_proto_testing.generated;' >> $@
@echo 'message GeneratedSwiftReservedEnums {' >> $@
@cat Protos/mined_words.txt | awk '{print " enum " $$1 " { NONE_" $$1 " = 0; }"}' >> $@
@echo '}' >> $@
# Rebuild just the protos used by the conformance test runner.
regenerate-conformance-protos: build ${PROTOC_GEN_SWIFT}
find Sources/Conformance -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
-I Protos/Conformance \
--tfiws_opt=FileNaming=DropPath \
--tfiws_out=Sources/Conformance \
`find Protos/Conformance -type f -name "*.proto"`
# Rebuild just the protos used by the CompileTests.
regenerate-compiletests-protos: \
regenerate-compiletests-multimodule-protos \
copy-compiletests-internalimportsbydefault-protos
# Update the CompileTests/MultiModule files.
# NOTE: Any changes here must also be done on the "test-plugin" target so it
# generates in the same way.
regenerate-compiletests-multimodule-protos: build ${PROTOC_GEN_SWIFT}
find CompileTests/MultiModule -name "*.pb.swift" -exec rm -f {} \;
${GENERATE_SRCS} \
-I Protos/CompileTests/MultiModule \
--tfiws_opt=Visibility=Public \
--tfiws_opt=ProtoPathModuleMappings=Protos/CompileTests/MultiModule/module_mappings.pbascii \
--tfiws_out=CompileTests/MultiModule \
`(find Protos/CompileTests/MultiModule -type f -name "*.proto")`
# We use the plugin for the InternalImportsByDefault test, so we don't actually need to regenerate
# anything. However, to keep the protos centralised in a single place (the Protos directory),
# this simply copies those files to the InternalImportsByDefault package in case they change.
copy-compiletests-internalimportsbydefault-protos:
@cp Protos/CompileTests/InternalImportsByDefault/* CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/Protos
# Helper to check if there is a protobuf checkout as expected.
check-for-protobuf-checkout:
@if [ ! -d "${GOOGLE_PROTOBUF_CHECKOUT}/src/google/protobuf" ]; then \
echo "ERROR: ${GOOGLE_PROTOBUF_CHECKOUT} does not appear to be a checkout of"; \
echo "ERROR: github.com/protocolbuffers/protobuf. Please check it out or set"; \
echo "ERROR: GOOGLE_PROTOBUF_CHECKOUT to point to a checkout."; \
exit 1; \
fi
#
# Helper to update the .proto files copied from the protocolbuffers/protobuf distro.
#
update-proto-files: check-for-protobuf-checkout
@rm -rf Protos/upstream
@mkdir -p \
Protos/upstream/conformance/test_protos \
Protos/upstream/google/protobuf/compiler \
Protos/upstream/editions/golden
@cp -v "${GOOGLE_PROTOBUF_CHECKOUT}"/conformance/*.proto Protos/upstream/conformance/
@cp -v "${GOOGLE_PROTOBUF_CHECKOUT}"/conformance/test_protos/*.proto Protos/upstream/conformance/test_protos/
@cp -v "${GOOGLE_PROTOBUF_CHECKOUT}"/src/google/protobuf/*.proto Protos/upstream/google/protobuf/
@cp -v "${GOOGLE_PROTOBUF_CHECKOUT}"/src/google/protobuf/compiler/*.proto Protos/upstream/google/protobuf/compiler/
@cp -v "${GOOGLE_PROTOBUF_CHECKOUT}"/editions/golden/test_messages_proto?_editions.proto Protos/upstream/editions/golden/
# Now copy into the Proto directories for the local targets.
@rm -rf Protos/Conformance/conformance/test_protos && mkdir -p Protos/Conformance/conformance/test_protos
@cp -v Protos/upstream/conformance/*.proto Protos/Conformance/conformance
@cp -v Protos/upstream/conformance/test_protos/*.proto Protos/Conformance/conformance/test_protos
@rm -rf Protos/Conformance/google && mkdir -p Protos/Conformance/google/protobuf Protos/Conformance/editions
@cp -v \
Protos/upstream/google/protobuf/test_messages_proto2.proto \
Protos/upstream/google/protobuf/test_messages_proto3.proto \
Protos/Conformance/google/protobuf/
@cp -v \
Protos/upstream/editions/golden/test_messages_proto2_editions.proto \
Protos/upstream/editions/golden/test_messages_proto3_editions.proto \
Protos/Conformance/editions/
@rm -rf Protos/SwiftProtobuf/google && mkdir -p Protos/SwiftProtobuf/google/protobuf
@cp -v \
Protos/upstream/google/protobuf/timestamp.proto \
Protos/upstream/google/protobuf/field_mask.proto \
Protos/upstream/google/protobuf/api.proto \
Protos/upstream/google/protobuf/duration.proto \
Protos/upstream/google/protobuf/struct.proto \
Protos/upstream/google/protobuf/wrappers.proto \
Protos/upstream/google/protobuf/source_context.proto \
Protos/upstream/google/protobuf/any.proto \
Protos/upstream/google/protobuf/type.proto \
Protos/upstream/google/protobuf/empty.proto \
Protos/upstream/google/protobuf/descriptor.proto \
Protos/SwiftProtobuf/google/protobuf
@rm -rf Protos/SwiftProtobufPluginLibrary/google && mkdir -p Protos/SwiftProtobufPluginLibrary/google/protobuf/compiler
@cp -v Protos/upstream/google/protobuf/compiler/*.proto Protos/SwiftProtobufPluginLibrary/google/protobuf/compiler
#
# Helper to see if update-proto-files should be done
#
check-proto-files: check-for-protobuf-checkout
@for p in `cd ${GOOGLE_PROTOBUF_CHECKOUT} && ls conformance/*.proto conformance/test_protos/*.proto`; do \
diff -u "Protos/upstream/$$p" "${GOOGLE_PROTOBUF_CHECKOUT}/$$p" \
|| (echo "ERROR: Time to do a 'make update-proto-files'" && exit 1); \
done
@for p in `cd ${GOOGLE_PROTOBUF_CHECKOUT}/src && ls google/protobuf/*.proto | grep -v test`; do \
diff -u "Protos/upstream/$$p" "${GOOGLE_PROTOBUF_CHECKOUT}/src/$$p" \
|| (echo "ERROR: Time to do a 'make update-proto-files'" && exit 1); \
done
@for p in `cd ${GOOGLE_PROTOBUF_CHECKOUT}/src && ls google/protobuf/compiler/*.proto`; do \
diff -u "Protos/upstream/$$p" "${GOOGLE_PROTOBUF_CHECKOUT}/src/$$p" \
|| (echo "ERROR: Time to do a 'make update-proto-files'" && exit 1); \
done
# Runs the conformance tests.
test-conformance: build check-for-protobuf-checkout Sources/Conformance/failure_list_swift.txt Sources/Conformance/text_format_failure_list_swift.txt
$(CONFORMANCE_TEST_RUNNER) \
--enforce_recommended \
--failure_list Sources/Conformance/failure_list_swift.txt \
--text_format_failure_list Sources/Conformance/text_format_failure_list_swift.txt \
--maximum_edition 2023 \
$(SWIFT_CONFORMANCE_PLUGIN)
# Validate the CocoaPods podspec file against the current tree state.
pod-lib-lint:
@if [ `uname -s` = "Darwin" ] ; then \
pod lib lint SwiftProtobuf.podspec ; \
fi