2
0
Эх сурвалжийг харах

Some cleanup and X11 build issues fixed.

Michael Ragazzon 5 жил өмнө
parent
commit
d42480f0cc

+ 3 - 3
.appveyor.yml

@@ -24,10 +24,10 @@ install:
     mkdir Build-Dynamic, Build-Static
     
     cd Build-Dynamic
-    cmake -G "%VS_GENERATOR%" -DBUILD_SHARED_LIBS=ON -DBUILD_SAMPLES=ON ..
+    cmake -G "%VS_GENERATOR%" -DBUILD_SHARED_LIBS=ON -DBUILD_SAMPLES=ON -DWARNINGS_AS_ERRORS=ON ..
 
     cd ../Build-Static
-    cmake -G "%VS_GENERATOR%" -DBUILD_SHARED_LIBS=OFF -DBUILD_SAMPLES=OFF ..
+    cmake -G "%VS_GENERATOR%" -DBUILD_SHARED_LIBS=OFF -DBUILD_SAMPLES=OFF -DWARNINGS_AS_ERRORS=ON ..
     
     cd ..
     
@@ -96,7 +96,7 @@ for:
       set GLEW_INCLUDE_DIR=C:/msys64/mingw64/include/GL
       set GLEW_LIBRARIES=C:/msys64/mingw64/lib/libglew32.dll.a
       
-      cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_SAMPLES=ON -DBUILD_LUA_BINDINGS=ON -DCMAKE_C_COMPILER=gcc.exe -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_MAKE_PROGRAM=mingw32-make.exe -DGLEW_INCLUDE_DIR=%GLEW_INCLUDE_DIR% -DGLEW_LIBRARIES=%GLEW_LIBRARIES% ..
+      cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_SAMPLES=ON -DBUILD_LUA_BINDINGS=ON -DWARNINGS_AS_ERRORS=ON -DCMAKE_C_COMPILER=gcc.exe -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_MAKE_PROGRAM=mingw32-make.exe -DGLEW_INCLUDE_DIR=%GLEW_INCLUDE_DIR% -DGLEW_LIBRARIES=%GLEW_LIBRARIES% ..
 
       set CHERE_INVOKING=yes
       set MSYSTEM=MINGW64

+ 2 - 2
.travis.yml

@@ -14,7 +14,7 @@ matrix:
       compiler: clang
     - os: linux
       compiler: clang
-      env: BUILD_TESTING="ON" WARNINGS_AS_ERRORS="ON"
+      env: BUILD_TESTING="ON"
       addons:
         apt:
           packages:
@@ -88,7 +88,7 @@ install:
   - cmake --version
   - cd "$TRAVIS_BUILD_DIR"
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cmake -DNO_THIRDPARTY_CONTAINERS=ON -DENABLE_PRECOMPILED_HEADERS=OFF -G Xcode .; fi
-  - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then cmake -DBUILD_LUA_BINDINGS=ON -DBUILD_SAMPLES=ON -DBUILD_TESTING=${BUILD_TESTING:-OFF} -DWARNINGS_AS_ERRORS=${WARNINGS_AS_ERRORS:-OFF} -DDISABLE_RTTI_AND_EXCEPTIONS=${DISABLE_RTTI_AND_EXCEPTIONS:-OFF} -DNO_THIRDPARTY_CONTAINERS=${NO_THIRDPARTY_CONTAINERS:-OFF} -DNO_FONT_INTERFACE_DEFAULT=${NO_FONT_INTERFACE_DEFAULT:-OFF} -G Ninja .; fi
+  - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then cmake -DBUILD_LUA_BINDINGS=ON -DBUILD_SAMPLES=ON -DBUILD_TESTING=${BUILD_TESTING:-OFF} -DWARNINGS_AS_ERRORS=ON -DDISABLE_RTTI_AND_EXCEPTIONS=${DISABLE_RTTI_AND_EXCEPTIONS:-OFF} -DNO_THIRDPARTY_CONTAINERS=${NO_THIRDPARTY_CONTAINERS:-OFF} -DNO_FONT_INTERFACE_DEFAULT=${NO_FONT_INTERFACE_DEFAULT:-OFF} -G Ninja .; fi
 
 before_script:
   - if [[ "$VALGRIND_SAMPLES" == "1" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; fi

+ 3 - 2
Samples/basic/treeview/src/main.cpp

@@ -106,8 +106,9 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 
 	Shell::LoadFonts("assets/");
 
-	// Create the file data source and formatter. The samples directory '/' acts as our root.
-	FileSystem file_system("/");
+	// Create the file data source and formatter.
+	const Rml::String root = Shell::FindSamplesRoot();
+	FileSystem file_system(root);
 	FileFormatter file_formatter;
 
 	// Load and show the demo document.

+ 19 - 21
Samples/shell/src/Shell.cpp

@@ -56,23 +56,16 @@ void Shell::LoadFonts(const char* directory)
 
 enum class ListType { Files, Directories };
 
-static Rml::StringList ListFilesOrDirectories(ListType type, const Rml::String& in_directory, const Rml::String& extension)
+static Rml::StringList ListFilesOrDirectories(ListType type, const Rml::String& directory, const Rml::String& extension)
 {
-	if (in_directory.empty())
+	if (directory.empty())
 		return Rml::StringList();
 
-	Rml::String directory;
-
-	if (in_directory[0] == '/')
-		directory = Shell::FindSamplesRoot() + in_directory.substr(1);
-	else
-		directory = in_directory;
-
-	const Rml::String find_path = directory + "/*." + (extension.empty() ? Rml::String("*") : extension);
-
 	Rml::StringList result;
 
 #ifdef RMLUI_PLATFORM_WIN32
+	const Rml::String find_path = directory + "/*." + (extension.empty() ? Rml::String("*") : extension);
+
 	_finddata_t find_data;
 	intptr_t find_handle = _findfirst(find_path.c_str(), &find_data);
 	if (find_handle != -1)
@@ -98,25 +91,30 @@ static Rml::StringList ListFilesOrDirectories(ListType type, const Rml::String&
 	}
 #else
 	struct dirent** file_list = nullptr;
-	int file_count = -1;
-	file_count = scandir(find_path.c_str(), &file_list, 0, alphasort);
+	const int file_count = scandir(directory.c_str(), &file_list, 0, alphasort);
 	if (file_count == -1)
-		return;
+		return Rml::StringList();
 
-	// TODO: Untested
-	while (file_count--)
+	for (int i = 0; i < file_count; i++)
 	{
-		if (strcmp(file_list[file_count]->d_name, ".") == 0 ||
-			strcmp(file_list[file_count]->d_name, "..") == 0)
+		if (strcmp(file_list[i]->d_name, ".") == 0 ||
+			strcmp(file_list[i]->d_name, "..") == 0)
 			continue;
 
-		bool is_directory = ((file_list[file_count]->d_type & DT_DIR) == DT_DIR);
-		bool is_file = ((file_list[file_count]->d_type & DT_REG) == DT_REG);
+		bool is_directory = ((file_list[i]->d_type & DT_DIR) == DT_DIR);
+		bool is_file = ((file_list[i]->d_type & DT_REG) == DT_REG);
+
+		if (!extension.empty())
+		{
+			const char* last_dot = strrchr(file_list[i]->d_name, '.');
+			if (!last_dot || strcmp(last_dot + 1, extension.c_str()) != 0)
+				continue;
+		}
 
 		if ((type == ListType::Files && is_file) ||
 			(type == ListType::Directories && is_directory))
 		{
-			result.push_back(file_list[file_count]->d_name);
+			result.push_back(file_list[i]->d_name);
 		}
 	}
 	free(file_list);

+ 1 - 1
Samples/shell/src/win32/ShellWin32.cpp

@@ -95,7 +95,7 @@ void Shell::Shutdown()
 
 Rml::String Shell::FindSamplesRoot()
 {
-	const char* candidate_paths[] = { "", "..\\..\\Samples\\", "..\\Samples\\", "..\\..\\..\\Samples\\" };
+	const char* candidate_paths[] = { "", "..\\Samples\\", "..\\..\\Samples\\", "..\\..\\..\\Samples\\", "..\\..\\..\\..\\Samples\\" };
 	
 	// Fetch the path of the executable, test the candidate paths appended to that.
 	char executable_file_name[MAX_PATH];

+ 1 - 1
Samples/shell/src/x11/ShellX11.cpp

@@ -107,7 +107,7 @@ Rml::String Shell::FindSamplesRoot()
 	// For "../Samples/" to be valid we must be in the Build directory.
 	// If "../" is valid we are probably in the installation directory.
 	// Some build setups may nest the executables deeper in a build directory, try them last.
-	const char* candidate_paths[] = { "../Samples/", "../", "", "../../Samples/", "../../../Samples/"};
+	const char* candidate_paths[] = { "", "../", "../Samples/", "../../Samples/", "../../../Samples/", "../../../../Samples/" };
 
 	for (const char* relative_path : candidate_paths)
 	{

+ 4 - 4
Tests/Source/UnitTests/DataExpression.cpp

@@ -41,7 +41,7 @@ static DataModel model(type_register.GetTransformFuncRegister());
 static DataExpressionInterface interface(&model, nullptr);
 
 
-String TestExpression(const String& expression)
+static String TestExpression(const String& expression)
 {
 	String result;
 
@@ -65,9 +65,9 @@ String TestExpression(const String& expression)
 	}
 
 	return result;
-};
+}
 
-bool TestAssignment(const String& expression)
+static bool TestAssignment(const String& expression)
 {
 	bool result = false;
 	DataParser parser(expression, interface);
@@ -87,7 +87,7 @@ bool TestAssignment(const String& expression)
 		FAIL_CHECK("Could not parse assignment expression: " << expression);
 	}
 	return result;
-};
+}
 
 
 

+ 3 - 3
Tests/Source/VisualTests/Window.cpp

@@ -83,14 +83,14 @@ String Window::GetCurrentPath() const {
 	REQUIRE(current_id >= 0);
 	REQUIRE(current_id < (int)test_suite.files.size());
 
-	return test_suite.directory + '\\' + test_suite.files[current_id];
+	return test_suite.directory + '/' + test_suite.files[current_id];
 }
 
 String Window::GetReferencePath() const {
 	if (reference_file.empty())
 		return String();
 	const TestSuite& test_suite = GetCurrentTestSuite();
-	return test_suite.directory + '\\' + reference_file;
+	return test_suite.directory + '/' + reference_file;
 }
 
 void Window::OpenSource(const String& file_path)
@@ -293,7 +293,7 @@ void Window::ProcessEvent(Rml::Event& event)
 		else if (key_identifier == Rml::Input::KI_C && key_ctrl)
 		{
 			if (key_shift)
-				Shell::SetClipboardText(GetCurrentTestSuite().directory + '\\' + reference_file);
+				Shell::SetClipboardText(GetCurrentTestSuite().directory + '/' + reference_file);
 			else
 				Shell::SetClipboardText(GetCurrentPath());
 		}

+ 3 - 10
Tests/Source/VisualTests/XmlNodeHandlers.cpp

@@ -106,14 +106,7 @@ public:
 			}
 		}
 
-		LinkItem item{ rel, href };
-
-		if (rel == "match")
-			item.href = StringUtilities::Replace(href, '/', '\\');
-		else
-			item.href = href;
-
-		link_list->push_back(std::move(item));
+		link_list->push_back(LinkItem{ rel, href });
 
 		return nullptr;
 	}
@@ -139,10 +132,10 @@ static SharedPtr<XMLNodeHandlerLink> link_handler;
 void InitializeXmlNodeHandlers(MetaList* meta_list, LinkList* link_list)
 {
 	meta_handler = MakeShared<XMLNodeHandlerMeta>(meta_list);
-	REQUIRE(meta_handler);
+	REQUIRE((bool)meta_handler);
 	Rml::XMLParser::RegisterNodeHandler("meta", meta_handler);
 
 	link_handler = MakeShared<XMLNodeHandlerLink>(link_list);
-	REQUIRE(link_handler);
+	REQUIRE((bool)link_handler);
 	Rml::XMLParser::RegisterNodeHandler("link", link_handler);
 }

+ 3 - 1
Tests/Source/VisualTests/main.cpp

@@ -64,7 +64,9 @@ TEST_CASE("Run VisualTests")
 	context = TestsShell::GetMainContext();
 	REQUIRE(context);
 
-	StringList directories = { "/../Tests/Data/VisualTests" };
+	const String samples_root = Shell::FindSamplesRoot();
+
+	StringList directories = { samples_root + "../Tests/Data/VisualTests" };
 
 #ifdef RMLUI_VISUAL_TESTS_DIRECTORIES
 	StringUtilities::ExpandString(directories, RMLUI_VISUAL_TESTS_DIRECTORIES, ';');