Skip to content

Commit

Permalink
- Support other linker flags
Browse files Browse the repository at this point in the history
- Support adding framework bundle (Facebook SDK)
  • Loading branch information
beannt committed Jul 22, 2013
1 parent ae23c0e commit 5bd52e2
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 12 deletions.
3 changes: 2 additions & 1 deletion PBXBuildFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()

this.Add( FILE_REF_KEY, fileRef.guid );
SetWeakLink( weak );

// def Create(cls, file_ref, weak=False):
// if isinstance(file_ref, PBXFileReference):
// file_ref = file_ref.id
Expand Down Expand Up @@ -49,6 +49,7 @@ public bool SetWeakLink( bool weak = false )

settings = new PBXDictionary();
settings.Add( ATTRIBUTES_KEY, attributes );
_data[ SETTINGS_KEY ] = settings;
}
return true;
}
Expand Down
48 changes: 46 additions & 2 deletions XCBuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public class XCBuildConfiguration : PBXObject
protected const string BUILDSETTINGS_KEY = "buildSettings";
protected const string HEADER_SEARCH_PATHS_KEY = "HEADER_SEARCH_PATHS";
protected const string LIBRARY_SEARCH_PATHS_KEY = "LIBRARY_SEARCH_PATHS";
protected const string FRAMEWORK_SEARCH_PATHS_KEY = "FRAMEWORK_SEARCH_PATHS";
protected const string OTHER_C_FLAGS_KEY = "OTHER_CFLAGS";

protected const string OTHER_LD_FLAGS_KEY = "OTHER_LDFLAGS";

public XCBuildConfiguration( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
{

Expand Down Expand Up @@ -41,7 +43,7 @@ protected bool AddSearchPaths( PBXList paths, string key, bool recursive = true
foreach( string path in paths ) {
string currentPath = path;
if( recursive && !path.EndsWith( "/**" ) )
currentPath += "**";
currentPath += "/**";

// Debug.Log( "adding: " + currentPath );
if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( key ) ) {
Expand Down Expand Up @@ -73,6 +75,11 @@ public bool AddLibrarySearchPaths( PBXList paths, bool recursive = true )
{
return this.AddSearchPaths( paths, LIBRARY_SEARCH_PATHS_KEY, recursive );
}

public bool AddFrameworkSearchPaths(PBXList paths, bool recursive = true)
{
return this.AddSearchPaths(paths, FRAMEWORK_SEARCH_PATHS_KEY, recursive);
}

public bool AddOtherCFlags( string flag )
{
Expand Down Expand Up @@ -110,6 +117,43 @@ public bool AddOtherCFlags( PBXList flags )

return modified;
}

public bool AddOtherLDFlags( string flag )
{
Debug.Log( "INIZIO A" );
PBXList flags = new PBXList();
flags.Add( flag );
return AddOtherLDFlags( flags );
}

public bool AddOtherLDFlags( PBXList flags )
{
Debug.Log( "INIZIO B" );

bool modified = false;

if( !ContainsKey( BUILDSETTINGS_KEY ) )
this.Add( BUILDSETTINGS_KEY, new PBXDictionary() );

foreach( string flag in flags ) {

if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( OTHER_LD_FLAGS_KEY ) ) {
((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( OTHER_LD_FLAGS_KEY, new PBXList() );
}
else if ( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] is string ) {
string tempString = (string)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY];
((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] = new PBXList();
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( tempString );
}

if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Contains( flag ) ) {
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( flag );
modified = true;
}
}

return modified;
}

// class XCBuildConfiguration(PBXType):
// def add_search_paths(self, paths, base, key, recursive=True):
Expand Down
6 changes: 6 additions & 0 deletions XCMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public ArrayList headerpaths {
return (ArrayList)_datastore["headerpaths"];
}
}

public ArrayList linkers {
get {
return (ArrayList)_datastore["linkers"];
}
}

public ArrayList files {
get {
Expand Down
70 changes: 64 additions & 6 deletions XCProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ public XCProject( string filePath ) : this()
this.filePath = projects[ 0 ];
}

// Convert to absolute
this.projectRootPath = Path.GetFullPath(this.projectRootPath);

projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) );
string contents = projectFileInfo.OpenText().ReadToEnd();
StreamReader sr = projectFileInfo.OpenText();
string contents = sr.ReadToEnd();
sr.Close();

PBXParser parser = new PBXParser();
_datastore = parser.Decode( contents );
Expand Down Expand Up @@ -239,6 +244,20 @@ public bool AddOtherCFlags( PBXList flags )
modified = true;
return modified;
}

public bool AddOtherLDFlags( string flag )
{
return AddOtherLDFlags( new PBXList( flag ) );
}

public bool AddOtherLDFlags( PBXList flags )
{
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
buildConfig.Value.AddOtherLDFlags( flags );
}
modified = true;
return modified;
}

public bool AddHeaderSearchPaths( string path )
{
Expand Down Expand Up @@ -268,6 +287,26 @@ public bool AddLibrarySearchPaths( PBXList paths )
modified = true;
return modified;
}

public bool AddFrameworkSearchPaths(string path)
{
return AddFrameworkSearchPaths(new PBXList(path));
}

public bool AddFrameworkSearchPaths(PBXList paths)
{
foreach (KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations)
{
buildConfig.Value.AddFrameworkSearchPaths(paths);
}
modified = true;
return modified;
}

//FRAMEWORK_SEARCH_PATHS = (
// "$(inherited)",
// "\"$(SRCROOT)/../../../../../../../Documents/FacebookSDK\"",
//);


// public PBXList GetObjectOfType( string type )
Expand Down Expand Up @@ -323,7 +362,7 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
Debug.Log( "Missing file: " + filePath );
return results;
}
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 || tree.CompareTo( "GROUP" ) == 0 ) {
System.Uri fileURI = new System.Uri( absPath );
System.Uri rootURI = new System.Uri( ( projectRootPath + "/." ) );
filePath = rootURI.MakeRelativeUri( fileURI ).ToString();
Expand All @@ -349,7 +388,7 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
parent.AddChild( fileReference );
fileReferences.Add( fileReference );
results.Add( fileReference.guid, fileReference );

//Create a build file for reference
if( !string.IsNullOrEmpty( fileReference.buildPhase ) && createBuildFiles ) {
// PBXDictionary<PBXBuildPhase> currentPhase = GetBuildPhase( fileReference.buildPhase );
Expand All @@ -361,9 +400,15 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
buildFiles.Add( buildFile );
currentObject.Value.AddBuildFile( buildFile );
}
if ( !string.IsNullOrEmpty( absPath ) && ( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) && File.Exists( absPath ) ) {

if ( !string.IsNullOrEmpty( absPath ) && File.Exists(absPath) && tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
Debug.LogError(absPath);
string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
this.AddLibrarySearchPaths( new PBXList( libraryPath ) );
this.AddLibrarySearchPaths( new PBXList(libraryPath) );
}
else if (!string.IsNullOrEmpty( absPath ) && Directory.Exists(absPath) && absPath.EndsWith(".framework") && tree.CompareTo("GROUP") == 0) { // Annt: Add framework search path for FacebookSDK
string frameworkPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
this.AddFrameworkSearchPaths(new PBXList(frameworkPath));
}
break;
case "PBXResourcesBuildPhase":
Expand Down Expand Up @@ -882,7 +927,12 @@ public void ApplyMod( XCMod mod )
Debug.Log( "Adding files..." );
foreach( string filePath in mod.files ) {
string absoluteFilePath = System.IO.Path.Combine( mod.path, filePath );
this.AddFile( absoluteFilePath, modGroup );


if( filePath.EndsWith(".framework") )
this.AddFile( absoluteFilePath, frameworkGroup, "GROUP", true, false);
else
this.AddFile( absoluteFilePath, modGroup );
}

Debug.Log( "Adding folders..." );
Expand All @@ -896,6 +946,14 @@ public void ApplyMod( XCMod mod )
string absoluteHeaderPath = System.IO.Path.Combine( mod.path, headerpath );
this.AddHeaderSearchPaths( absoluteHeaderPath );
}

Debug.Log( "Adding other linker flags..." );
foreach( string linker in mod.linkers ) {
string _linker = linker;
if( !_linker.StartsWith("-") )
_linker = "-" + _linker;
this.AddOtherLDFlags( _linker );
}

this.Consolidate();
}
Expand Down
6 changes: 3 additions & 3 deletions XCodeEditorMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace UnityEditor.XCodeEditor
public class XCodeEditorMenu
{

[MenuItem ("Build Tools/XCode Editor/DebugTest %t")]
//[MenuItem ("Build Tools/XCode Editor/DebugTest %t")]
static void DebugTest()
{
string projectPath = Path.Combine( Directory.GetParent( Application.dataPath ).ToString(), "XCode" );
// Debug.Log( "XcodePath: " + projectPath );

// XCProject currentProject = new XCProject( projectPath );
XCProject.ApplyMod( projectPath, "/Users/Elyn/Projects/UnityPlugins/Unity Sandbox Project/Assets/Modules/GameCenter/Editor/iOS/GameCenter.projmods" );
//XCProject.ApplyMod( projectPath, "/Users/Elyn/Projects/UnityPlugins/Unity Sandbox Project/Assets/Modules/GameCenter/Editor/iOS/GameCenter.projmods" );

//Debug.Log(
// PBXDictionary test = new PBXDictionary();
Expand Down Expand Up @@ -62,7 +62,7 @@ static void DebugTest()
}


[MenuItem ("Build Tools/XCode Editor/DebugTest2 %y")]
//[MenuItem ("Build Tools/XCode Editor/DebugTest2 %y")]
static void DebugTest2()
{
string path1 = "/Users/Elyn/Projects/UnityPlugins/Unity Sandbox Project/Assets/Modules/GameCenter/Editor/iOS/GameCenterManager.m";
Expand Down

0 comments on commit 5bd52e2

Please sign in to comment.