def testAddProjectsTwice(self): """ csnProjectTests: test that adding a project twice has no effect. """ # dummyLib project dummyLib = csnProject.Project("DummyLib", "library") # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") # add dummyLib a first time dummyExe.AddProjects([dummyLib]) # count projects nProjects = len(dummyExe.dependenciesManager.projects) # add dummyLib another time dummyExe.AddProjects([dummyLib]) # test same number of projects self.assertEqual(nProjects, len(dummyExe.dependenciesManager.projects))
def testName(self): """ csnProjectTests: test that the name of the project is correct. """ # dummyLib project dummyLib = csnProject.Project("DummyLib", "library") # check the name self.assertEqual(dummyLib.name, "DummyLib")
def testCreateHeader(self): """ testCreateHeader: test the CreateHeader method. """ project = csnProject.Project("Project", "library") project.AddCustomCommand(csnCilab.CreateToolkitHeader) # generate generator = csnBuild.Generator() generator.Generate(project) # check that the headerFile is there path = "%s/%s" % (project.GetBuildFolder(), "CISTIBToolkit.h") headerFile = open(path, 'r') foundSrcPath = False foundBuildPath = False for line in headerFile: if not foundSrcPath: if line.find("CISTIB_TOOLKIT_FOLDER") != -1: foundSrcPath = True if not foundBuildPath: if line.find("CISTIB_TOOLKIT_BUILD_FOLDER") != -1: foundBuildPath = True headerFile.close() # test self.assertTrue(foundSrcPath) self.assertTrue(foundBuildPath) # clean up shutil.rmtree(csnProject.globalCurrentContext.GetBuildFolder())
def testAddProjectsCyclicDependency(self): """ csnProjectTests: test that a cylic dependency is detected. """ # dummyLib project dummyLib = csnProject.Project("DummyLib", "library") # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") # dummyExe depends on dummyLib dummyExe.AddProjects([dummyLib]) # try making dummyLib depend on dummyExe (cyclic dependency) dummyLib.AddProjects([dummyExe]) # check dependencies (CSnake should detect the cyclic dependency there) self.assertRaises(csnDependencies.DependencyError, dummyLib.GetProjects, _recursive=True, _onlyRequiredProjects=True)
def testAddProjectsSelfDependency(self): """ csnProjectTests: test that a project cannot depend on itself. """ # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") # test adding self self.assertRaises(csnDependencies.DependencyError, dummyExe.AddProjects, [dummyExe])
def testGlob(self): """ csnProjectTests: test that globbing source files works. """ # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") dummyExe.AddSources(["data/my src/DummyExe/src/*.cpp"]) # should have 1 source files assert len(dummyExe.GetSources()) == 1, csnUtility.Join( dummyExe.GetSources(), _addQuotes=1)
def testAddSources(self): """ csnProjectTests: test that a non-existing source file is detected. """ # dummyLib project dummyLib = csnProject.Project("DummyLib", "library") # check adding non existing file dummyLib.AddSources(["main.cpp"]) self.assertRaises(IOError, dummyLib.GetCompileManager)
def testSourceRootFolder(self): """ csnProjectTests: test that the source root folder, containing csnBuildTest.py, is deduced correctly by the parent class csnBuild.Project. """ # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") dummyExe.AddSources(["data/my src/DummyExe/src/*.cpp"]) # check folder self.assertEqual(os.path.abspath(dummyExe.sourceRootFolder), os.path.abspath(os.path.dirname(__file__)))
def GimiasPluginProject(_name, _sourceRootFolder=None): """ This class is used to build a plugin coming from the CilabApps/Plugins folder. Use AddWidgetModules to add widget modules to the plugin. """ if _sourceRootFolder is None: _sourceRootFolder = csnUtility.NormalizePath( os.path.dirname(csnProject.FindFilename(1))) pluginName = "GIMIAS%s" % _name project = csnProject.Project(_name, _type="dll", _sourceRootFolder=_sourceRootFolder, _categories=[pluginName]) project.applicationsProject = None project.installSubFolder = "plugins/%s/lib" % _name project.AddIncludeFolders(["."]) project.AddWidgetModules = new.instancemethod( _AddWidgetModulesMemberFunction, project) project.context.SetSuperSubCategory("Plugins", pluginName) # Windows debug installFolder = "%s/debug" % project.installSubFolder project.installManager.AddFilesToInstall(project.Glob("plugin.xml"), installFolder, _debugOnly=1, _WIN32=1) installFolder = installFolder + "/Filters/" project.installManager.AddFilesToInstall(project.Glob("Filters/*.xml"), installFolder, _debugOnly=1, _WIN32=1) # Windows release installFolder = "%s/release" % project.installSubFolder project.installManager.AddFilesToInstall(project.Glob("plugin.xml"), installFolder, _releaseOnly=1, _WIN32=1) installFolder = installFolder + "/Filters/" project.installManager.AddFilesToInstall(project.Glob("Filters/*.xml"), installFolder, _releaseOnly=1, _WIN32=1) # Linux project.installManager.AddFilesToInstall(project.Glob("plugin.xml"), project.installSubFolder, _NOT_WIN32=1) installFolder = project.installSubFolder + "/Filters" project.installManager.AddFilesToInstall(project.Glob("Filters/*.xml"), installFolder, _NOT_WIN32=1) return project
def testAddProjectsNameConflict(self): """ csnProjectTests: test that two projects cannot have the same name. """ # dummyLib project dummyLib = csnProject.Project("DummyLib", "library") # dummyLib2 project: same name as dummyLib dummyLib2 = csnProject.Project("DummyLib", "library") # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") # add dummyLib dummyExe.AddProjects([dummyLib]) # add dummyLib2 dummyExe.AddProjects([dummyLib2]) # get the generator generator = csnBuild.Generator() # test NameError self.assertRaises(NameError, generator.Generate, dummyExe) # clean up shutil.rmtree(csnProject.globalCurrentContext.GetBuildFolder())
def StandardModuleProject(_name, _type, _sourceRootFolder=None): if _sourceRootFolder is None: _sourceRootFolder = csnUtility.NormalizePath( os.path.dirname(csnProject.FindFilename(1))) project = csnProject.Project(_name, _type, _sourceRootFolder) project.applicationsProject = None project.AddLibraryModules = new.instancemethod( _AddLibraryModulesMemberFunction, project) project.AddApplications = new.instancemethod( _AddApplicationsMemberFunction, project) return project
def testBuildBinFolderSlashes(self): """ csnProjectTests: test that build bin folder may not contain any backward slashes. """ # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") # get the generator generator = csnBuild.Generator() # replace the build folder testPath = os.path.abspath(os.path.dirname(__file__)).replace( "\\", "/") csnProject.globalCurrentContext.SetBuildFolder("%s\\%s" % (testPath, "temp_bin")) # test SyntaxError self.assertRaises(csnGenerator.SyntaxError, generator.Generate, dummyExe)
def testGenerate(self): """ csnBuildTest: test configuring a dummy project. """ # load fake context self.context = csnContext.Load("config/csnake_context.txt") # change the build folder self.context.SetBuildFolder(self.context.GetBuildFolder() + "/build") # set it as global context csnProject.globalCurrentContext = self.context # dummyExe project dummyExe = csnProject.Project("DummyExe", "executable") # generate cmake files generator = csnBuild.Generator() generator.Generate(dummyExe) # clean up shutil.rmtree(csnProject.globalCurrentContext.GetBuildFolder())
def testWinSwitch(self): """ csnInstallTests: test install files with windows switch. """ location = "./Install" project = csnProject.Project("TestProject", "dll") project.AddFilesToInstall(["Hello.cpp"], location, _WIN32=1) project.AddFilesToInstall(["Bye.h"], location, _NOT_WIN32=1) # _WIN32 case if (self.context.GetCompilername().find("Visual Studio") != -1): assert project.installManager.filesToInstall["Release"][ location] == ["Hello.cpp"] assert project.installManager.filesToInstall["Debug"][ location] == ["Hello.cpp"] # _NOT_WIN32 case elif (self.context.GetCompilername().find("KDevelop3") != -1 or self.context.GetCompilername().find("Makefile") != -1): assert project.installManager.filesToInstall["Release"][ location] == ["Bye.h"] assert project.installManager.filesToInstall["Debug"][ location] == ["Bye.h"]
def testInstall(self): """ csnInstallTests: test the installation of files. """ # dummyLib project dummyInstall = csnProject.Project("DummyInstall", "library") dummyInstall.AddFilesToInstall(dummyInstall.Glob("AllTests.bat"), _debugOnly=1, _WIN32=1, _NOT_WIN32=1) dummyInstall.AddFilesToInstall(dummyInstall.Glob("AllTests.sh"), _releaseOnly=1, _WIN32=1, _NOT_WIN32=1) dummyInstall.installManager.InstallBinariesToBuildFolder() # check presence of the files assert os.path.exists("build/bin/Debug/AllTests.bat" ), "File not installed in Debug mode." assert os.path.exists("build/bin/Release/AllTests.sh" ), "File not installed in Release mode." # clean up shutil.rmtree(csnProject.globalCurrentContext.GetBuildFolder())
def CommandLinePlugin(_name, _holderProject=None): """ Create a command line plugin project. """ _sourceRootFolder = csnUtility.NormalizePath( os.path.dirname(csnProject.FindFilename(1))) # command line lib projectLibName = "%sLib" % _name projectLib = csnProject.Project(projectLibName, "dll", _sourceRootFolder) #project = CilabModuleProject(projectName, "dll", _sourceRootFolder) projectLib.AddDefinitions(["-Dmain=ModuleEntryPoint"], _private=1) projectLib.installSubFolder = "commandLinePlugins" projectLib.CMakeInsertBeforeTarget = new.instancemethod( CreateCMakeCLPPre, projectLib) projectLib.CMakeInsertAfterTarget = new.instancemethod( CreateCMakeCLPPost, projectLib) # command line executable projectAppName = _name projectApp = csnBuild.Project(projectAppName, "executable", _sourceRootFolder) projectApp.AddProjects([projectLib]) projectApp.installSubFolder = "commandLinePlugins" # wrapper for shared libraries wrapperSourceFile = None for thirdParty in csnProject.globalCurrentContext.GetThirdPartyFolders(): currentWrapperSourceFile = u'%s/SLICER/Slicer3/Applications/CLI/Templates/CommandLineSharedLibraryWrapper.cxx' % thirdParty if os.path.isfile(currentWrapperSourceFile): wrapperSourceFile = currentWrapperSourceFile if wrapperSourceFile is None: raise Exception( "Could not find Slicer template in your thirdParty folders.") projectApp.AddSources([wrapperSourceFile]) # force the creation of the application project projectLib.AddProjects([projectApp], _dependency=0) if not (_holderProject is None): _holderProject.AddProjects([projectLib]) return projectLib
import csnProject import csnUtility import os.path import inspect import csnVisualStudio2003 import csnVisualStudio2005 import csnVisualStudio2008 if csnBuild.version < 2.22: import csnVisualStudio2008x64 # Used to configure gimias def CreateGIMIAS(): gimias = csnCilab.CilabModuleProject("Gimias", "executable") gimias.AddSources(gimias.Glob("GUI/MainApp/src/*.h"), _checkExists=1) gimias.AddSources(gimias.Glob("GUI/MainApp/src/*.cxx"), _checkExists=1) gimias.SetPrecompiledHeader("GUI/MainApp/gmMainAppPCH.h") gimias.AddIncludeFolders([gimias.GetBuildFolder()]) return gimias commandLinePlugins = csnProject.Project( "CommandLinePlugins", "container", csnUtility.NormalizePath(os.path.dirname(inspect.stack()[1][1])), _categories=["GIMIASCommandLinePlugins"])