Skip to content

Commit 85b5bcf

Browse files
committed
Add thrift/annotation/*.thrift
1 parent 051a293 commit 85b5bcf

18 files changed

Lines changed: 2588 additions & 46 deletions

Makefile

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,92 +28,96 @@ thrift:: thrift-cpp thrift-hs
2828

2929
thrift-hs:: compiler
3030
( \
31-
THRIFT_COMPILE=$$($(CABAL) -v0 list-bin exe:thrift-compiler); \
31+
THRIFT_COMPILE=$$($(CABAL) -v0 list-bin exe:thrift-compiler) && \
3232
(cd lib && $${THRIFT_COMPILE} --hs \
33-
if/RpcOptions.thrift); \
33+
if/RpcOptions.thrift) && \
3434
(cd lib && $${THRIFT_COMPILE} --hs \
35-
if/ApplicationException.thrift); \
35+
if/ApplicationException.thrift) && \
3636
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
3737
test/if/math.thrift \
38-
-o test); \
39-
mkdir -p cpp-channel/test/if; \
38+
-o test) && \
39+
mkdir -p cpp-channel/test/if && \
4040
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
4141
test/if/math.thrift \
42-
-o ../cpp-channel/test/if); \
42+
-o ../cpp-channel/test/if) && \
4343
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
4444
test/if/math.thrift \
45-
-o ../server/test); \
45+
-o ../server/test) && \
4646
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
4747
test/if/math.thrift \
48-
-o ../http/test); \
48+
-o ../http/test) && \
4949
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
5050
test/if/echoer.thrift \
51-
-o test); \
51+
-o test) && \
5252
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
5353
test/if/echoer.thrift \
54-
-o ../server/test); \
54+
-o ../server/test) && \
5555
(cd lib && $${THRIFT_COMPILE} --hs --use-int \
5656
test/if/echoer.thrift \
57-
-o ../http/test); \
57+
-o ../http/test) && \
5858
(cd server && $${THRIFT_COMPILE} --hs \
5959
test/if/hash_map.thrift \
60-
-o test); \
60+
-o test) && \
6161
(cd tests && $${THRIFT_COMPILE} --hs \
62-
if/hs_prefix.thrift); \
62+
thrift/annotation/thrift.thrift) && \
6363
(cd tests && $${THRIFT_COMPILE} --hs \
64-
if/foo.thrift); \
64+
thrift/annotation/scope.thrift) && \
6565
(cd tests && $${THRIFT_COMPILE} --hs \
66-
if/constants.thrift); \
66+
if/hs_prefix.thrift) && \
67+
(cd tests && $${THRIFT_COMPILE} --hs \
68+
if/foo.thrift) && \
69+
(cd tests && $${THRIFT_COMPILE} --hs \
70+
if/constants.thrift) && \
6771
(cd tests && $${THRIFT_COMPILE} --hs \
6872
--duplicate-names \
69-
if/duplicate.thrift); \
73+
if/duplicate.thrift) && \
7074
(cd tests && $${THRIFT_COMPILE} --hs \
71-
if/EnumConst.thrift); \
75+
if/EnumConst.thrift) && \
7276
(cd tests && $${THRIFT_COMPILE} --hs \
73-
if/enum.thrift); \
77+
if/enum.thrift) && \
7478
(cd tests && $${THRIFT_COMPILE} --hs \
75-
if/exception.thrift); \
79+
if/exception.thrift) && \
7680
(cd tests && $${THRIFT_COMPILE} --hs \
7781
--use-int --use-hash-map --use-hash-set \
78-
if/flags.thrift); \
82+
if/flags.thrift) && \
7983
(cd tests && $${THRIFT_COMPILE} --hs \
8084
--extra-hasfields \
81-
if/hasfield.thrift); \
85+
if/hasfield.thrift) && \
8286
(cd tests && $${THRIFT_COMPILE} --hs \
83-
if/A.thrift); \
87+
if/A.thrift) && \
8488
(cd tests && $${THRIFT_COMPILE} --hs \
85-
if/B.thrift); \
89+
if/B.thrift) && \
8690
(cd tests && $${THRIFT_COMPILE} --hs \
87-
if/C.thrift); \
91+
if/C.thrift) && \
8892
(cd tests && $${THRIFT_COMPILE} --hs \
89-
if/D.thrift); \
93+
if/D.thrift) && \
9094
(cd tests && $${THRIFT_COMPILE} --hs \
91-
if/E.thrift); \
95+
if/E.thrift) && \
9296
(cd tests && $${THRIFT_COMPILE} --hs \
93-
if/versions.thrift); \
97+
if/versions.thrift) && \
9498
(cd tests && $${THRIFT_COMPILE} --hs \
95-
if/monoid.thrift); \
99+
if/monoid.thrift) && \
96100
(cd tests && $${THRIFT_COMPILE} --hs \
97-
if/hs_test.thrift); \
101+
if/hs_test.thrift) && \
98102
(cd tests && $${THRIFT_COMPILE} --hs \
99-
if/hs_test.thrift -o ../lib/test); \
103+
if/hs_test.thrift -o ../lib/test) && \
100104
(cd tests && $${THRIFT_COMPILE} --hs \
101-
if/map.thrift); \
105+
if/map.thrift) && \
102106
(cd tests && $${THRIFT_COMPILE} --hs \
103-
if/messed_up_case.thrift); \
107+
if/messed_up_case.thrift) && \
104108
(cd tests && $${THRIFT_COMPILE} --hs \
105-
if/namespace.thrift); \
109+
if/namespace.thrift) && \
106110
(cd tests && $${THRIFT_COMPILE} --hs \
107-
if/namespace_included.thrift); \
111+
if/namespace_included.thrift) && \
108112
(cd tests && $${THRIFT_COMPILE} --hs \
109-
if/parens.thrift); \
113+
if/parens.thrift) && \
110114
(cd tests && $${THRIFT_COMPILE} --hs \
111115
--required-symbols "A,B,C,X,weNeedThis" \
112-
if/huge.thrift); \
116+
if/huge.thrift) && \
113117
(cd tests && $${THRIFT_COMPILE} --hs \
114-
if/scoped_enums.thrift); \
118+
if/scoped_enums.thrift) && \
115119
(cd tests && $${THRIFT_COMPILE} --hs \
116-
if/service.thrift); \
120+
if/service.thrift) \
117121
)
118122
# those files are required for thrift-compiler's tests
119123
mkdir -p compiler/tests/if

compiler/thrift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../thrift

compiler/thrift-compiler.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extra-source-files: test/fixtures/**/*.ast,
1919
test/fixtures/gen-hs2/**/*.hs,
2020
test/if/*.thrift,
2121
tests/if/*.thrift,
22-
tests/if/*.hs
22+
tests/if/*.hs,
23+
thrift/**/*.thrift
2324

2425
description:
2526
A compiler from the Thrift Interface Definition Language (IDL) to Haskell.

tests/thrift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../thrift

tests/thrift-tests.cabal

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ extra-source-files: cpp/*.h, cpp/*.cpp,
1818
if/*.thrift,
1919
if/gen-cpp2/*.h,
2020
if/gen-cpp2/*.cpp,
21-
if/gen-cpp2/*.tcc
21+
if/gen-cpp2/*.tcc,
22+
thrift/**/*.thrift
2223

2324
description:
2425
Tests for Haskell Thrift.
@@ -109,25 +110,37 @@ test-suite binary-protocol
109110
import: fb-haskell, test-common
110111
type: exitcode-stdio-1.0
111112
main-is: BinaryProtocolTest.hs
112-
other-modules: Foo.Types
113+
other-modules:
114+
Foo.Types,
115+
Facebook.Thrift.Annotation.Thrift.Thrift.Types,
116+
Scope.Types
113117
ghc-options: -main-is BinaryProtocolTest
114118
test-suite const-gen
115119
import: fb-haskell, test-common
116120
type: exitcode-stdio-1.0
117121
main-is: ConstGenTest.hs
118-
other-modules: Constants.Types
122+
other-modules:
123+
Constants.Types,
124+
Facebook.Thrift.Annotation.Thrift.Thrift.Types,
125+
Scope.Types
119126
ghc-options: -main-is ConstGenTest
120127
test-suite const-parser
121128
import: fb-haskell, test-common
122129
type: exitcode-stdio-1.0
123130
main-is: ConstParserTest.hs
124-
other-modules: Constants.Types
131+
other-modules:
132+
Constants.Types,
133+
Facebook.Thrift.Annotation.Thrift.Thrift.Types,
134+
Scope.Types
125135
ghc-options: -main-is ConstParserTest
126136
test-suite const
127137
import: fb-haskell, test-common
128138
type: exitcode-stdio-1.0
129139
main-is: ConstTest.hs
130-
other-modules: Constants.Types, Foo.Types
140+
other-modules:
141+
Constants.Types, Foo.Types,
142+
Facebook.Thrift.Annotation.Thrift.Thrift.Types,
143+
Scope.Types
131144
ghc-options: -main-is ConstTest
132145
test-suite duplicate-names
133146
import: fb-haskell, test-common
@@ -215,7 +228,10 @@ test-suite json
215228
import: fb-haskell, test-common
216229
type: exitcode-stdio-1.0
217230
main-is: JSONTest.hs
218-
other-modules: Foo.Types
231+
other-modules:
232+
Foo.Types,
233+
Facebook.Thrift.Annotation.Thrift.Thrift.Types,
234+
Scope.Types
219235
ghc-options: -main-is JSONTest
220236
test-suite lexer
221237
import: fb-haskell, test-common
@@ -227,7 +243,10 @@ test-suite map
227243
import: fb-haskell, test-common
228244
type: exitcode-stdio-1.0
229245
main-is: MapTest.hs
230-
other-modules: Map.Types
246+
other-modules:
247+
Map.Types,
248+
Facebook.Thrift.Annotation.Thrift.Thrift.Types,
249+
Scope.Types
231250
ghc-options: -main-is MapTest
232251
test-suite message
233252
import: fb-haskell, fb-cpp, test-common

thrift/annotation/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
add_library(thriftannotation)
16+
target_link_libraries(thriftannotation PUBLIC Folly::folly)
17+
18+
foreach (name cpp hack java python go scope thrift)
19+
thrift_generate(
20+
${name} # file_name
21+
"" # services
22+
"cpp2" # language
23+
"templates,no_metadata" # options
24+
"${CMAKE_CURRENT_SOURCE_DIR}" # file_path
25+
"${CMAKE_CURRENT_BINARY_DIR}" # output_path
26+
"thrift/annotation" # include_prefix
27+
THRIFT_INCLUDE_DIRECTORIES ${THRIFT_SOURCE_DIR})
28+
target_sources(thriftannotation PRIVATE ${${name}-cpp2-SOURCES})
29+
endforeach ()
30+
31+
install(TARGETS thriftannotation EXPORT fbthrift-exports
32+
DESTINATION ${LIB_INSTALL_DIR})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <map>
18+
#include <string>
19+
20+
namespace apache::thrift::detail {
21+
22+
const std::map<std::string, std::string>& bundled_annotation_files();
23+
24+
} // namespace apache::thrift::detail

thrift/annotation/compat.thrift

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
include "thrift/annotation/scope.thrift"
18+
19+
package "facebook.com/thrift/annotation"
20+
21+
namespace java com.facebook.thrift.annotation_deprecated
22+
namespace android com.facebook.thrift.annotation_deprecated
23+
namespace py.asyncio facebook_thrift_asyncio.annotation.compat
24+
namespace go thrift.annotation.compat
25+
namespace py thrift.annotation.compat
26+
27+
/**
28+
* Enumeration for coding error actions.
29+
* Used for handling malformed UTF-8 bytes.
30+
*/
31+
enum CodingErrorAction {
32+
/**
33+
* Default behavior of the languages.
34+
* Pythons default is report, java is replacing malformed
35+
* bytes, cpp skips validation and ignores malformed bytes.
36+
*/
37+
Legacy = 0,
38+
/**
39+
* A decode error is thrown when the bytes are malformed.
40+
* Default behavior in Thrift v1.
41+
*/
42+
Report = 1,
43+
}
44+
45+
/**
46+
* Enables compatibility on string and binary types. When target data
47+
* type is string, UTF-8 byte sequence is validated. If it is invalid,
48+
* one of the CodingErrorAction is taken.
49+
*/
50+
@scope.Program
51+
@scope.Structured
52+
@scope.Field
53+
@scope.Typedef
54+
struct Strings {
55+
1: CodingErrorAction onInvalidUtf8;
56+
}
57+
58+
@Strings{onInvalidUtf8 = CodingErrorAction.Report}
59+
@scope.Transitive
60+
struct Utf8 {}
61+
62+
@Strings{onInvalidUtf8 = CodingErrorAction.Legacy}
63+
@scope.Transitive
64+
struct LegacyString {}
65+
66+
/**
67+
* Enumeration for enum types.
68+
*/
69+
enum EnumType {
70+
/**
71+
* Default enum type of the languages in Thrift v0.
72+
* C++ default is open, Java is closed.
73+
*/
74+
Legacy = 0,
75+
/**
76+
* Enum is defined as open enum type.
77+
* A new enum value UNRECOGNIZED is added to the enum for the values outside the defined range.
78+
* Unrecognized values are stored as its underlying integer value and can be retrieved.
79+
* Default behavior in Thrift v1.
80+
*/
81+
Open = 1,
82+
}
83+
84+
/**
85+
* Enables compatibility on enums.
86+
*/
87+
@scope.Program
88+
@scope.Enum
89+
struct Enums {
90+
1: EnumType type;
91+
}

0 commit comments

Comments
 (0)