diff --git a/thrift/compiler/generate/t_mstch_cpp2_generator.cc b/thrift/compiler/generate/t_mstch_cpp2_generator.cc index f65cbaae59e..846c3f47452 100644 --- a/thrift/compiler/generate/t_mstch_cpp2_generator.cc +++ b/thrift/compiler/generate/t_mstch_cpp2_generator.cc @@ -774,7 +774,18 @@ class cpp_mstch_program : public mstch_program { // If you don't have a schema const you don't need schema includes. ::apache::thrift::compiler::has_schema(sm_, *program_) && // Opting out of schema const should disable all of its failure modes. - !program->find_structured_annotation_or_null(kDisableSchemaConstUri); + !program->find_structured_annotation_or_null( + kDisableSchemaConstUri) && + // File-relative includes break schema const naming, + // so exclude programs with includes that don't contain a path + // separator. + std::all_of( + program->includes().begin(), + program->includes().end(), + [](const t_include* inc) { + auto path = inc->raw_path(); + return std::find(path.begin(), path.end(), '/') != path.end(); + }); return std::make_unique(static_cast(ret)); }); return static_cast(supports); diff --git a/thrift/compiler/test/fixtures/service-schema/out/cpp2/gen-cpp2/module_constants.cpp b/thrift/compiler/test/fixtures/service-schema/out/cpp2/gen-cpp2/module_constants.cpp index cf9c815164c..75603bfd19f 100644 --- a/thrift/compiler/test/fixtures/service-schema/out/cpp2/gen-cpp2/module_constants.cpp +++ b/thrift/compiler/test/fixtures/service-schema/out/cpp2/gen-cpp2/module_constants.cpp @@ -21,11 +21,7 @@ ::std::string_view _fbthrift_schema_b747839c13cb3aa5() { ::folly::Range _fbthrift_schema_b747839c13cb3aa5_includes() { - static const ::std::array<::std::string_view, 2> includes = { - _fbthrift_schema_b747839c13cb3aa5(), - ::apache::thrift::detail::mc::readSchema(::cpp2::include_constants::_fbthrift_schema_8569dfae849b43aa), - }; - return ::folly::range(includes); + return {}; } } // namespace module_constants diff --git a/thrift/compiler/test/fixtures/service-schema/out/cpp2_sinit/gen-cpp2/module_constants.cpp b/thrift/compiler/test/fixtures/service-schema/out/cpp2_sinit/gen-cpp2/module_constants.cpp index cf9c815164c..75603bfd19f 100644 --- a/thrift/compiler/test/fixtures/service-schema/out/cpp2_sinit/gen-cpp2/module_constants.cpp +++ b/thrift/compiler/test/fixtures/service-schema/out/cpp2_sinit/gen-cpp2/module_constants.cpp @@ -21,11 +21,7 @@ ::std::string_view _fbthrift_schema_b747839c13cb3aa5() { ::folly::Range _fbthrift_schema_b747839c13cb3aa5_includes() { - static const ::std::array<::std::string_view, 2> includes = { - _fbthrift_schema_b747839c13cb3aa5(), - ::apache::thrift::detail::mc::readSchema(::cpp2::include_constants::_fbthrift_schema_8569dfae849b43aa), - }; - return ::folly::range(includes); + return {}; } } // namespace module_constants