Skip to content

Commit 5bd52e2

Browse files
committed
- Support other linker flags
- Support adding framework bundle (Facebook SDK)
1 parent ae23c0e commit 5bd52e2

File tree

5 files changed

+121
-12
lines changed

5 files changed

+121
-12
lines changed

PBXBuildFile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()
1717

1818
this.Add( FILE_REF_KEY, fileRef.guid );
1919
SetWeakLink( weak );
20-
20+
2121
// def Create(cls, file_ref, weak=False):
2222
// if isinstance(file_ref, PBXFileReference):
2323
// file_ref = file_ref.id
@@ -49,6 +49,7 @@ public bool SetWeakLink( bool weak = false )
4949

5050
settings = new PBXDictionary();
5151
settings.Add( ATTRIBUTES_KEY, attributes );
52+
_data[ SETTINGS_KEY ] = settings;
5253
}
5354
return true;
5455
}

XCBuildConfiguration.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ public class XCBuildConfiguration : PBXObject
88
protected const string BUILDSETTINGS_KEY = "buildSettings";
99
protected const string HEADER_SEARCH_PATHS_KEY = "HEADER_SEARCH_PATHS";
1010
protected const string LIBRARY_SEARCH_PATHS_KEY = "LIBRARY_SEARCH_PATHS";
11+
protected const string FRAMEWORK_SEARCH_PATHS_KEY = "FRAMEWORK_SEARCH_PATHS";
1112
protected const string OTHER_C_FLAGS_KEY = "OTHER_CFLAGS";
12-
13+
protected const string OTHER_LD_FLAGS_KEY = "OTHER_LDFLAGS";
14+
1315
public XCBuildConfiguration( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
1416
{
1517

@@ -41,7 +43,7 @@ protected bool AddSearchPaths( PBXList paths, string key, bool recursive = true
4143
foreach( string path in paths ) {
4244
string currentPath = path;
4345
if( recursive && !path.EndsWith( "/**" ) )
44-
currentPath += "**";
46+
currentPath += "/**";
4547

4648
// Debug.Log( "adding: " + currentPath );
4749
if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( key ) ) {
@@ -73,6 +75,11 @@ public bool AddLibrarySearchPaths( PBXList paths, bool recursive = true )
7375
{
7476
return this.AddSearchPaths( paths, LIBRARY_SEARCH_PATHS_KEY, recursive );
7577
}
78+
79+
public bool AddFrameworkSearchPaths(PBXList paths, bool recursive = true)
80+
{
81+
return this.AddSearchPaths(paths, FRAMEWORK_SEARCH_PATHS_KEY, recursive);
82+
}
7683

7784
public bool AddOtherCFlags( string flag )
7885
{
@@ -110,6 +117,43 @@ public bool AddOtherCFlags( PBXList flags )
110117

111118
return modified;
112119
}
120+
121+
public bool AddOtherLDFlags( string flag )
122+
{
123+
Debug.Log( "INIZIO A" );
124+
PBXList flags = new PBXList();
125+
flags.Add( flag );
126+
return AddOtherLDFlags( flags );
127+
}
128+
129+
public bool AddOtherLDFlags( PBXList flags )
130+
{
131+
Debug.Log( "INIZIO B" );
132+
133+
bool modified = false;
134+
135+
if( !ContainsKey( BUILDSETTINGS_KEY ) )
136+
this.Add( BUILDSETTINGS_KEY, new PBXDictionary() );
137+
138+
foreach( string flag in flags ) {
139+
140+
if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( OTHER_LD_FLAGS_KEY ) ) {
141+
((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( OTHER_LD_FLAGS_KEY, new PBXList() );
142+
}
143+
else if ( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] is string ) {
144+
string tempString = (string)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY];
145+
((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] = new PBXList();
146+
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( tempString );
147+
}
148+
149+
if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Contains( flag ) ) {
150+
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( flag );
151+
modified = true;
152+
}
153+
}
154+
155+
return modified;
156+
}
113157

114158
// class XCBuildConfiguration(PBXType):
115159
// def add_search_paths(self, paths, base, key, recursive=True):

XCMod.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public ArrayList headerpaths {
5656
return (ArrayList)_datastore["headerpaths"];
5757
}
5858
}
59+
60+
public ArrayList linkers {
61+
get {
62+
return (ArrayList)_datastore["linkers"];
63+
}
64+
}
5965

6066
public ArrayList files {
6167
get {

XCProject.cs

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ public XCProject( string filePath ) : this()
7676
this.filePath = projects[ 0 ];
7777
}
7878

79+
// Convert to absolute
80+
this.projectRootPath = Path.GetFullPath(this.projectRootPath);
81+
7982
projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) );
80-
string contents = projectFileInfo.OpenText().ReadToEnd();
83+
StreamReader sr = projectFileInfo.OpenText();
84+
string contents = sr.ReadToEnd();
85+
sr.Close();
8186

8287
PBXParser parser = new PBXParser();
8388
_datastore = parser.Decode( contents );
@@ -239,6 +244,20 @@ public bool AddOtherCFlags( PBXList flags )
239244
modified = true;
240245
return modified;
241246
}
247+
248+
public bool AddOtherLDFlags( string flag )
249+
{
250+
return AddOtherLDFlags( new PBXList( flag ) );
251+
}
252+
253+
public bool AddOtherLDFlags( PBXList flags )
254+
{
255+
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
256+
buildConfig.Value.AddOtherLDFlags( flags );
257+
}
258+
modified = true;
259+
return modified;
260+
}
242261

243262
public bool AddHeaderSearchPaths( string path )
244263
{
@@ -268,6 +287,26 @@ public bool AddLibrarySearchPaths( PBXList paths )
268287
modified = true;
269288
return modified;
270289
}
290+
291+
public bool AddFrameworkSearchPaths(string path)
292+
{
293+
return AddFrameworkSearchPaths(new PBXList(path));
294+
}
295+
296+
public bool AddFrameworkSearchPaths(PBXList paths)
297+
{
298+
foreach (KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations)
299+
{
300+
buildConfig.Value.AddFrameworkSearchPaths(paths);
301+
}
302+
modified = true;
303+
return modified;
304+
}
305+
306+
//FRAMEWORK_SEARCH_PATHS = (
307+
// "$(inherited)",
308+
// "\"$(SRCROOT)/../../../../../../../Documents/FacebookSDK\"",
309+
//);
271310

272311

273312
// public PBXList GetObjectOfType( string type )
@@ -323,7 +362,7 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
323362
Debug.Log( "Missing file: " + filePath );
324363
return results;
325364
}
326-
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
365+
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 || tree.CompareTo( "GROUP" ) == 0 ) {
327366
System.Uri fileURI = new System.Uri( absPath );
328367
System.Uri rootURI = new System.Uri( ( projectRootPath + "/." ) );
329368
filePath = rootURI.MakeRelativeUri( fileURI ).ToString();
@@ -349,7 +388,7 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
349388
parent.AddChild( fileReference );
350389
fileReferences.Add( fileReference );
351390
results.Add( fileReference.guid, fileReference );
352-
391+
353392
//Create a build file for reference
354393
if( !string.IsNullOrEmpty( fileReference.buildPhase ) && createBuildFiles ) {
355394
// PBXDictionary<PBXBuildPhase> currentPhase = GetBuildPhase( fileReference.buildPhase );
@@ -361,9 +400,15 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
361400
buildFiles.Add( buildFile );
362401
currentObject.Value.AddBuildFile( buildFile );
363402
}
364-
if ( !string.IsNullOrEmpty( absPath ) && ( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) && File.Exists( absPath ) ) {
403+
404+
if ( !string.IsNullOrEmpty( absPath ) && File.Exists(absPath) && tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
405+
Debug.LogError(absPath);
365406
string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
366-
this.AddLibrarySearchPaths( new PBXList( libraryPath ) );
407+
this.AddLibrarySearchPaths( new PBXList(libraryPath) );
408+
}
409+
else if (!string.IsNullOrEmpty( absPath ) && Directory.Exists(absPath) && absPath.EndsWith(".framework") && tree.CompareTo("GROUP") == 0) { // Annt: Add framework search path for FacebookSDK
410+
string frameworkPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
411+
this.AddFrameworkSearchPaths(new PBXList(frameworkPath));
367412
}
368413
break;
369414
case "PBXResourcesBuildPhase":
@@ -882,7 +927,12 @@ public void ApplyMod( XCMod mod )
882927
Debug.Log( "Adding files..." );
883928
foreach( string filePath in mod.files ) {
884929
string absoluteFilePath = System.IO.Path.Combine( mod.path, filePath );
885-
this.AddFile( absoluteFilePath, modGroup );
930+
931+
932+
if( filePath.EndsWith(".framework") )
933+
this.AddFile( absoluteFilePath, frameworkGroup, "GROUP", true, false);
934+
else
935+
this.AddFile( absoluteFilePath, modGroup );
886936
}
887937

888938
Debug.Log( "Adding folders..." );
@@ -896,6 +946,14 @@ public void ApplyMod( XCMod mod )
896946
string absoluteHeaderPath = System.IO.Path.Combine( mod.path, headerpath );
897947
this.AddHeaderSearchPaths( absoluteHeaderPath );
898948
}
949+
950+
Debug.Log( "Adding other linker flags..." );
951+
foreach( string linker in mod.linkers ) {
952+
string _linker = linker;
953+
if( !_linker.StartsWith("-") )
954+
_linker = "-" + _linker;
955+
this.AddOtherLDFlags( _linker );
956+
}
899957

900958
this.Consolidate();
901959
}

XCodeEditorMenu.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace UnityEditor.XCodeEditor
99
public class XCodeEditorMenu
1010
{
1111

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

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

2121
//Debug.Log(
2222
// PBXDictionary test = new PBXDictionary();
@@ -62,7 +62,7 @@ static void DebugTest()
6262
}
6363

6464

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

0 commit comments

Comments
 (0)