mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00
Add ComponentCompiler::build_from_path
This commit is contained in:
parent
fd9d154b27
commit
9eecdefb35
5 changed files with 57 additions and 0 deletions
|
@ -136,6 +136,9 @@ if(BUILD_TESTING)
|
||||||
|
|
||||||
add_executable(api_tests tests/tests.cpp)
|
add_executable(api_tests tests/tests.cpp)
|
||||||
target_link_libraries(api_tests PRIVATE SixtyFPS Catch2::Catch2)
|
target_link_libraries(api_tests PRIVATE SixtyFPS Catch2::Catch2)
|
||||||
|
target_compile_definitions(api_tests PRIVATE
|
||||||
|
SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"
|
||||||
|
)
|
||||||
add_test(api_tests ${CMAKE_CURRENT_BINARY_DIR}/api_tests)
|
add_test(api_tests ${CMAKE_CURRENT_BINARY_DIR}/api_tests)
|
||||||
# Somehow the wrong relative rpath ends up in the binary, requiring us to change the
|
# Somehow the wrong relative rpath ends up in the binary, requiring us to change the
|
||||||
# working directory.
|
# working directory.
|
||||||
|
|
|
@ -502,6 +502,18 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<ComponentDefinition> build_from_path(std::string_view path)
|
||||||
|
{
|
||||||
|
cbindgen_private::ComponentDefinitionOpaque result;
|
||||||
|
if (cbindgen_private::sixtyfps_interpreter_component_compiler_build_from_path(
|
||||||
|
&inner, sixtyfps::private_api::string_to_slice(path), &result)) {
|
||||||
|
|
||||||
|
return ComponentDefinition(result);
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
10
api/sixtyfps-cpp/tests/test.60
Normal file
10
api/sixtyfps-cpp/tests/test.60
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/* LICENSE BEGIN
|
||||||
|
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||||
|
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||||
|
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
This file is also available under commercial licensing terms.
|
||||||
|
Please contact info@sixtyfps.io for more information.
|
||||||
|
LICENSE END */
|
||||||
|
export Test := Rectangle {}
|
|
@ -277,4 +277,16 @@ SCENARIO("Component Compiler")
|
||||||
auto result = compiler.build_from_source("export Dummy := Rectangle {}", "");
|
auto result = compiler.build_from_source("export Dummy := Rectangle {}", "");
|
||||||
REQUIRE(result.has_value());
|
REQUIRE(result.has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Compile failure from path")
|
||||||
|
{
|
||||||
|
auto result = compiler.build_from_path(SOURCE_DIR "/file-not-there.60");
|
||||||
|
REQUIRE_FALSE(result.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Compile from path")
|
||||||
|
{
|
||||||
|
auto result = compiler.build_from_path(SOURCE_DIR "/tests/test.60");
|
||||||
|
REQUIRE(result.has_value());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1352,6 +1352,26 @@ pub(crate) mod ffi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sixtyfps_interpreter_component_compiler_build_from_path(
|
||||||
|
compiler: &mut ComponentCompilerOpaque,
|
||||||
|
path: Slice<u8>,
|
||||||
|
component_definition_ptr: *mut ComponentDefinitionOpaque,
|
||||||
|
) -> bool {
|
||||||
|
use std::str::FromStr;
|
||||||
|
match spin_on::spin_on(
|
||||||
|
compiler
|
||||||
|
.as_component_compiler_mut()
|
||||||
|
.build_from_path(PathBuf::from_str(std::str::from_utf8(&path).unwrap()).unwrap()),
|
||||||
|
) {
|
||||||
|
Some(definition) => {
|
||||||
|
std::ptr::write(component_definition_ptr as *mut ComponentDefinition, definition);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
// Note: This needs to stay the size of 1 pointer to allow for the null pointer definition
|
// Note: This needs to stay the size of 1 pointer to allow for the null pointer definition
|
||||||
// in the C++ wrapper to allow for the null state.
|
// in the C++ wrapper to allow for the null state.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue