void CppCodeEvent::EnsureAssociatedSourceFileIsUpToDate( gd::Project& project) const { #if !defined(GD_NO_WX_GUI) gd::String outputFile(CodeCompiler::Get()->GetOutputDirectory() + "GD" + gd::String::From(this) + "SourceFile.cpp"); gd::SourceFile* sourceFile; // First check if the associated source file exists in the GD project. if (project.HasSourceFile(associatedGDManagedSourceFile, "C++")) sourceFile = &project.GetSourceFile(associatedGDManagedSourceFile); else { // If there is no associated source file existing, then create a new one sourceFile = &project.InsertNewSourceFile(outputFile, "C++"); sourceFile->SetGDManaged(true); } // Then check if the associated source file is up to date associatedGDManagedSourceFile = outputFile; if (sourceFile->GetFileName() != outputFile) { sourceFile->SetFileName(outputFile); } else if (wxFileExists(outputFile)) { wxFileName sourceFileInfo(outputFile); if (sourceFileInfo.GetModificationTime().GetTicks() >= lastChangeTimeStamp) return; } // The associated source file is non existing or not up to date: Regenerate // it. It will be compiled ( see CodeCompilationHelpers ) as it will be // detected ( by DependenciesAnalyzer ) as a SourceFile dependency which is // not up to date. gd::FileStream file; file.open(outputFile, std::ios_base::out); file << GenerateAssociatedFileCode(); file.close(); #else gd::LogError( "BAD USE: C++ Code event not supported when wxWidgets support is " "disabled"); #endif }
/* * GDevelop Core * Copyright 2008-2014 Florian Rival ([email protected]). All rights reserved. * This project is released under the MIT License. */ /** * @file Tests covering common features of GDevelop Core. */ #include "catch.hpp" #include "GDCore/CommonTools.h" #include "GDCore/PlatformDefinition/Project.h" #include "GDCore/PlatformDefinition/SourceFile.h" TEST_CASE( "SourceFile", "[common]" ) { SECTION("Basics") { gd::Project project; project.InsertNewSourceFile("test.cpp", "C++"); project.InsertNewSourceFile("test.js", "Javascript"); REQUIRE( project.HasSourceFile("test.cpp", "C++") == true ); REQUIRE( project.HasSourceFile("test.cpp", "JS") == false ); REQUIRE( project.HasSourceFile("test.cpp") == true ); gd::SourceFile & cppSourceFile = project.GetSourceFile("test.cpp"); REQUIRE( cppSourceFile.GetFileName() == "test.cpp" ); REQUIRE( cppSourceFile.GetLanguage() == "C++" ); project.RemoveSourceFile("test.cpp"); REQUIRE( project.HasSourceFile("test.cpp") == false ); REQUIRE( project.HasSourceFile("test.js") == true ); } }