2015-07-14 18:17:55 -04:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
using System ;
using System.Collections.Generic ;
using System.Text ;
using System.IO ;
using System.Xml ;
using System.Xml.Linq ;
namespace UnrealBuildTool
{
// Represents a folder within the master project. TODO Not using at the moment.
public class CodeLiteFolder : MasterProjectFolder
{
2015-09-24 12:37:21 -04:00
public CodeLiteFolder ( ProjectFileGenerator InitOwnerProjectFileGenerator , string InitFolderName )
2015-07-14 18:17:55 -04:00
: base ( InitOwnerProjectFileGenerator , InitFolderName )
{
}
}
public class CodeLiteGenerator : ProjectFileGenerator
{
public string SolutionExtension = ".workspace" ;
public string CodeCompletionFileName = "CodeCompletionFolders.txt" ;
public string CodeCompletionPreProcessorFileName = "CodeLitePreProcessor.txt" ;
2015-09-24 12:37:21 -04:00
public CodeLiteGenerator ( FileReference InOnlyGameProject )
: base ( InOnlyGameProject )
2015-09-17 09:15:44 -04:00
{
}
2015-07-14 18:17:55 -04:00
//
// Returns CodeLite's project filename extension.
//
override public string ProjectFileExtension
{
get
{
return ".project" ;
}
}
2015-09-24 12:37:21 -04:00
protected override bool WriteMasterProjectFile ( ProjectFile UBTProject )
2015-07-14 18:17:55 -04:00
{
var SolutionFileName = MasterProjectName + SolutionExtension ;
var CodeCompletionFile = MasterProjectName + CodeCompletionFileName ;
var CodeCompletionPreProcessorFile = MasterProjectName + CodeCompletionPreProcessorFileName ;
2015-09-03 08:47:24 -04:00
var FullCodeLiteMasterFile = Path . Combine ( MasterProjectPath . FullName , SolutionFileName ) ;
var FullCodeLiteCodeCompletionFile = Path . Combine ( MasterProjectPath . FullName , CodeCompletionFile ) ;
var FullCodeLiteCodeCompletionPreProcessorFile = Path . Combine ( MasterProjectPath . FullName , CodeCompletionPreProcessorFile ) ;
2015-07-14 18:17:55 -04:00
//
// HACK
// TODO This is for now a hack. According to the original submitter, Eranif (a CodeLite developer) will support code completion folders in *.workspace files.
2015-09-03 08:47:24 -04:00
// We create a separate file with all the folder name in it to copy manually into the code completion
2015-07-14 18:17:55 -04:00
// filed of CodeLite workspace. (Workspace Settings/Code Completion -> copy the content of the file threre.)
List < string > IncludeDirectories = new List < string > ( ) ;
List < string > PreProcessor = new List < string > ( ) ;
2015-09-24 12:37:21 -04:00
foreach ( var CurProject in GeneratedProjectFiles )
2015-07-21 13:39:28 -04:00
{
2015-07-14 18:17:55 -04:00
CodeLiteProject Project = CurProject as CodeLiteProject ;
if ( Project = = null )
{
continue ;
}
2015-09-24 12:37:21 -04:00
foreach ( var CurrentPath in Project . IntelliSenseIncludeSearchPaths )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
// Convert relative path into absolute.
DirectoryReference IntelliSenseIncludeSearchPath = DirectoryReference . Combine ( Project . ProjectFilePath . Directory , CurrentPath ) ;
IncludeDirectories . Add ( IntelliSenseIncludeSearchPath . FullName ) ;
2015-07-14 18:17:55 -04:00
}
2015-09-24 12:37:21 -04:00
foreach ( var CurrentPath in Project . IntelliSenseSystemIncludeSearchPaths )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
// Convert relative path into absolute.
DirectoryReference IntelliSenseSystemIncludeSearchPath = DirectoryReference . Combine ( Project . ProjectFilePath . Directory , CurrentPath ) ;
2015-09-24 12:37:21 -04:00
IncludeDirectories . Add ( IntelliSenseSystemIncludeSearchPath . FullName ) ;
2015-07-14 18:17:55 -04:00
}
2015-09-24 12:37:21 -04:00
foreach ( var CurDef in Project . IntelliSensePreprocessorDefinitions )
2015-07-14 18:17:55 -04:00
{
if ( ! PreProcessor . Contains ( CurDef ) )
{
PreProcessor . Add ( CurDef ) ;
}
}
}
//
// Write code completions data into files.
//
File . WriteAllLines ( FullCodeLiteCodeCompletionFile , IncludeDirectories ) ;
File . WriteAllLines ( FullCodeLiteCodeCompletionPreProcessorFile , PreProcessor ) ;
//
// Write CodeLites Workspace
//
XmlWriterSettings settings = new XmlWriterSettings ( ) ;
settings . Indent = true ;
XElement CodeLiteWorkspace = new XElement ( "CodeLite_Workspace" ) ;
XAttribute CodeLiteWorkspaceName = new XAttribute ( "Name" , MasterProjectName ) ;
XAttribute CodeLiteWorkspaceSWTLW = new XAttribute ( "SWTLW" , "Yes" ) ; // This flag will only work in CodeLite version > 8.0. See below
CodeLiteWorkspace . Add ( CodeLiteWorkspaceName ) ;
CodeLiteWorkspace . Add ( CodeLiteWorkspaceSWTLW ) ;
//
// ATTN This part will work for the next release of CodeLite. That may
// be CodeLite version > 8.0. CodeLite 8.0 does not have this functionality.
// TODO Macros are ignored for now.
//
// Write Code Completion folders into the WorkspaceParserPaths section.
//
XElement CodeLiteWorkspaceParserPaths = new XElement ( "WorkspaceParserPaths" ) ;
2015-09-24 12:37:21 -04:00
foreach ( var CurrentPath in IncludeDirectories )
2015-07-14 18:17:55 -04:00
{
XElement CodeLiteWorkspaceParserPathInclude = new XElement ( "Include" ) ;
XAttribute CodeLiteWorkspaceParserPath = new XAttribute ( "Path" , CurrentPath ) ;
CodeLiteWorkspaceParserPathInclude . Add ( CodeLiteWorkspaceParserPath ) ;
CodeLiteWorkspaceParserPaths . Add ( CodeLiteWorkspaceParserPathInclude ) ;
}
CodeLiteWorkspace . Add ( CodeLiteWorkspaceParserPaths ) ;
//
// Write project file information into CodeLite's workspace file.
//
2015-09-24 12:37:21 -04:00
foreach ( var CurProject in AllProjectFiles )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
var ProjectExtension = CurProject . ProjectFilePath . GetExtension ( ) ;
2015-07-14 18:17:55 -04:00
//
// TODO For now ignore C# project files.
//
2015-09-24 12:37:21 -04:00
if ( ProjectExtension = = ".csproj" )
2015-07-14 18:17:55 -04:00
{
continue ;
}
//
// Iterate through all targets.
//
2015-09-24 12:37:21 -04:00
foreach ( ProjectTarget CurrentTarget in CurProject . ProjectTargets )
2015-07-14 18:17:55 -04:00
{
2015-09-24 12:37:21 -04:00
string [ ] tmp = CurrentTarget . ToString ( ) . Split ( '.' ) ;
string ProjectTargetFileName = CurProject . ProjectFilePath . Directory . MakeRelativeTo ( MasterProjectPath ) + "/" + tmp [ 0 ] + ProjectExtension ;
String ProjectName = tmp [ 0 ] ;
2015-07-14 18:17:55 -04:00
XElement CodeLiteWorkspaceProject = new XElement ( "Project" ) ;
XAttribute CodeLiteWorkspaceProjectName = new XAttribute ( "Name" , ProjectName ) ;
XAttribute CodeLiteWorkspaceProjectPath = new XAttribute ( "Path" , ProjectTargetFileName ) ;
XAttribute CodeLiteWorkspaceProjectActive = new XAttribute ( "Active" , "No" ) ;
CodeLiteWorkspaceProject . Add ( CodeLiteWorkspaceProjectName ) ;
CodeLiteWorkspaceProject . Add ( CodeLiteWorkspaceProjectPath ) ;
CodeLiteWorkspaceProject . Add ( CodeLiteWorkspaceProjectActive ) ;
CodeLiteWorkspace . Add ( CodeLiteWorkspaceProject ) ;
}
}
//
// We need to create the configuration matrix. That will assign the project configuration to
// the samge workspace configuration.
//
XElement CodeLiteWorkspaceBuildMatrix = new XElement ( "BuildMatrix" ) ;
2015-09-24 12:37:21 -04:00
foreach ( UnrealTargetConfiguration CurConfiguration in SupportedConfigurations )
2015-07-14 18:17:55 -04:00
{
if ( UnrealBuildTool . IsValidConfiguration ( CurConfiguration ) )
{
XElement CodeLiteWorkspaceBuildMatrixConfiguration = new XElement ( "WorkspaceConfiguration" ) ;
XAttribute CodeLiteWorkspaceProjectName = new XAttribute ( "Name" , CurConfiguration . ToString ( ) ) ;
XAttribute CodeLiteWorkspaceProjectSelected = new XAttribute ( "Selected" , "no" ) ;
CodeLiteWorkspaceBuildMatrixConfiguration . Add ( CodeLiteWorkspaceProjectName ) ;
CodeLiteWorkspaceBuildMatrixConfiguration . Add ( CodeLiteWorkspaceProjectSelected ) ;
2015-09-24 12:37:21 -04:00
foreach ( var CurProject in AllProjectFiles )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
var ProjectExtension = CurProject . ProjectFilePath . GetExtension ( ) ;
2015-07-14 18:17:55 -04:00
//
// TODO For now ignore C# project files.
//
2015-09-24 12:37:21 -04:00
if ( ProjectExtension = = ".csproj" )
2015-07-14 18:17:55 -04:00
{
continue ;
}
2015-09-24 12:37:21 -04:00
foreach ( ProjectTarget target in CurProject . ProjectTargets )
2015-07-14 18:17:55 -04:00
{
2015-09-24 12:37:21 -04:00
string [ ] tmp = target . ToString ( ) . Split ( '.' ) ;
String ProjectName = tmp [ 0 ] ;
2015-07-14 18:17:55 -04:00
XElement CodeLiteWorkspaceBuildMatrixConfigurationProject = new XElement ( "Project" ) ;
XAttribute CodeLiteWorkspaceBuildMatrixConfigurationProjectName = new XAttribute ( "Name" , ProjectName ) ;
XAttribute CodeLiteWorkspaceBuildMatrixConfigurationProjectConfigName = new XAttribute ( "ConfigName" , CurConfiguration . ToString ( ) ) ;
CodeLiteWorkspaceBuildMatrixConfigurationProject . Add ( CodeLiteWorkspaceBuildMatrixConfigurationProjectName ) ;
CodeLiteWorkspaceBuildMatrixConfigurationProject . Add ( CodeLiteWorkspaceBuildMatrixConfigurationProjectConfigName ) ;
CodeLiteWorkspaceBuildMatrixConfiguration . Add ( CodeLiteWorkspaceBuildMatrixConfigurationProject ) ;
}
}
CodeLiteWorkspaceBuildMatrix . Add ( CodeLiteWorkspaceBuildMatrixConfiguration ) ;
}
}
CodeLiteWorkspace . Add ( CodeLiteWorkspaceBuildMatrix ) ;
CodeLiteWorkspace . Save ( FullCodeLiteMasterFile ) ;
return true ;
}
2015-09-24 12:37:21 -04:00
protected override ProjectFile AllocateProjectFile ( FileReference InitFilePath )
2015-07-14 18:17:55 -04:00
{
2015-09-24 12:37:21 -04:00
return new CodeLiteProject ( InitFilePath , OnlyGameProject ) ;
2015-07-14 18:17:55 -04:00
}
2015-09-24 12:37:21 -04:00
public override MasterProjectFolder AllocateMasterProjectFolder ( ProjectFileGenerator InitOwnerProjectFileGenerator , string InitFolderName )
2015-07-14 18:17:55 -04:00
{
2015-09-24 12:37:21 -04:00
return new CodeLiteFolder ( InitOwnerProjectFileGenerator , InitFolderName ) ;
2015-07-14 18:17:55 -04:00
}
2015-09-03 08:47:24 -04:00
public override void CleanProjectFiles ( DirectoryReference InMasterProjectDirectory , string InMasterProjectName , DirectoryReference InIntermediateProjectFilesDirectory )
2015-07-14 18:17:55 -04:00
{
// TODO Delete all files here. Not finished yet.
var SolutionFileName = InMasterProjectName + SolutionExtension ;
var CodeCompletionFile = InMasterProjectName + CodeCompletionFileName ;
var CodeCompletionPreProcessorFile = InMasterProjectName + CodeCompletionPreProcessorFileName ;
2015-09-03 08:47:24 -04:00
FileReference FullCodeLiteMasterFile = FileReference . Combine ( InMasterProjectDirectory , SolutionFileName ) ;
FileReference FullCodeLiteCodeCompletionFile = FileReference . Combine ( InMasterProjectDirectory , CodeCompletionFile ) ;
FileReference FullCodeLiteCodeCompletionPreProcessorFile = FileReference . Combine ( InMasterProjectDirectory , CodeCompletionPreProcessorFile ) ;
2015-07-14 18:17:55 -04:00
2015-09-03 08:47:24 -04:00
if ( FullCodeLiteMasterFile . Exists ( ) )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
FullCodeLiteMasterFile . Delete ( ) ;
2015-07-14 18:17:55 -04:00
}
2015-09-03 08:47:24 -04:00
if ( FullCodeLiteCodeCompletionFile . Exists ( ) )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
FullCodeLiteCodeCompletionFile . Delete ( ) ;
2015-07-14 18:17:55 -04:00
}
2015-09-03 08:47:24 -04:00
if ( FullCodeLiteCodeCompletionPreProcessorFile . Exists ( ) )
2015-07-14 18:17:55 -04:00
{
2015-09-03 08:47:24 -04:00
FullCodeLiteCodeCompletionPreProcessorFile . Delete ( ) ;
2015-07-14 18:17:55 -04:00
}
// Delete the project files folder
2015-09-03 08:47:24 -04:00
if ( InIntermediateProjectFilesDirectory . Exists ( ) )
2015-07-14 18:17:55 -04:00
{
try
{
2015-09-03 08:47:24 -04:00
Directory . Delete ( InIntermediateProjectFilesDirectory . FullName , true ) ;
2015-07-14 18:17:55 -04:00
}
catch ( Exception Ex )
{
2015-09-03 08:47:24 -04:00
Log . TraceInformation ( "Error while trying to clean project files path {0}. Ignored." , InIntermediateProjectFilesDirectory ) ;
2015-07-14 18:17:55 -04:00
Log . TraceInformation ( "\t" + Ex . Message ) ;
}
}
}
}
}