Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions PBX Editor/PBXBuildFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@ public class PBXBuildFile : PBXObject
private const string WEAK_VALUE = "Weak";
private const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";

public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()
public PBXBuildFile( PBXFileReference fileRef, bool weak = false, string[] compilerFlags = null ) : base()
{
this.Add( FILE_REF_KEY, fileRef.guid );
SetWeakLink( weak );

if (!string.IsNullOrEmpty(fileRef.compilerFlags))
{
foreach (var flag in fileRef.compilerFlags.Split(','))
AddCompilerFlag(flag);
}
AddCompilerFlags(compilerFlags);
}

public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
Expand Down Expand Up @@ -68,16 +63,11 @@ public bool SetWeakLink( bool weak = false )
else {
attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
}


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

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

return true;
}
Expand All @@ -104,23 +94,35 @@ public bool AddCodeSignOnCopy()
}


public bool AddCompilerFlag( string flag )
public bool AddCompilerFlags( params string[] flags )
{
if( !_data.ContainsKey( SETTINGS_KEY ) )
_data[ SETTINGS_KEY ] = new PBXDictionary();

if( !((PBXDictionary)_data[ SETTINGS_KEY ]).ContainsKey( COMPILER_FLAGS_KEY ) ) {
((PBXDictionary)_data[ SETTINGS_KEY ]).Add( COMPILER_FLAGS_KEY, flag );
return true;
}
if( flags == null || flags.Length == 0)
return false;

object settingsObject;
PBXDictionary settings;

if( !_data.TryGetValue( SETTINGS_KEY, out settingsObject ) ) {
settings = new PBXDictionary();
_data[ SETTINGS_KEY ] = settings;
} else
settings = settingsObject as PBXDictionary;

string[] flags = ((string)((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ]).Split( ' ' );
foreach( string item in flags ) {
if( item.CompareTo( flag ) == 0 )
return false;
List<string> currentFlags = null;
if( settings.ContainsKey( COMPILER_FLAGS_KEY ) ) {
// merge specified with existing
currentFlags = new List<string>(((string)settings[ COMPILER_FLAGS_KEY ]).Split( ' ' ));

foreach( string flag in flags ) {
if( !currentFlags.Contains(flag) )
currentFlags.Add(flag);
}
} else {
// no current flags so just use ones specified
currentFlags = new List<string>(flags);
}
((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ] = ( string.Join( " ", flags ) + " " + flag );

settings[ COMPILER_FLAGS_KEY ] = string.Join( " ", currentFlags.ToArray() );
return true;
}

Expand Down
1 change: 0 additions & 1 deletion PBX Editor/PBXFileReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class PBXFileReference : PBXObject
protected const string LASTKNOWN_FILE_TYPE_KEY = "lastKnownFileType";
protected const string ENCODING_KEY = "fileEncoding";

public string compilerFlags;
public string buildPhase;
public readonly Dictionary<TreeEnum, string> trees = new Dictionary<TreeEnum, string> {
{ TreeEnum.ABSOLUTE, "<absolute>" },
Expand Down
5 changes: 2 additions & 3 deletions PBX Editor/PBXParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,8 @@ private bool SerializeString( string aString, StringBuilder builder, bool useQuo
return true;
}

// FIX ME: Original regexp was: @"^[A-Za-z0-9_.]+$", we use modified regexp with '/-' allowed
// to workaround Unity bug when all PNGs had "Libraries/" (group name) added to their paths after append
if( !Regex.IsMatch( aString, @"^[A-Za-z0-9_./-]+$" ) ) {
// Escape any string values that don't match the following
if( !Regex.IsMatch( aString, @"^[A-Za-z0-9_./]+$" ) ) {
useQuotes = true;
}

Expand Down
Loading