Skip to content

Commit

Permalink
Complete PBX structure.
Browse files Browse the repository at this point in the history
TODO: convert pbxlist to generic
  • Loading branch information
dcariola committed Sep 21, 2012
1 parent 21ed82e commit 7592764
Show file tree
Hide file tree
Showing 21 changed files with 840 additions and 283 deletions.
102 changes: 102 additions & 0 deletions PBXBuildFile.cs
@@ -0,0 +1,102 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UnityEditor.XCodeEditor
{
public class PBXBuildFile : PBXType
{
const string SETTINGS_KEY = "settings";
const string ATTRIBUTES_KEY = "ATTRIBUTES";
const string WEAK_VALUE = "Weak";
const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";

public PBXBuildFile( string fileRef, bool weak = false ) : base()
{

// def Create(cls, file_ref, weak=False):
// if isinstance(file_ref, PBXFileReference):
// file_ref = file_ref.id
//
// bf = cls()
// bf.id = cls.GenerateId()
// bf['fileRef'] = file_ref
//
// if weak:
// bf.set_weak_link(True)
//
// return bf
}


public bool SetWeakLink( bool weak = false )
{
PBXDictionary settings = this[SETTINGS_KEY] as PBXDictionary;
PBXList attributes = null;

if( settings == null ) {
if( weak ) {
attributes = new PBXList();
attributes.Add( WEAK_VALUE );

settings = new PBXDictionary();
settings.Add( ATTRIBUTES_KEY, attributes );
}
return true;
}

attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
if( attributes == null ) {
if( weak ) {
attributes = new PBXList();
}
else {
return false;
}
}

if( weak ) {
attributes.Add( WEAK_VALUE );
}
else {
attributes.Remove( WEAK_VALUE );
}

settings.Add( ATTRIBUTES_KEY, attributes );
this.Add( SETTINGS_KEY, settings );

return true;
}

public bool AddCompilerFlag( string flag )
{
// if( !this.ContainsKey( SETTINGS_KEY ) )
// this[ SETTINGS_KEY ] = new PBXDictionary();
//
// if( !(PBXDictionary)this[ SETTINGS_KEY ]

return false;

// def add_compiler_flag(self, flag):
// k_settings = 'settings'
// k_attributes = 'COMPILER_FLAGS'
//
// if not self.has_key(k_settings):
// self[k_settings] = PBXDict()
//
// if not self[k_settings].has_key(k_attributes):
// self[k_settings][k_attributes] = flag
// return True
//
// flags = self[k_settings][k_attributes].split(' ')
//
// if flag in flags:
// return False
//
// flags.append(flag)
//
// self[k_settings][k_attributes] = ' '.join(flags)
}

}
}
2 changes: 1 addition & 1 deletion XCGroup.cs.meta → PBXBuildFile.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions PBXBuildPhase.cs
@@ -0,0 +1,100 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UnityEditor.XCodeEditor
{
public class PBXBuildPhase : PBXType
{
protected const string FILES_KEY = "files";

public bool AddBuildFile( PBXBuildFile file )
{
if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
return false;

if( !ContainsKey( FILES_KEY ) )
this.Add( FILES_KEY, new PBXList() );

((PBXList)this[ FILES_KEY ]).Add( file.id );
return true;
}

public void RemoveBuildFile( string id )
{
if( !ContainsKey( FILES_KEY ) ) {
this.Add( FILES_KEY, new PBXList() );
return;
}

((PBXList)this[ FILES_KEY ]).Remove( id );
}

public bool HasBuildFile( string id )
{
if( !ContainsKey( FILES_KEY ) ) {
this.Add( FILES_KEY, new PBXList() );
return false;
}

if( !IsGuid( id ) )
return false;

return ((PBXList)this[ FILES_KEY ]).Contains( id );
}

// class PBXBuildPhase(PBXType):
// def add_build_file(self, bf):
// if bf.get('isa') != 'PBXBuildFile':
// return False
//
// if not self.has_key('files'):
// self['files'] = PBXList()
//
// self['files'].add(bf.id)
//
// return True
//
// def remove_build_file(self, id):
// if not self.has_key('files'):
// self['files'] = PBXList()
// return
//
// self['files'].remove(id)
//
// def has_build_file(self, id):
// if not self.has_key('files'):
// self['files'] = PBXList()
// return False
//
// if not PBXType.IsGuid(id):
// id = id.id
//
// return id in self['files']
}

public class PBXFrameworksBuildPhase : PBXBuildPhase
{

}

public class PBXResourcesBuildPhase : PBXBuildPhase
{

}

public class PBXShellScriptBuildPhase : PBXBuildPhase
{

}

public class PBXSourcesBuildPhase : PBXBuildPhase
{

}

public class PBXCopyFilesBuildPhase : PBXBuildPhase
{

}
}
7 changes: 7 additions & 0 deletions PBXBuildPhase.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions PBXDictionary.cs
@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UnityEditor.XCodeEditor
{
public class PBXDictionary : Dictionary<string, object>
{

}
}
7 changes: 7 additions & 0 deletions PBXDictionary.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions PBXFileReference.cs
@@ -0,0 +1,118 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UnityEditor.XCodeEditor
{
public class PBXFileReference : PBXType
{
public string buildPhase;
public readonly Dictionary<string, string> types = new Dictionary<string, string> {
{"a", "archive.ar" }
// {".a", {"archive.ar", "PBXFrameworksBuildPhase"}},
// {".app", {"wrapper.application", null }}
};
// '.a':('archive.ar', 'PBXFrameworksBuildPhase'),
// '.app': ('wrapper.application', None),
// '.s': ('sourcecode.asm', 'PBXSourcesBuildPhase'),
// '.c': ('sourcecode.c.c', 'PBXSourcesBuildPhase'),
// '.cpp': ('sourcecode.cpp.cpp', 'PBXSourcesBuildPhase'),
// '.framework': ('wrapper.framework','PBXFrameworksBuildPhase'),
// '.h': ('sourcecode.c.h', None),
// '.icns': ('image.icns','PBXResourcesBuildPhase'),
// '.m': ('sourcecode.c.objc', 'PBXSourcesBuildPhase'),
// '.mm': ('sourcecode.cpp.objcpp', 'PBXSourcesBuildPhase'),
// '.nib': ('wrapper.nib', 'PBXResourcesBuildPhase'),
// '.plist': ('text.plist.xml', 'PBXResourcesBuildPhase'),
// '.png': ('image.png', 'PBXResourcesBuildPhase'),
// '.rtf': ('text.rtf', 'PBXResourcesBuildPhase'),
// '.tiff': ('image.tiff', 'PBXResourcesBuildPhase'),
// '.txt': ('text', 'PBXResourcesBuildPhase'),
// '.xcodeproj': ('wrapper.pb-project', None),
// '.xib': ('file.xib', 'PBXResourcesBuildPhase'),
// '.strings': ('text.plist.strings', 'PBXResourcesBuildPhase'),
// '.bundle': ('wrapper.plug-in', 'PBXResourcesBuildPhase'),
// '.dylib': ('compiled.mach-o.dylib', 'PBXFrameworksBuildPhase')
// }

public PBXFileReference() : base()
{

}

// class PBXFileReference(PBXType):
// def __init__(self, d=None):
// PBXType.__init__(self, d)
// self.build_phase = None
//
// types = {
// '.a':('archive.ar', 'PBXFrameworksBuildPhase'),
// '.app': ('wrapper.application', None),
// '.s': ('sourcecode.asm', 'PBXSourcesBuildPhase'),
// '.c': ('sourcecode.c.c', 'PBXSourcesBuildPhase'),
// '.cpp': ('sourcecode.cpp.cpp', 'PBXSourcesBuildPhase'),
// '.framework': ('wrapper.framework','PBXFrameworksBuildPhase'),
// '.h': ('sourcecode.c.h', None),
// '.icns': ('image.icns','PBXResourcesBuildPhase'),
// '.m': ('sourcecode.c.objc', 'PBXSourcesBuildPhase'),
// '.mm': ('sourcecode.cpp.objcpp', 'PBXSourcesBuildPhase'),
// '.nib': ('wrapper.nib', 'PBXResourcesBuildPhase'),
// '.plist': ('text.plist.xml', 'PBXResourcesBuildPhase'),
// '.png': ('image.png', 'PBXResourcesBuildPhase'),
// '.rtf': ('text.rtf', 'PBXResourcesBuildPhase'),
// '.tiff': ('image.tiff', 'PBXResourcesBuildPhase'),
// '.txt': ('text', 'PBXResourcesBuildPhase'),
// '.xcodeproj': ('wrapper.pb-project', None),
// '.xib': ('file.xib', 'PBXResourcesBuildPhase'),
// '.strings': ('text.plist.strings', 'PBXResourcesBuildPhase'),
// '.bundle': ('wrapper.plug-in', 'PBXResourcesBuildPhase'),
// '.dylib': ('compiled.mach-o.dylib', 'PBXFrameworksBuildPhase')
// }
//
// trees = [
// '<absolute>',
// '<group>',
// 'BUILT_PRODUCTS_DIR',
// 'DEVELOPER_DIR',
// 'SDKROOT',
// 'SOURCE_ROOT',
// ]
//
// def guess_file_type(self):
// self.remove('explicitFileType')
// self.remove('lastKnownFileType')
// ext = os.path.splitext(self.get('name', ''))[1]
//
// f_type, build_phase = PBXFileReference.types.get(ext, ('?', None))
//
// self['lastKnownFileType'] = f_type
// self.build_phase = build_phase
//
// if f_type == '?':
// print 'unknown file extension: %s' % ext
// print 'please add extension and Xcode type to PBXFileReference.types'
//
// return f_type
//
// def set_file_type(self, ft):
// self.remove('explicitFileType')
// self.remove('lastKnownFileType')
//
// self['explicitFileType'] = ft
//
// @classmethod
// def Create(cls, os_path, tree='SOURCE_ROOT'):
// if tree not in cls.trees:
// print 'Not a valid sourceTree type: %s' % tree
// return None
//
// fr = cls()
// fr.id = cls.GenerateId()
// fr['path'] = os_path
// fr['name'] = os.path.split(os_path)[1]
// fr['sourceTree'] = '<absolute>' if os.path.isabs(os_path) else tree
// fr.guess_file_type()
//
// return fr
}
}
7 changes: 7 additions & 0 deletions PBXFileReference.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7592764

Please sign in to comment.