Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ xcbaselines
/docs
/build
mined_words.txt
/DescriptorTestData.bin
/*DescriptorTestData.bin
/Package.resolved

# Intermediate conformance test outputs
Expand Down
40 changes: 33 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ CONFORMANCE_PROTOS= \
Protos/google/protobuf/test_messages_proto2.proto \
Protos/google/protobuf/test_messages_proto3.proto

SWIFT_DESCRIPTOR_TEST_PROTOS= \
SWIFT_PLUGINLIB_DESCRIPTOR_TEST_PROTOS= \
Protos/pluginlib_descriptor_test.proto \
Protos/pluginlib_descriptor_test2.proto \
${PLUGIN_PROTOS}

SWIFT_PLUGIN_DESCRIPTOR_TEST_PROTOS= \
Protos/plugin_descriptor_test.proto

.PHONY: \
all \
build \
Expand Down Expand Up @@ -200,8 +203,13 @@ all: build

# This generates a LinuxMain.swift to include all of the test cases.
# It is needed for all builds before 5.4.x
# NOTE: This doesn't include Tests/protoc-gen-swiftTests because the older
# SwiftPM versions could have a test depend on an executable target.
generate-linux-main:
@${AWK} -f DevTools/CollectTests.awk Tests/*/Test_*.swift > Tests/LinuxMain.swift.new
@${AWK} -f DevTools/CollectTests.awk \
Tests/SwiftProtobufPluginLibraryTests/Test_*.swift \
Tests/SwiftProtobufTests/Test_*.swift \
> Tests/LinuxMain.swift.new
@if ! cmp -s Tests/LinuxMain.swift.new Tests/LinuxMain.swift; then \
cp Tests/LinuxMain.swift.new Tests/LinuxMain.swift; \
echo "FYI: Tests/LinuxMain.swift Updated"; \
Expand All @@ -222,7 +230,7 @@ install: build

clean:
swift package clean
rm -rf .build _test ${PROTOC_GEN_SWIFT} DescriptorTestData.bin \
rm -rf .build _test ${PROTOC_GEN_SWIFT} *DescriptorTestData.bin \
Performance/_generated Performance/_results Protos/mined_words.txt \
docs build
find . -name '*~' | xargs rm -f
Expand Down Expand Up @@ -313,6 +321,7 @@ regenerate: \
regenerate-plugin-protos \
regenerate-test-protos \
regenerate-conformance-protos \
Tests/protoc-gen-swiftTests/DescriptorTestData.swift \
Tests/SwiftProtobufPluginLibraryTests/DescriptorTestData.swift

# Rebuild just the protos included in the runtime library
Expand Down Expand Up @@ -353,20 +362,37 @@ regenerate-fuzz-protos: build ${PROTOC_GEN_SWIFT}
--tfiws_out=FuzzTesting/Sources/FuzzCommon \
Protos/fuzz_testing.proto

Tests/SwiftProtobufPluginLibraryTests/DescriptorTestData.swift: build ${PROTOC_GEN_SWIFT} ${SWIFT_DESCRIPTOR_TEST_PROTOS}
Tests/SwiftProtobufPluginLibraryTests/DescriptorTestData.swift: build ${PROTOC_GEN_SWIFT} ${SWIFT_PLUGINLIB_DESCRIPTOR_TEST_PROTOS}
# Until the flag isn't needed, add the flag to enable proto3 optional.
@${PROTOC} \
--experimental_allow_proto3_optional \
--include_imports \
--descriptor_set_out=PluginLibDescriptorTestData.bin \
-I Protos \
${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 ']' >> $@
@echo 'let fileDescriptorSetData = Data(fileDescriptorSetBytes)' >> $@

Tests/protoc-gen-swiftTests/DescriptorTestData.swift: build ${PROTOC_GEN_SWIFT} ${SWIFT_PLUGIN_DESCRIPTOR_TEST_PROTOS}
# Until the flag isn't needed, add the flag to enable proto3 optional.
@${PROTOC} \
--experimental_allow_proto3_optional \
--include_imports \
--descriptor_set_out=DescriptorTestData.bin \
--descriptor_set_out=PluginDescriptorTestData.bin \
-I Protos \
${SWIFT_DESCRIPTOR_TEST_PROTOS}
${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 < DescriptorTestData.bin >> $@
@xxd -i < PluginDescriptorTestData.bin >> $@
@echo ']' >> $@
@echo 'let fileDescriptorSetData = Data(fileDescriptorSetBytes)' >> $@

Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ let package = Package(
name: "SwiftProtobufPluginLibraryTests",
dependencies: ["SwiftProtobufPluginLibrary"]
),
.testTarget(
name: "protoc-gen-swiftTests",
dependencies: ["protoc-gen-swift"]
),
],
swiftLanguageVersions: [.v5]
)
63 changes: 63 additions & 0 deletions Protos/plugin_descriptor_test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Protos/pluginlib_descriptor_test.proto - test proto
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
// -----------------------------------------------------------------------------
///
/// Test proto for Tests/SwiftProtobufPluginLibraryTests/Test_Descriptor.swift
///
// -----------------------------------------------------------------------------

syntax = "proto2";

package swift_descriptor_test;

// To check handling of extension ranges that are out of order.
message MsgExtensionRangeOrdering {
extensions 1, 3, 2, 4;
extensions 7;
reserved 8;
extensions 9;

extensions 100 to 110;
reserved 121 to 125;
extensions 126 to 130;
extensions 111 to 120;
}

// To check handling of extension ranges that are out of order, have fields or
// reserved things mix through them.
message MsgExtensionRangeOrderingWithFields {
extensions 1, 3, 2, 4;
optional int32 field6 = 6;
extensions 7;
reserved 8;
extensions 9;

extensions 100 to 110;
reserved 121 to 123;
optional int32 field124 = 124;
optional int32 field125 = 125;
extensions 126 to 130;
extensions 111 to 120;
optional int32 field200 = 200;
}

// Intermixed ranges and fields so help ensure no merge issues
message MsgExtensionRangeOrderingNoMerging {
optional int32 field1 = 1;
optional int32 field2 = 2;
extensions 3 to 5;
optional int32 field6 = 6;
extensions 7 to 12;
optional int32 field13 = 13;
optional int32 field15 = 15;
extensions 16 to 20;
optional int32 field21 = 21;
}
44 changes: 0 additions & 44 deletions Protos/pluginlib_descriptor_test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,47 +106,3 @@ message Proto2MessageForPresence {
}

}

// To check handling of extension ranges that are out of order.
message MsgExtensionRangeOrdering {
extensions 1, 3, 2, 4;
extensions 7;
reserved 8;
extensions 9;

extensions 100 to 110;
reserved 121 to 125;
extensions 126 to 130;
extensions 111 to 120;
}

// To check handling of extension ranges that are out of order, have fields or
// reserved things mix through them.
message MsgExtensionRangeOrderingWithFields {
extensions 1, 3, 2, 4;
optional int32 field6 = 6;
extensions 7;
reserved 8;
extensions 9;

extensions 100 to 110;
reserved 121 to 123;
optional int32 field124 = 124;
optional int32 field125 = 125;
extensions 126 to 130;
extensions 111 to 120;
optional int32 field200 = 200;
}

// Intermixed ranges and fields so help ensure no merge issues
message MsgExtensionRangeOrderingNoMerging {
optional int32 field1 = 1;
optional int32 field2 = 2;
extensions 3 to 5;
optional int32 field6 = 6;
extensions 7 to 12;
optional int32 field13 = 13;
optional int32 field15 = 15;
extensions 16 to 20;
optional int32 field21 = 21;
}
Loading