فهرست منبع

Reworked XCode file ref handling.
Added custom resource folders.

woollybah 10 سال پیش
والد
کامیت
91cb8b17bd
3فایلهای تغییر یافته به همراه180 افزوده شده و 45 حذف شده
  1. 176 41
      bmk_util.bmx
  2. 4 0
      make.bmk
  3. 0 4
      resources/ios/template/project.xcodeproj/project.pbxproj

+ 176 - 41
bmk_util.bmx

@@ -778,6 +778,34 @@ Function ReplaceBlock:String( text:String,tag:String,repText:String,mark:String=
 	Return text[..i]+repText+text[i2..]
 	Return text[..i]+repText+text[i2..]
 End Function
 End Function
 
 
+Function SplitPaths:String[](paths:String)
+	Local split:String[] = New String[0]
+	
+	Local inQuote:Int
+	Local token:String
+	For Local i:Int = 0 Until paths.length
+		Local char:Int = paths[i]
+		If char = Asc("~q") Then
+			inQuote = Not inQuote
+		Else If char = Asc(" ") And Not inQuote Then
+			token = token.Trim()
+			If token Then
+				split :+ [token]
+			End If
+			token = Null
+		Else
+			token :+ Chr(char)
+		End If
+	Next
+	
+	token = token.Trim()
+	If token Then
+		split :+ [token]
+	End If
+	
+	Return split
+End Function
+
 Function PackageIOSApp( path$, lnk_files:TList, opts$ )
 Function PackageIOSApp( path$, lnk_files:TList, opts$ )
 
 
 	Local templatePath:String = BlitzMaxPath() + "/resources/ios/template"
 	Local templatePath:String = BlitzMaxPath() + "/resources/ios/template"
@@ -807,8 +835,32 @@ Function PackageIOSApp( path$, lnk_files:TList, opts$ )
 	Local fileMap:TFileMap = New TFileMap
 	Local fileMap:TFileMap = New TFileMap
 	
 	
 	For Local f:String = EachIn lnk_files
 	For Local f:String = EachIn lnk_files
-		fileMap.FileId(f, uuid)
+		Local kind:Int
+		Select ExtractExt(f)
+			Case "a"
+				kind = TFileID.TYPE_ARC
+			Case "o"
+				kind = TFileID.TYPE_OBJ
+			Case "dylib"
+				kind = TFileID.TYPE_DYL
+		Default
+			If f.StartsWith("-l") Then
+				kind = TFileID.TYPE_DYL
+			End If
+			If f.StartsWith("-framework") Then
+				kind = TFileID.TYPE_FRM
+			End If
+		End Select
+		fileMap.FileId(f, uuid, TFileMap.BUILD, kind)
 	Next
 	Next
+	
+	' add project-specific resource paths?
+	Local paths:String[] = SplitPaths(String(globals.GetRawVar("resource_path")))
+	If paths Then
+		For Local f:String = EachIn paths
+			fileMap.FileId(f, uuid, TFileMap.BUILD, TFileID.TYPE_DIR)
+		Next
+	End If
 
 
 	Local project:String = LoadString(projectPath)
 	Local project:String = LoadString(projectPath)
 
 
@@ -849,15 +901,15 @@ Function iOSCopyDefaultFiles(templatePath:String, appPath:String)
 	End If
 	End If
 
 
 	' create assets dir if missing
 	' create assets dir if missing
-	Local assetsDir:String = appPath + "/assets"
-	
-	If FileType(assetsDir) <> FILETYPE_DIR Then
-		CreateDir(assetsDir)
-
-		If FileType(assetsDir) <> FILETYPE_DIR Then
-			Throw "Error creating assests dir '" + assetsDir + "'"
-		End If
-	End If
+	'Local assetsDir:String = appPath + "/assets"
+	'
+	'If FileType(assetsDir) <> FILETYPE_DIR Then
+	'	CreateDir(assetsDir)
+'
+'		If FileType(assetsDir) <> FILETYPE_DIR Then
+'			Throw "Error creating assests dir '" + assetsDir + "'"
+'		End If
+'	End If
 
 
 End Function
 End Function
 
 
@@ -904,6 +956,30 @@ Function iOSProjectAppendFiles:String(text:String, uuid:String, fileMap:TFileMap
 	End If
 	End If
 	text = text[..offset] + iOSProjectFrameworksBuildPhase(uuid, fileMap) + text[offset..]
 	text = text[..offset] + iOSProjectFrameworksBuildPhase(uuid, fileMap) + text[offset..]
 	
 	
+	offset = FindEol(text,"/* Begin PBXResourcesBuildPhase section */")
+	If offset <> -1 Then
+		offset = FindEol(text,"/* Resources */ = {",offset)
+	End If
+	If offset <> -1 Then
+		offset = FindEol(text,"files = (",offset)
+	End If
+	If offset = -1 Then
+		Return ""
+	End If
+	text = text[..offset] + iOSProjectResourcesBuildPhase(uuid, fileMap) + text[offset..]
+	
+	offset = FindEol(text,"/* Begin PBXGroup section */")
+	If offset <> -1 Then
+		offset = FindEol(text,"/* Resources */ = {",offset)
+	End If
+	If offset <> -1 Then
+		offset = FindEol(text,"children = (",offset)
+	End If
+	If offset = -1 Then
+		Return ""
+	End If
+	text = text[..offset] + iOSProjectResourcesGroup(uuid, fileMap) + text[offset..]
+
 	offset = FindEol(text,"/* Begin PBXGroup section */")
 	offset = FindEol(text,"/* Begin PBXGroup section */")
 	If offset <> -1 Then
 	If offset <> -1 Then
 		offset = FindEol(text,"/* Frameworks */ = {",offset)
 		offset = FindEol(text,"/* Frameworks */ = {",offset)
@@ -916,7 +992,6 @@ Function iOSProjectAppendFiles:String(text:String, uuid:String, fileMap:TFileMap
 	End If
 	End If
 	text = text[..offset] + iOSProjectFrameworksGroup(uuid, fileMap) + text[offset..]
 	text = text[..offset] + iOSProjectFrameworksGroup(uuid, fileMap) + text[offset..]
 	
 	
-	
 	offset = FindEol(text,"/* Begin PBXGroup section */")
 	offset = FindEol(text,"/* Begin PBXGroup section */")
 	If offset <> -1 Then
 	If offset <> -1 Then
 		offset = FindEol(text,"/* libs */ = {",offset)
 		offset = FindEol(text,"/* libs */ = {",offset)
@@ -975,11 +1050,18 @@ Function iOSProjectBuildFiles:String(uuid:String, fileMap:TFileMap)
 	For Local f:TFileId = EachIn fileMap.buildFiles
 	For Local f:TFileId = EachIn fileMap.buildFiles
 		Local path:String = f.path
 		Local path:String = f.path
 		Local id:String = f.id
 		Local id:String = f.id
-		Local fileRef:String = fileMap.FileId(path, uuid, TFileMap.REF)
+		Local fileRef:String = fileMap.FileId(path, uuid, TFileMap.REF, f.kind)
 		Local dir:String = ExtractDir(path)
 		Local dir:String = ExtractDir(path)
 		Local name:String = StripDir(path)
 		Local name:String = StripDir(path)
 		
 		
-		stack.AddLast "~t~t" + id + " = {isa = PBXBuildFile; fileRef = " + fileRef + "; };"
+		Select f.kind
+			Case TFileId.TYPE_ARC, TFileId.TYPE_OBJ, TFileId.TYPE_DYL
+				stack.AddLast "~t~t" + id + " /* " + name + " */ = {isa = PBXBuildFile; fileRef = " + fileRef + "; };"
+			Case TFileId.TYPE_DIR
+				stack.AddLast "~t~t" + id + " /* " + name + " in Resources */ = {isa = PBXBuildFile; fileRef = " + fileRef + "; };"
+			Case TFileId.TYPE_LIB, TFileId.TYPE_FRM
+				stack.AddLast "~t~t" + id + " /* " + name + " in Frameworks */ = {isa = PBXBuildFile; fileRef = " + fileRef + "; };"
+		End Select
 	Next
 	Next
 	
 	
 	If stack.Count() Then
 	If stack.Count() Then
@@ -998,38 +1080,41 @@ Function iOSProjectFileRefs:String(uuid:String, fileMap:TFileMap)
 		Local dir:String = ExtractDir(path)
 		Local dir:String = ExtractDir(path)
 		Local name:String = StripDir(path)
 		Local name:String = StripDir(path)
 		
 		
-		Select ExtractExt(name)
-			Case "a"
+		Local fid:TFileId = fileMap.GetBuildFileIdForPath(path)
+		
+		Select fid.kind
+			Case TFileId.TYPE_ARC
 				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = " + name + "; path = ~q" + path + "~q; sourceTree = ~q<absolute>~q; };"
 				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = " + name + "; path = ~q" + path + "~q; sourceTree = ~q<absolute>~q; };"
-			Case "o"
+			Case TFileId.TYPE_OBJ
 				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = ~qcompiled.mach-o.objfile~q; name = " + name + "; path = ~q" + path + "~q; sourceTree = ~q<absolute>~q; };"
 				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = ~qcompiled.mach-o.objfile~q; name = " + name + "; path = ~q" + path + "~q; sourceTree = ~q<absolute>~q; };"
-			Case "dylib"
+			Case TFileId.TYPE_DYL
 				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = ~qcompiled.mach-o.dylib~q; name = " + name + "; path = ~q" + path + "~q; sourceTree = ~q<absolute>~q; };"
 				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = ~qcompiled.mach-o.dylib~q; name = " + name + "; path = ~q" + path + "~q; sourceTree = ~q<absolute>~q; };"
-		End Select
-		
-		If path.StartsWith("-l") Then
-			name = "lib" + path[2..] + ".a"
-			Local found:Int = False
-			' path should be provided as a -L...
-			For Local p:String = EachIn fileMap.refFiles.Keys()
-				If p.StartsWith("-L") Then
-					Local libPath:String = p[2..].Replace("~q", "") + "/" + name
-					If FileType(libPath) Then
-						found = True
-						stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = " + name + "; path = ~q" + libPath + "~q; sourceTree = ~q<absolute>~q; };"
-						Exit
+			Case TFileId.TYPE_DIR
+				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = folder; path = ~q" + path + "~q; sourceTree = SOURCE_ROOT; };"
+
+			Case TFileId.TYPE_LIB
+				name = "lib" + path[2..] + ".a"
+				Local found:Int = False
+				' path should be provided as a -L...
+				For Local p:String = EachIn fileMap.refFiles.Keys()
+					If p.StartsWith("-L") Then
+						Local libPath:String = p[2..].Replace("~q", "") + "/" + name
+						If FileType(libPath) Then
+							found = True
+							stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = " + name + "; path = ~q" + libPath + "~q; sourceTree = ~q<absolute>~q; };"
+							Exit
+						End If
 					End If
 					End If
+				Next
+				If Not found Then
+					Print "WARNING : could not find file for library import '" + path + "'. Maybe LD_OPTS: -L...  was not defined?"
 				End If
 				End If
-			Next
-			If Not found Then
-				Print "WARNING : could not find file for library import '" + path + "'. Maybe LD_OPTS: -L...  was not defined?"
-			End If
-		End If
-		
-		If path.StartsWith("-framework") Then
-			name = path[11..]
-			stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = " + name + ".framework; path = System/Library/Frameworks/" + name + ".framework; sourceTree = SDKROOT; };"
-		End If
+
+			Case TFileId.TYPE_FRM
+				name = path[11..]
+				stack.AddLast "~t~t" + id + " = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = " + name + ".framework; path = System/Library/Frameworks/" + name + ".framework; sourceTree = SDKROOT; };"
+		End Select
+
 	Next
 	Next
 	
 	
 	If stack.Count() Then
 	If stack.Count() Then
@@ -1071,6 +1156,45 @@ Function iOSProjectFrameworksBuildPhase:String(uuid:String, fileMap:TFileMap)
 	Return stack.Join(",~n")
 	Return stack.Join(",~n")
 End Function
 End Function
 
 
+Function iOSProjectResourcesBuildPhase:String(uuid:String, fileMap:TFileMap)
+	Local stack:TStringStack = New TStringStack
+
+	For Local f:TFileId = EachIn fileMap.buildFiles
+		Local path:String = f.path
+		Local id:String = f.id
+		
+		If f.kind = TFileId.TYPE_DIR Then
+			stack.AddLast "~t~t~t~t" + id + " /* " + path + " in Resources */"
+		End If
+	Next
+	
+	If stack.Count() Then
+		stack.AddLast ""
+	End If
+	
+	Return stack.Join(",~n")
+End Function
+
+Function iOSProjectResourcesGroup:String(uuid:String, fileMap:TFileMap)
+	Local stack:TStringStack = New TStringStack
+
+	For Local path:String = EachIn fileMap.refFiles.Keys()
+		Local id:String = String(fileMap.refFiles.ValueForKey(path))
+		
+		Local fid:TFileId = fileMap.GetBuildFileIdForPath(path)
+		
+		If fid.kind = TFileId.TYPE_DIR Then
+			stack.AddLast "~t~t~t~t" + id + " /* " + path + " */"
+		End If
+	Next
+	
+	If stack.Count() Then
+		stack.AddLast ""
+	End If
+	
+	Return stack.Join(",~n")
+End Function
+
 Function iOSProjectFrameworksGroup:String(uuid:String, fileMap:TFileMap)
 Function iOSProjectFrameworksGroup:String(uuid:String, fileMap:TFileMap)
 	Local stack:TStringStack = New TStringStack
 	Local stack:TStringStack = New TStringStack
 
 
@@ -1193,8 +1317,18 @@ Type TStringStack Extends TList
 End Type
 End Type
 
 
 Type TFileId
 Type TFileId
+
+	Const TYPE_OBJ:Int = 1
+	Const TYPE_ARC:Int = 2
+	Const TYPE_DYL:Int = 3
+	Const TYPE_LIB:Int = 4
+	Const TYPE_FRM:Int = 5
+	Const TYPE_DIR:Int = 6
+
 	Field path:String
 	Field path:String
 	Field id:String
 	Field id:String
+	
+	Field kind:Int
 End Type
 End Type
 
 
 Type TFileMap
 Type TFileMap
@@ -1207,7 +1341,7 @@ Type TFileMap
 	Field refFiles:TMap = New TMap
 	Field refFiles:TMap = New TMap
 	Field buildFiles:TList = New TList
 	Field buildFiles:TList = New TList
 	
 	
-	Method FileId:String(path:String, uuid:String, kind:Int = BUILD)
+	Method FileId:String(path:String, uuid:String, kind:Int = BUILD, fileKind:Int = 0)
 	
 	
 		Local id:String
 		Local id:String
 		If kind = BUILD Then
 		If kind = BUILD Then
@@ -1231,6 +1365,7 @@ Type TFileMap
 			Local f:TFileId = New TFileId
 			Local f:TFileId = New TFileId
 			f.path = path
 			f.path = path
 			f.id = id
 			f.id = id
+			f.kind = fileKind
 			buildFiles.AddLast(f)
 			buildFiles.AddLast(f)
 		Else
 		Else
 			refFiles.Insert(path, id)
 			refFiles.Insert(path, id)

+ 4 - 0
make.bmk

@@ -195,6 +195,10 @@
 
 
 @end
 @end
 
 
+@define addresourcepath
+	globals.Add("resource_path", arg1)
+@end
+
 @define addlib
 @define addlib
 	globals.Add("libs", arg1)
 	globals.Add("libs", arg1)
 @end
 @end

+ 0 - 4
resources/ios/template/project.xcodeproj/project.pbxproj

@@ -15,7 +15,6 @@
 		FA8B4B97196703B400F8EB7C /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA8B4B96196703B400F8EB7C /* CoreMotion.framework */; };
 		FA8B4B97196703B400F8EB7C /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA8B4B96196703B400F8EB7C /* CoreMotion.framework */; };
 		FD779EDE0E26BA1200F39101 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FD779EDD0E26BA1200F39101 /* CoreAudio.framework */; };
 		FD779EDE0E26BA1200F39101 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FD779EDD0E26BA1200F39101 /* CoreAudio.framework */; };
 		7C8210791294A24C002C4212 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C8210781294A24C002C4212 /* QuartzCore.framework */; };
 		7C8210791294A24C002C4212 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C8210781294A24C002C4212 /* QuartzCore.framework */; };
-		7CD6ED101294B9D9005678BB /* assets in Resources */ = {isa = PBXBuildFile; fileRef = 7CD6ED0E1294B9D9005678BB /* assets */; };
 		7CF9539A1311FB37005295F9 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CF953991311FB37005295F9 /* OpenAL.framework */; };
 		7CF9539A1311FB37005295F9 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CF953991311FB37005295F9 /* OpenAL.framework */; };
 		7CFC10BD139C4FF8006BABB6 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CFC10BC139C4FF8006BABB6 /* AVFoundation.framework */; };
 		7CFC10BD139C4FF8006BABB6 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CFC10BC139C4FF8006BABB6 /* AVFoundation.framework */; };
 		FD787AA10E22A5CC003E8E36 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = FD787AA00E22A5CC003E8E36 /* Default.png */; };
 		FD787AA10E22A5CC003E8E36 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = FD787AA00E22A5CC003E8E36 /* Default.png */; };
@@ -34,7 +33,6 @@
 		FD779EDD0E26BA1200F39101 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
 		FD779EDD0E26BA1200F39101 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
 		7C8210781294A24C002C4212 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
 		7C8210781294A24C002C4212 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
 		7CBDF49E1295F5B6001F0D79 /* ${PROJECT}.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ${PROJECT}.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		7CBDF49E1295F5B6001F0D79 /* ${PROJECT}.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ${PROJECT}.app; sourceTree = BUILT_PRODUCTS_DIR; };
-		7CD6ED0E1294B9D9005678BB /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; path = assets; sourceTree = SOURCE_ROOT; };
 		7CF953991311FB37005295F9 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
 		7CF953991311FB37005295F9 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
 		7CFC10BC139C4FF8006BABB6 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
 		7CFC10BC139C4FF8006BABB6 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
 		FD787AA00E22A5CC003E8E36 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
 		FD787AA00E22A5CC003E8E36 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
@@ -96,7 +94,6 @@
 		29B97317FDCFA39411CA2CEA /* Resources */ = {
 		29B97317FDCFA39411CA2CEA /* Resources */ = {
 			isa = PBXGroup;
 			isa = PBXGroup;
 			children = (
 			children = (
-				7CD6ED0E1294B9D9005678BB /* assets */,
 			);
 			);
 			name = Resources;
 			name = Resources;
 			sourceTree = "<group>";
 			sourceTree = "<group>";
@@ -185,7 +182,6 @@
 			isa = PBXResourcesBuildPhase;
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			buildActionMask = 2147483647;
 			files = (
 			files = (
-				7CD6ED101294B9D9005678BB /* assets in Resources */,
 				FD787AA10E22A5CC003E8E36 /* Default.png in Resources */,
 				FD787AA10E22A5CC003E8E36 /* Default.png in Resources */,
 				FD787AAA0E22A5CC003E8E36 /* [email protected] in Resources */,
 				FD787AAA0E22A5CC003E8E36 /* [email protected] in Resources */,
 				FD925B190E0F276600E92347 /* Icon.png in Resources */,
 				FD925B190E0F276600E92347 /* Icon.png in Resources */,