Skip to content

Commit 529948b

Browse files
committed
Merge pull request dcariola#5 from beannt/master
Merging from beannt/master: Support more feartures and sample
2 parents ae23c0e + 8bf7f5b commit 529948b

File tree

8 files changed

+951
-24
lines changed

8 files changed

+951
-24
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: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ 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+
protected const string GCC_ENABLE_CPP_EXCEPTIONS_KEY = "GCC_ENABLE_CPP_EXCEPTIONS";
15+
protected const string GCC_ENABLE_OBJC_EXCEPTIONS_KEY = "GCC_ENABLE_OBJC_EXCEPTIONS";
16+
1317
public XCBuildConfiguration( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
1418
{
1519

@@ -41,7 +45,7 @@ protected bool AddSearchPaths( PBXList paths, string key, bool recursive = true
4145
foreach( string path in paths ) {
4246
string currentPath = path;
4347
if( recursive && !path.EndsWith( "/**" ) )
44-
currentPath += "**";
48+
currentPath += "/**";
4549

4650
// Debug.Log( "adding: " + currentPath );
4751
if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( key ) ) {
@@ -73,18 +77,23 @@ public bool AddLibrarySearchPaths( PBXList paths, bool recursive = true )
7377
{
7478
return this.AddSearchPaths( paths, LIBRARY_SEARCH_PATHS_KEY, recursive );
7579
}
80+
81+
public bool AddFrameworkSearchPaths(PBXList paths, bool recursive = true)
82+
{
83+
return this.AddSearchPaths(paths, FRAMEWORK_SEARCH_PATHS_KEY, recursive);
84+
}
7685

7786
public bool AddOtherCFlags( string flag )
7887
{
79-
Debug.Log( "INIZIO 1" );
88+
//Debug.Log( "INIZIO 1" );
8089
PBXList flags = new PBXList();
8190
flags.Add( flag );
8291
return AddOtherCFlags( flags );
8392
}
8493

8594
public bool AddOtherCFlags( PBXList flags )
8695
{
87-
Debug.Log( "INIZIO 2" );
96+
//Debug.Log( "INIZIO 2" );
8897

8998
bool modified = false;
9099

@@ -110,6 +119,61 @@ public bool AddOtherCFlags( PBXList flags )
110119

111120
return modified;
112121
}
122+
123+
public bool AddOtherLDFlags( string flag )
124+
{
125+
//Debug.Log( "INIZIO A" );
126+
PBXList flags = new PBXList();
127+
flags.Add( flag );
128+
return AddOtherLDFlags( flags );
129+
}
130+
131+
public bool AddOtherLDFlags( PBXList flags )
132+
{
133+
//Debug.Log( "INIZIO B" );
134+
135+
bool modified = false;
136+
137+
if( !ContainsKey( BUILDSETTINGS_KEY ) )
138+
this.Add( BUILDSETTINGS_KEY, new PBXDictionary() );
139+
140+
foreach( string flag in flags ) {
141+
142+
if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( OTHER_LD_FLAGS_KEY ) ) {
143+
((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( OTHER_LD_FLAGS_KEY, new PBXList() );
144+
}
145+
else if ( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] is string ) {
146+
string tempString = (string)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY];
147+
((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] = new PBXList();
148+
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( tempString );
149+
}
150+
151+
if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Contains( flag ) ) {
152+
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( flag );
153+
modified = true;
154+
}
155+
}
156+
157+
return modified;
158+
}
159+
160+
public bool GccEnableCppExceptions (string value)
161+
{
162+
if (!ContainsKey (BUILDSETTINGS_KEY))
163+
this.Add (BUILDSETTINGS_KEY, new PBXDictionary ());
164+
165+
((PBXDictionary)_data [BUILDSETTINGS_KEY])[GCC_ENABLE_CPP_EXCEPTIONS_KEY] = value;
166+
return true;
167+
}
168+
169+
public bool GccEnableObjCExceptions (string value)
170+
{
171+
if (!ContainsKey (BUILDSETTINGS_KEY))
172+
this.Add (BUILDSETTINGS_KEY, new PBXDictionary ());
173+
174+
((PBXDictionary)_data [BUILDSETTINGS_KEY])[GCC_ENABLE_OBJC_EXCEPTIONS_KEY] = value;
175+
return true;
176+
}
113177

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

XCMod.cs

Lines changed: 7 additions & 1 deletion
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 Hashtable buildSettings {
61+
get {
62+
return (Hashtable)_datastore["buildSettings"];
63+
}
64+
}
5965

6066
public ArrayList files {
6167
get {
@@ -86,7 +92,7 @@ public XCMod( string filename )
8692
path = System.IO.Path.GetDirectoryName( filename );
8793

8894
string contents = projectFileInfo.OpenText().ReadToEnd();
89-
_datastore = (Hashtable)MiniJSON.jsonDecode( contents );
95+
_datastore = (Hashtable)XMiniJSON.jsonDecode( contents );
9096

9197
// group = (string)_datastore["group"];
9298
// patches = (ArrayList)_datastore["patches"];

XCProject.cs

Lines changed: 112 additions & 15 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,7 +244,39 @@ 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+
}
242252

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+
}
261+
262+
public bool GccEnableCppExceptions (string value)
263+
{
264+
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
265+
buildConfig.Value.GccEnableCppExceptions( value );
266+
}
267+
modified = true;
268+
return modified;
269+
}
270+
271+
public bool GccEnableObjCExceptions (string value)
272+
{
273+
foreach( KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations ) {
274+
buildConfig.Value.GccEnableObjCExceptions( value );
275+
}
276+
modified = true;
277+
return modified;
278+
}
279+
243280
public bool AddHeaderSearchPaths( string path )
244281
{
245282
return AddHeaderSearchPaths( new PBXList( path ) );
@@ -268,6 +305,26 @@ public bool AddLibrarySearchPaths( PBXList paths )
268305
modified = true;
269306
return modified;
270307
}
308+
309+
public bool AddFrameworkSearchPaths(string path)
310+
{
311+
return AddFrameworkSearchPaths(new PBXList(path));
312+
}
313+
314+
public bool AddFrameworkSearchPaths(PBXList paths)
315+
{
316+
foreach (KeyValuePair<string, XCBuildConfiguration> buildConfig in buildConfigurations)
317+
{
318+
buildConfig.Value.AddFrameworkSearchPaths(paths);
319+
}
320+
modified = true;
321+
return modified;
322+
}
323+
324+
//FRAMEWORK_SEARCH_PATHS = (
325+
// "$(inherited)",
326+
// "\"$(SRCROOT)/../../../../../../../Documents/FacebookSDK\"",
327+
//);
271328

272329

273330
// public PBXList GetObjectOfType( string type )
@@ -315,15 +372,15 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
315372
// Debug.Log( "Is rooted: " + absPath );
316373
}
317374
else if( tree.CompareTo( "SDKROOT" ) != 0) {
318-
absPath = Path.Combine( Application.dataPath, filePath );
375+
absPath = Path.Combine( Application.dataPath.Replace("Assets", ""), filePath );
319376
// Debug.Log( "RElative: " + absPath );
320377
}
321378

322379
if( !( File.Exists( absPath ) || Directory.Exists( absPath ) ) && tree.CompareTo( "SDKROOT" ) != 0 ) {
323-
Debug.Log( "Missing file: " + filePath );
380+
Debug.Log( "Missing file: " + absPath + " > " + filePath );
324381
return results;
325382
}
326-
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
383+
else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 || tree.CompareTo( "GROUP" ) == 0 ) {
327384
System.Uri fileURI = new System.Uri( absPath );
328385
System.Uri rootURI = new System.Uri( ( projectRootPath + "/." ) );
329386
filePath = rootURI.MakeRelativeUri( fileURI ).ToString();
@@ -349,7 +406,7 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
349406
parent.AddChild( fileReference );
350407
fileReferences.Add( fileReference );
351408
results.Add( fileReference.guid, fileReference );
352-
409+
353410
//Create a build file for reference
354411
if( !string.IsNullOrEmpty( fileReference.buildPhase ) && createBuildFiles ) {
355412
// PBXDictionary<PBXBuildPhase> currentPhase = GetBuildPhase( fileReference.buildPhase );
@@ -361,9 +418,15 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
361418
buildFiles.Add( buildFile );
362419
currentObject.Value.AddBuildFile( buildFile );
363420
}
364-
if ( !string.IsNullOrEmpty( absPath ) && ( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) && File.Exists( absPath ) ) {
421+
422+
if ( !string.IsNullOrEmpty( absPath ) && File.Exists(absPath) && tree.CompareTo( "SOURCE_ROOT" ) == 0 ) {
423+
//Debug.LogError(absPath);
365424
string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
366-
this.AddLibrarySearchPaths( new PBXList( libraryPath ) );
425+
this.AddLibrarySearchPaths( new PBXList(libraryPath) );
426+
}
427+
else if (!string.IsNullOrEmpty( absPath ) && Directory.Exists(absPath) && absPath.EndsWith(".framework") && tree.CompareTo("GROUP") == 0) { // Annt: Add framework search path for FacebookSDK
428+
string frameworkPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
429+
this.AddFrameworkSearchPaths(new PBXList(frameworkPath));
367430
}
368431
break;
369432
case "PBXResourcesBuildPhase":
@@ -464,9 +527,10 @@ public bool AddFolder( string folderPath, PBXGroup parent = null, string[] exclu
464527
if( !Directory.Exists( folderPath ) )
465528
return false;
466529
DirectoryInfo sourceDirectoryInfo = new DirectoryInfo( folderPath );
467-
530+
468531
if( exclude == null )
469532
exclude = new string[] {};
533+
string regexExclude = string.Format( @"{0}", string.Join( "|", exclude ) );
470534

471535
PBXDictionary results = new PBXDictionary();
472536

@@ -479,6 +543,10 @@ public bool AddFolder( string folderPath, PBXGroup parent = null, string[] exclu
479543

480544
foreach( string directory in Directory.GetDirectories( folderPath ) )
481545
{
546+
if( Regex.IsMatch( directory, regexExclude ) ) {
547+
continue;
548+
}
549+
482550
// special_folders = ['.bundle', '.framework', '.xcodeproj']
483551
Debug.Log( "DIR: " + directory );
484552
if( directory.EndsWith( ".bundle" ) ) {
@@ -494,18 +562,15 @@ public bool AddFolder( string folderPath, PBXGroup parent = null, string[] exclu
494562
AddFolder( directory, newGroup, exclude, recursive, createBuildFile );
495563
}
496564
}
497-
498565
// Adding files.
499-
string regexExclude = string.Format( @"{0}", string.Join( "|", exclude ) );
500566
foreach( string file in Directory.GetFiles( folderPath ) ) {
501567
if( Regex.IsMatch( file, regexExclude ) ) {
502568
continue;
503569
}
504-
// Debug.Log( "--> " + file + ", " + newGroup );
570+
//Debug.Log( "--> " + file + ", " + newGroup );
505571
AddFile( file, newGroup, "SOURCE_ROOT", createBuildFile );
506572
}
507-
508-
573+
509574
modified = true;
510575
return modified;
511576
// def add_folder(self, os_path, parent=None, excludes=None, recursive=True, create_build_files=True):
@@ -882,7 +947,12 @@ public void ApplyMod( XCMod mod )
882947
Debug.Log( "Adding files..." );
883948
foreach( string filePath in mod.files ) {
884949
string absoluteFilePath = System.IO.Path.Combine( mod.path, filePath );
885-
this.AddFile( absoluteFilePath, modGroup );
950+
951+
952+
if( filePath.EndsWith(".framework") )
953+
this.AddFile( absoluteFilePath, frameworkGroup, "GROUP", true, false);
954+
else
955+
this.AddFile( absoluteFilePath, modGroup );
886956
}
887957

888958
Debug.Log( "Adding folders..." );
@@ -896,7 +966,34 @@ public void ApplyMod( XCMod mod )
896966
string absoluteHeaderPath = System.IO.Path.Combine( mod.path, headerpath );
897967
this.AddHeaderSearchPaths( absoluteHeaderPath );
898968
}
899-
969+
970+
Debug.Log( "Configure build settings..." );
971+
Hashtable buildSettings = mod.buildSettings;
972+
if( buildSettings.ContainsKey("OTHER_LDFLAGS") )
973+
{
974+
Debug.Log( " Adding other linker flags..." );
975+
ArrayList otherLinkerFlags = (ArrayList) buildSettings["OTHER_LDFLAGS"];
976+
foreach( string linker in otherLinkerFlags )
977+
{
978+
string _linker = linker;
979+
if( !_linker.StartsWith("-") )
980+
_linker = "-" + _linker;
981+
this.AddOtherLDFlags( _linker );
982+
}
983+
}
984+
985+
if( buildSettings.ContainsKey("GCC_ENABLE_CPP_EXCEPTIONS") )
986+
{
987+
Debug.Log( " GCC_ENABLE_CPP_EXCEPTIONS = " + buildSettings["GCC_ENABLE_CPP_EXCEPTIONS"] );
988+
this.GccEnableCppExceptions( (string) buildSettings["GCC_ENABLE_CPP_EXCEPTIONS"] );
989+
}
990+
991+
if( buildSettings.ContainsKey("GCC_ENABLE_OBJC_EXCEPTIONS") )
992+
{
993+
Debug.Log( " GCC_ENABLE_OBJC_EXCEPTIONS = " + buildSettings["GCC_ENABLE_OBJC_EXCEPTIONS"] );
994+
this.GccEnableObjCExceptions( (string) buildSettings["GCC_ENABLE_OBJC_EXCEPTIONS"] );
995+
}
996+
900997
this.Consolidate();
901998
}
902999

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)