Skip to content

Commit 7592764

Browse files
committed
Complete PBX structure.
TODO: convert pbxlist to generic
1 parent 21ed82e commit 7592764

21 files changed

+840
-283
lines changed

PBXBuildFile.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace UnityEditor.XCodeEditor
6+
{
7+
public class PBXBuildFile : PBXType
8+
{
9+
const string SETTINGS_KEY = "settings";
10+
const string ATTRIBUTES_KEY = "ATTRIBUTES";
11+
const string WEAK_VALUE = "Weak";
12+
const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
13+
14+
public PBXBuildFile( string fileRef, bool weak = false ) : base()
15+
{
16+
17+
// def Create(cls, file_ref, weak=False):
18+
// if isinstance(file_ref, PBXFileReference):
19+
// file_ref = file_ref.id
20+
//
21+
// bf = cls()
22+
// bf.id = cls.GenerateId()
23+
// bf['fileRef'] = file_ref
24+
//
25+
// if weak:
26+
// bf.set_weak_link(True)
27+
//
28+
// return bf
29+
}
30+
31+
32+
public bool SetWeakLink( bool weak = false )
33+
{
34+
PBXDictionary settings = this[SETTINGS_KEY] as PBXDictionary;
35+
PBXList attributes = null;
36+
37+
if( settings == null ) {
38+
if( weak ) {
39+
attributes = new PBXList();
40+
attributes.Add( WEAK_VALUE );
41+
42+
settings = new PBXDictionary();
43+
settings.Add( ATTRIBUTES_KEY, attributes );
44+
}
45+
return true;
46+
}
47+
48+
attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
49+
if( attributes == null ) {
50+
if( weak ) {
51+
attributes = new PBXList();
52+
}
53+
else {
54+
return false;
55+
}
56+
}
57+
58+
if( weak ) {
59+
attributes.Add( WEAK_VALUE );
60+
}
61+
else {
62+
attributes.Remove( WEAK_VALUE );
63+
}
64+
65+
settings.Add( ATTRIBUTES_KEY, attributes );
66+
this.Add( SETTINGS_KEY, settings );
67+
68+
return true;
69+
}
70+
71+
public bool AddCompilerFlag( string flag )
72+
{
73+
// if( !this.ContainsKey( SETTINGS_KEY ) )
74+
// this[ SETTINGS_KEY ] = new PBXDictionary();
75+
//
76+
// if( !(PBXDictionary)this[ SETTINGS_KEY ]
77+
78+
return false;
79+
80+
// def add_compiler_flag(self, flag):
81+
// k_settings = 'settings'
82+
// k_attributes = 'COMPILER_FLAGS'
83+
//
84+
// if not self.has_key(k_settings):
85+
// self[k_settings] = PBXDict()
86+
//
87+
// if not self[k_settings].has_key(k_attributes):
88+
// self[k_settings][k_attributes] = flag
89+
// return True
90+
//
91+
// flags = self[k_settings][k_attributes].split(' ')
92+
//
93+
// if flag in flags:
94+
// return False
95+
//
96+
// flags.append(flag)
97+
//
98+
// self[k_settings][k_attributes] = ' '.join(flags)
99+
}
100+
101+
}
102+
}

XCGroup.cs.meta renamed to PBXBuildFile.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PBXBuildPhase.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace UnityEditor.XCodeEditor
6+
{
7+
public class PBXBuildPhase : PBXType
8+
{
9+
protected const string FILES_KEY = "files";
10+
11+
public bool AddBuildFile( PBXBuildFile file )
12+
{
13+
if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
14+
return false;
15+
16+
if( !ContainsKey( FILES_KEY ) )
17+
this.Add( FILES_KEY, new PBXList() );
18+
19+
((PBXList)this[ FILES_KEY ]).Add( file.id );
20+
return true;
21+
}
22+
23+
public void RemoveBuildFile( string id )
24+
{
25+
if( !ContainsKey( FILES_KEY ) ) {
26+
this.Add( FILES_KEY, new PBXList() );
27+
return;
28+
}
29+
30+
((PBXList)this[ FILES_KEY ]).Remove( id );
31+
}
32+
33+
public bool HasBuildFile( string id )
34+
{
35+
if( !ContainsKey( FILES_KEY ) ) {
36+
this.Add( FILES_KEY, new PBXList() );
37+
return false;
38+
}
39+
40+
if( !IsGuid( id ) )
41+
return false;
42+
43+
return ((PBXList)this[ FILES_KEY ]).Contains( id );
44+
}
45+
46+
// class PBXBuildPhase(PBXType):
47+
// def add_build_file(self, bf):
48+
// if bf.get('isa') != 'PBXBuildFile':
49+
// return False
50+
//
51+
// if not self.has_key('files'):
52+
// self['files'] = PBXList()
53+
//
54+
// self['files'].add(bf.id)
55+
//
56+
// return True
57+
//
58+
// def remove_build_file(self, id):
59+
// if not self.has_key('files'):
60+
// self['files'] = PBXList()
61+
// return
62+
//
63+
// self['files'].remove(id)
64+
//
65+
// def has_build_file(self, id):
66+
// if not self.has_key('files'):
67+
// self['files'] = PBXList()
68+
// return False
69+
//
70+
// if not PBXType.IsGuid(id):
71+
// id = id.id
72+
//
73+
// return id in self['files']
74+
}
75+
76+
public class PBXFrameworksBuildPhase : PBXBuildPhase
77+
{
78+
79+
}
80+
81+
public class PBXResourcesBuildPhase : PBXBuildPhase
82+
{
83+
84+
}
85+
86+
public class PBXShellScriptBuildPhase : PBXBuildPhase
87+
{
88+
89+
}
90+
91+
public class PBXSourcesBuildPhase : PBXBuildPhase
92+
{
93+
94+
}
95+
96+
public class PBXCopyFilesBuildPhase : PBXBuildPhase
97+
{
98+
99+
}
100+
}

PBXBuildPhase.cs.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PBXDictionary.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace UnityEditor.XCodeEditor
6+
{
7+
public class PBXDictionary : Dictionary<string, object>
8+
{
9+
10+
}
11+
}

PBXDictionary.cs.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PBXFileReference.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace UnityEditor.XCodeEditor
6+
{
7+
public class PBXFileReference : PBXType
8+
{
9+
public string buildPhase;
10+
public readonly Dictionary<string, string> types = new Dictionary<string, string> {
11+
{"a", "archive.ar" }
12+
// {".a", {"archive.ar", "PBXFrameworksBuildPhase"}},
13+
// {".app", {"wrapper.application", null }}
14+
};
15+
// '.a':('archive.ar', 'PBXFrameworksBuildPhase'),
16+
// '.app': ('wrapper.application', None),
17+
// '.s': ('sourcecode.asm', 'PBXSourcesBuildPhase'),
18+
// '.c': ('sourcecode.c.c', 'PBXSourcesBuildPhase'),
19+
// '.cpp': ('sourcecode.cpp.cpp', 'PBXSourcesBuildPhase'),
20+
// '.framework': ('wrapper.framework','PBXFrameworksBuildPhase'),
21+
// '.h': ('sourcecode.c.h', None),
22+
// '.icns': ('image.icns','PBXResourcesBuildPhase'),
23+
// '.m': ('sourcecode.c.objc', 'PBXSourcesBuildPhase'),
24+
// '.mm': ('sourcecode.cpp.objcpp', 'PBXSourcesBuildPhase'),
25+
// '.nib': ('wrapper.nib', 'PBXResourcesBuildPhase'),
26+
// '.plist': ('text.plist.xml', 'PBXResourcesBuildPhase'),
27+
// '.png': ('image.png', 'PBXResourcesBuildPhase'),
28+
// '.rtf': ('text.rtf', 'PBXResourcesBuildPhase'),
29+
// '.tiff': ('image.tiff', 'PBXResourcesBuildPhase'),
30+
// '.txt': ('text', 'PBXResourcesBuildPhase'),
31+
// '.xcodeproj': ('wrapper.pb-project', None),
32+
// '.xib': ('file.xib', 'PBXResourcesBuildPhase'),
33+
// '.strings': ('text.plist.strings', 'PBXResourcesBuildPhase'),
34+
// '.bundle': ('wrapper.plug-in', 'PBXResourcesBuildPhase'),
35+
// '.dylib': ('compiled.mach-o.dylib', 'PBXFrameworksBuildPhase')
36+
// }
37+
38+
public PBXFileReference() : base()
39+
{
40+
41+
}
42+
43+
// class PBXFileReference(PBXType):
44+
// def __init__(self, d=None):
45+
// PBXType.__init__(self, d)
46+
// self.build_phase = None
47+
//
48+
// types = {
49+
// '.a':('archive.ar', 'PBXFrameworksBuildPhase'),
50+
// '.app': ('wrapper.application', None),
51+
// '.s': ('sourcecode.asm', 'PBXSourcesBuildPhase'),
52+
// '.c': ('sourcecode.c.c', 'PBXSourcesBuildPhase'),
53+
// '.cpp': ('sourcecode.cpp.cpp', 'PBXSourcesBuildPhase'),
54+
// '.framework': ('wrapper.framework','PBXFrameworksBuildPhase'),
55+
// '.h': ('sourcecode.c.h', None),
56+
// '.icns': ('image.icns','PBXResourcesBuildPhase'),
57+
// '.m': ('sourcecode.c.objc', 'PBXSourcesBuildPhase'),
58+
// '.mm': ('sourcecode.cpp.objcpp', 'PBXSourcesBuildPhase'),
59+
// '.nib': ('wrapper.nib', 'PBXResourcesBuildPhase'),
60+
// '.plist': ('text.plist.xml', 'PBXResourcesBuildPhase'),
61+
// '.png': ('image.png', 'PBXResourcesBuildPhase'),
62+
// '.rtf': ('text.rtf', 'PBXResourcesBuildPhase'),
63+
// '.tiff': ('image.tiff', 'PBXResourcesBuildPhase'),
64+
// '.txt': ('text', 'PBXResourcesBuildPhase'),
65+
// '.xcodeproj': ('wrapper.pb-project', None),
66+
// '.xib': ('file.xib', 'PBXResourcesBuildPhase'),
67+
// '.strings': ('text.plist.strings', 'PBXResourcesBuildPhase'),
68+
// '.bundle': ('wrapper.plug-in', 'PBXResourcesBuildPhase'),
69+
// '.dylib': ('compiled.mach-o.dylib', 'PBXFrameworksBuildPhase')
70+
// }
71+
//
72+
// trees = [
73+
// '<absolute>',
74+
// '<group>',
75+
// 'BUILT_PRODUCTS_DIR',
76+
// 'DEVELOPER_DIR',
77+
// 'SDKROOT',
78+
// 'SOURCE_ROOT',
79+
// ]
80+
//
81+
// def guess_file_type(self):
82+
// self.remove('explicitFileType')
83+
// self.remove('lastKnownFileType')
84+
// ext = os.path.splitext(self.get('name', ''))[1]
85+
//
86+
// f_type, build_phase = PBXFileReference.types.get(ext, ('?', None))
87+
//
88+
// self['lastKnownFileType'] = f_type
89+
// self.build_phase = build_phase
90+
//
91+
// if f_type == '?':
92+
// print 'unknown file extension: %s' % ext
93+
// print 'please add extension and Xcode type to PBXFileReference.types'
94+
//
95+
// return f_type
96+
//
97+
// def set_file_type(self, ft):
98+
// self.remove('explicitFileType')
99+
// self.remove('lastKnownFileType')
100+
//
101+
// self['explicitFileType'] = ft
102+
//
103+
// @classmethod
104+
// def Create(cls, os_path, tree='SOURCE_ROOT'):
105+
// if tree not in cls.trees:
106+
// print 'Not a valid sourceTree type: %s' % tree
107+
// return None
108+
//
109+
// fr = cls()
110+
// fr.id = cls.GenerateId()
111+
// fr['path'] = os_path
112+
// fr['name'] = os.path.split(os_path)[1]
113+
// fr['sourceTree'] = '<absolute>' if os.path.isabs(os_path) else tree
114+
// fr.guess_file_type()
115+
//
116+
// return fr
117+
}
118+
}

PBXFileReference.cs.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)