-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dart: allow conditionally disabling 'Finalizable' marker usage (#1646)
---------- Motivation ---------- It turned out that in certain rare cases Dart compiler experiences internal compiler error related to scope building when 'Finalizable' is used. The fix for the problems is available in Dart SDK 3.6.0+. There can be problems if the user cannot immediately upgrade to the new Dart SDK and wants to use other new features/bug-fixes. ---------- Implemented change ---------- In order to ease the transition phase for users the new CLI flag called 'dartdisablefinalizablemarker' was introduced. It allows users to conditionally disable the usage of 'Finalizable' marker interface. Moreover, new CMake tests have been introduced to verify that 'GLUECODIUM_DART_DISABLE_FINALIZABLE_MARKER' flag works as expected. They bring also a new utility for CMake tests, which allow users to verify if the generated file contains a given string. ---------- IMPORTANT ---------- It is discouraged to use this flag, because when 'Finalizable' marker interface is not used a rare race conditions between garbage collection and native finalizers may occur. The flag is designed ONLY to help during the transition phase to Dart SDK 3.6.0+. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
- Loading branch information
1 parent
f4393fb
commit 6519c60
Showing
16 changed files
with
233 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
cmake/tests/unit/gluecodium_generate/dart-disable-finalizable-marker/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (C) 2025 HERE Europe B.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
cmake_minimum_required(VERSION 3.12) | ||
|
||
project(gluecodium.test) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${GLUECODIUM_CMAKE_DIR}/modules") | ||
include(gluecodium/Gluecodium) | ||
|
||
include(${GLUECODIUM_CMAKE_TESTS_DIR}/utils/check_file_does_not_contain_string_after_build.cmake) | ||
|
||
add_library(dummySharedLibrary SHARED "${CMAKE_CURRENT_LIST_DIR}/cpp/FooImpl.cpp") | ||
|
||
gluecodium_generate(dummySharedLibrary GENERATORS cpp dart) | ||
gluecodium_target_lime_sources(dummySharedLibrary | ||
PRIVATE "${CMAKE_CURRENT_LIST_DIR}/lime/foo.lime") | ||
|
||
set_target_properties(dummySharedLibrary PROPERTIES GLUECODIUM_DART_DISABLE_FINALIZABLE_MARKER "ON") | ||
|
||
set(GENERATED_MAIN_DIR_PATH "${CMAKE_CURRENT_BINARY_DIR}/gluecodium/dummySharedLibrary/cpp-dart/main") | ||
set(GENERATED_MAIN_DART_FILES_PATH "${GENERATED_MAIN_DIR_PATH}/dart/lib/src/unit/test") | ||
|
||
check_file_does_not_contain_string_after_build( | ||
dummySharedLibrary "${GENERATED_MAIN_DART_FILES_PATH}/foo.dart" "Finalizable") | ||
|
||
check_file_does_not_contain_string_after_build( | ||
dummySharedLibrary "${GENERATED_MAIN_DART_FILES_PATH}/bar.dart" "Finalizable") | ||
|
||
check_file_does_not_contain_string_after_build( | ||
dummySharedLibrary "${GENERATED_MAIN_DART_FILES_PATH}/baz.dart" "Finalizable") |
19 changes: 19 additions & 0 deletions
19
cmake/tests/unit/gluecodium_generate/dart-disable-finalizable-marker/cpp/FooImpl.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (C) 2016-2025 HERE Europe B.V. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// License-Filename: LICENSE | ||
// | ||
// ------------------------------------------------------------------------------------------------- |
28 changes: 28 additions & 0 deletions
28
cmake/tests/unit/gluecodium_generate/dart-disable-finalizable-marker/lime/foo.lime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (C) 2016-2025 HERE Europe B.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
package unit.test | ||
|
||
class Foo { | ||
|
||
} | ||
|
||
interface Bar { | ||
fun bar() | ||
} | ||
|
||
lambda Baz = (Int) -> Void |
41 changes: 41 additions & 0 deletions
41
cmake/tests/utils/check_file_does_not_contain_string_after_build.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) 2016-2025 HERE Europe B.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
#[=======================================================================[.rst: | ||
.. command:check_file_does_not_contain_string_after_build | ||
Checks that provided file does not contain a given string after given target is built. | ||
Adds post build command which tries to grep for a given string. | ||
check_file_does_not_contain_string_after_build( | ||
<target> # Target to add post build command | ||
<file_path> # File or directory path to check | ||
<needle> # String to look for in the file. | ||
) | ||
#]=======================================================================] | ||
|
||
function(check_file_does_not_contain_string_after_build _target file_path needle) | ||
add_custom_command( | ||
TARGET ${_target} | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E echo | ||
"Loads a file '${file_path}' and looks for '${needle}'. This file contains it if command fails." | ||
COMMAND ${CMAKE_COMMAND} -DCHECK_FILE_DOES_NOT_CONTAIN_FILE_PATH="${file_path}" | ||
-DCHECK_FILE_DOES_NOT_CONTAIN_NEEDLE="${needle}" | ||
-P "${GLUECODIUM_CMAKE_TESTS_DIR}/utils/run_check_file_does_not_contain_string.cmake") | ||
endfunction() |
38 changes: 38 additions & 0 deletions
38
cmake/tests/utils/run_check_file_does_not_contain_string.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (C) 2016-2025 HERE Europe B.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/message_colored.cmake") | ||
|
||
set(_required_vars CHECK_FILE_DOES_NOT_CONTAIN_FILE_PATH CHECK_FILE_DOES_NOT_CONTAIN_NEEDLE) | ||
|
||
foreach(_required_variable ${_required_vars}) | ||
if(NOT DEFINED ${_required_variable}) | ||
message_colored(RED FATAL_ERROR "${_required_variable} must be specified") | ||
endif() | ||
endforeach() | ||
|
||
file(STRINGS ${CHECK_FILE_DOES_NOT_CONTAIN_FILE_PATH} _lines) | ||
|
||
foreach(_line ${_lines}) | ||
if("${_line}" MATCHES "${CHECK_FILE_DOES_NOT_CONTAIN_NEEDLE}") | ||
message_colored( | ||
RED FATAL_ERROR | ||
"The file ${CHECK_FILE_DOES_NOT_CONTAIN_FILE_PATH} contains: ${CHECK_FILE_DOES_NOT_CONTAIN_NEEDLE}") | ||
endif() | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters