1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Templates and other services to create XCode projects
16 module xcode_templates
21 import compiler
::abstract_compiler
24 # Map to identify the PBX file type for a given file extension
25 private var pbx_file_types
: Map[String, String] is lazy
do
26 var map
= new HashMap[String, String]
29 map
["m"] = "sourcecode.c.objc"
30 map
["c"] = "sourcecode.c.c"
31 map
["h"] = "sourcecode.c.h"
32 map
["cpp"] = "sourcecode.cpp.cpp"
33 map
["hpp"] = "sourcecode.cpp.h"
34 map
["vsh"] = "sourcecode.glsl"
35 map
["fsh"] = "sourcecode.glsl"
38 map
["png"] = "image.png"
39 map
["gif"] = "image.gif"
40 map
["jpg"] = "image.jpeg"
41 map
["jpeg"] = "image.jpeg"
42 map
["pdf"] = "image.pdf"
43 map
["ico"] = "image.ico"
46 map
["app"] = "wrapper.application"
47 map
["plist"] = "text.plist.xml"
48 map
["storyboard"] = "file.storyboard"
49 map
["xib"] = "file.xib"
50 map
["xcassets"] = "folder.assetcatalog"
51 map
["xctest"] = "wrapper.cfbundle"
56 # Generator of PBX UUIDs quique to an execution of the compiler
57 private var pbx_uuid_generator
= new PbxUUIDGenerator is lazy
60 # Generator of PBX UUIDs
62 # PBX UUID are composed of 24 hex characters.
63 # They only need to be unique within the same project.
65 # This implementation simply counts upward from 0.
66 class PbxUUIDGenerator
74 var hex_val
= seed
.to_hex
.to_upper
75 return "0"*(24-hex_val
.length
) + hex_val
79 # Reference to a file for the PBX format of a project file
81 # TODO create subclasses for different file types, this is currently for
82 # compilable source files only.
88 # UUID for build elements
89 private var build_uuid
: String = sys
.pbx_uuid_generator
.next_uuid
is lazy
92 private var ref_uuid
: String = sys
.pbx_uuid_generator
.next_uuid
is lazy
94 # Documentation to add besides this file in the template
95 private fun doc
: String do return path
97 # PBX file type for `self`
100 var map
= sys
.pbx_file_types
101 var ext
= path
.file_extension
102 if ext
!= null and map
.keys
.has
(ext
) then return map
[ext
]
106 # PBX description of this file
107 private fun description
: Writable do return """
108 {{{ref_uuid}}} /* {{{doc}}} */ = {
109 isa = PBXFileReference;
111 lastKnownFileType = {{{file_type}}};
113 sourceTree = "<group>";
117 private fun add_to_project
(project
: PbxprojectTemplate)
119 project
.source_files
.add
self
120 project
.files
.add
self
124 # Template for a PBX project file, usually a `project.pbcproj`
126 # This file list all information required to build an XCode project.
127 # It would usually be written and read by XCode.
128 # From the command line, xcodebuild can read this file but not write it.
130 # Information in the file (simplified list):
132 # * Compilable source files
134 # * Build configurations (Release and debug modes, cflags, etc.)
135 # * List of files composing the project
136 class PbxprojectTemplate
139 # Name of the project
142 # All body/implementation source files to be compiled
143 private var source_files
= new Array[PbxFile]
145 # All asset files added to the app package
146 private var asset_files
= new Array[PbxFile]
148 # All files used by this project
149 private var files
= new Array[PbxFile]
151 # Add `file` to this project
152 fun add_file
(file
: PbxFile) do file
.add_to_project
(self)
165 /* Begin PBXBuildFile section */
168 # List build files (compilable sources and assets) with their reference UUID
169 for array
in [source_files
, asset_files
] do for file
in array
do add
"""
170 {{{file.build_uuid}}} /* {{{file.doc}}} */ = {
172 fileRef = {{{file.ref_uuid}}} /* {{{file.doc}}} */;
177 /* End PBXBuildFile section */
179 /* Begin PBXContainerItemProxy section */
180 AF9F83EA1A5F0D21004B62C0 /* PBXContainerItemProxy */ = {
181 isa = PBXContainerItemProxy;
182 containerPortal = AF9F83C41A5F0D21004B62C0 /* Project object */;
184 remoteGlobalIDString = AF9F83CB1A5F0D21004B62C0;
185 remoteInfo = {{{name}}};
187 /* End PBXContainerItemProxy section */
189 /* Begin PBXFileReference section */
190 /* Static generated files */
191 AF9F83CC1A5F0D21004B62C0 /* {{{name}}}.app */ = {
192 isa = PBXFileReference;
193 explicitFileType = wrapper.application;
195 path = {{{name}}}.app;
196 sourceTree = BUILT_PRODUCTS_DIR;
198 AF9F83D01A5F0D21004B62C0 /* Info.plist */ = {
199 isa = PBXFileReference;
200 lastKnownFileType = text.plist.xml;
202 sourceTree = "<group>";
204 AF9F83DE1A5F0D21004B62C0 /* Base */ = {
205 isa = PBXFileReference;
206 lastKnownFileType = file.storyboard;
208 path = Base.lproj/Main.storyboard;
209 sourceTree = "<group>";
211 AF9F83E01A5F0D21004B62C0 /* Images.xcassets */ = {
212 isa = PBXFileReference;
213 lastKnownFileType = folder.assetcatalog;
214 path = Images.xcassets;
215 sourceTree = "<group>";
217 AF9F83E31A5F0D21004B62C0 /* Base */ = {
218 isa = PBXFileReference;
219 lastKnownFileType = file.xib;
221 path = Base.lproj/LaunchScreen.xib;
222 sourceTree = "<group>";
224 AF9F83E91A5F0D21004B62C0 /* {{{name}}}Tests.xctest */ = {
225 isa = PBXFileReference;
226 explicitFileType = wrapper.cfbundle;
228 path = {{{name}}}Tests.xctest;
229 sourceTree = BUILT_PRODUCTS_DIR;
231 AF9F83EE1A5F0D21004B62C0 /* Info.plist */ = {
232 isa = PBXFileReference;
233 lastKnownFileType = text.plist.xml;
235 sourceTree = "<group>";
237 AF9F83EF1A5F0D21004B62C0 /* {{{name}}}Tests.m */ = {
238 isa = PBXFileReference;
239 lastKnownFileType = sourcecode.c.objc;
240 path = {{{name}}}Tests.m;
241 sourceTree = "<group>";
244 /* Changing generated files */
246 # Describe all known files
247 for file
in files
do add file
.description
250 /* End PBXFileReference section */
252 /* Begin PBXFrameworksBuildPhase section */
253 AF9F83C91A5F0D21004B62C0 /* Frameworks */ = {
254 isa = PBXFrameworksBuildPhase;
255 buildActionMask = 2147483647;
258 runOnlyForDeploymentPostprocessing = 0;
260 AF9F83E61A5F0D21004B62C0 /* Frameworks */ = {
261 isa = PBXFrameworksBuildPhase;
262 buildActionMask = 2147483647;
265 runOnlyForDeploymentPostprocessing = 0;
267 /* End PBXFrameworksBuildPhase section */
269 /* Begin PBXGroup section */
270 AF9F83C31A5F0D21004B62C0 = {
273 AF9F83CE1A5F0D21004B62C0 /* {{{name}}} */,
274 AF9F83EC1A5F0D21004B62C0 /* {{{name}}}Tests */,
275 AF9F83CD1A5F0D21004B62C0 /* Products */,
277 sourceTree = "<group>";
279 AF9F83CD1A5F0D21004B62C0 /* Products */ = {
282 AF9F83CC1A5F0D21004B62C0 /* {{{name}}}.app */,
283 AF9F83E91A5F0D21004B62C0 /* {{{name}}}Tests.xctest */,
286 sourceTree = "<group>";
288 AF9F83CE1A5F0D21004B62C0 /* {{{name}}} */ = {
292 # Reference all known files
293 for file
in files
do add
"""
294 {{{file.ref_uuid}}} /* {{{file.doc}}} */,
300 sourceTree = "<group>";
302 AF9F83CF1A5F0D21004B62C0 /* Supporting Files */ = {
305 AF9F83D01A5F0D21004B62C0 /* Info.plist */,
306 AF9F83D11A5F0D21004B62C0 /* main.m */,
308 name = "Supporting Files";
309 sourceTree = "<group>";
311 AF9F83EC1A5F0D21004B62C0 /* {{{name}}}Tests */ = {
314 AF9F83EF1A5F0D21004B62C0 /* {{{name}}}Tests.m */,
315 AF9F83ED1A5F0D21004B62C0 /* Supporting Files */,
317 path = {{{name}}}Tests;
318 sourceTree = "<group>";
320 AF9F83ED1A5F0D21004B62C0 /* Supporting Files */ = {
323 AF9F83EE1A5F0D21004B62C0 /* Info.plist */,
325 name = "Supporting Files";
326 sourceTree = "<group>";
328 /* End PBXGroup section */
330 /* Begin PBXNativeTarget section */
331 AF9F83CB1A5F0D21004B62C0 /* {{{name}}} */ = {
332 isa = PBXNativeTarget;
333 buildConfigurationList = AF9F83F31A5F0D21004B62C0 /* Build configuration list for PBXNativeTarget "{{{name}}}" */;
335 AF9F83C81A5F0D21004B62C0 /* Sources */,
336 AF9F83C91A5F0D21004B62C0 /* Frameworks */,
337 AF9F83CA1A5F0D21004B62C0 /* Resources */,
344 productName = {{{name}}};
345 productReference = AF9F83CC1A5F0D21004B62C0 /* {{{name}}}.app */;
346 productType = "com.apple.product-type.application";
348 AF9F83E81A5F0D21004B62C0 /* {{{name}}}Tests */ = {
349 isa = PBXNativeTarget;
350 buildConfigurationList = AF9F83F61A5F0D21004B62C0 /* Build configuration list for PBXNativeTarget "{{{name}}}Tests" */;
352 AF9F83E51A5F0D21004B62C0 /* Sources */,
353 AF9F83E61A5F0D21004B62C0 /* Frameworks */,
354 AF9F83E71A5F0D21004B62C0 /* Resources */,
359 AF9F83EB1A5F0D21004B62C0 /* PBXTargetDependency */,
361 name = {{{name}}}Tests;
362 productName = {{{name}}}Tests;
363 productReference = AF9F83E91A5F0D21004B62C0 /* {{{name}}}Tests.xctest */;
364 productType = "com.apple.product-type.bundle.unit-test";
366 /* End PBXNativeTarget section */
368 /* Begin PBXProject section */
369 AF9F83C41A5F0D21004B62C0 /* Project object */ = {
372 LastUpgradeCheck = 0610;
374 AF9F83CB1A5F0D21004B62C0 = {
375 CreatedOnToolsVersion = 6.1.1;
377 AF9F83E81A5F0D21004B62C0 = {
378 CreatedOnToolsVersion = 6.1.1;
379 TestTargetID = AF9F83CB1A5F0D21004B62C0;
383 buildConfigurationList = AF9F83C71A5F0D21004B62C0 /* Build configuration list for PBXProject "{{{name}}}" */;
384 compatibilityVersion = "Xcode 3.2";
385 developmentRegion = English;
386 hasScannedForEncodings = 0;
391 mainGroup = AF9F83C31A5F0D21004B62C0;
392 productRefGroup = AF9F83CD1A5F0D21004B62C0 /* Products */;
396 AF9F83CB1A5F0D21004B62C0 /* {{{name}}} */,
397 AF9F83E81A5F0D21004B62C0 /* {{{name}}}Tests */,
400 /* End PBXProject section */
402 /* Begin PBXResourcesBuildPhase section */
403 AF9F83CA1A5F0D21004B62C0 /* Resources */ = {
404 isa = PBXResourcesBuildPhase;
405 buildActionMask = 2147483647;
408 # Reference all asset files by their build UUID
409 for file
in asset_files
do add
"""
410 {{{file.build_uuid}}} /* {{{file.doc}}} */,
415 runOnlyForDeploymentPostprocessing = 0;
417 AF9F83E71A5F0D21004B62C0 /* Resources */ = {
418 isa = PBXResourcesBuildPhase;
419 buildActionMask = 2147483647;
422 runOnlyForDeploymentPostprocessing = 0;
424 /* End PBXResourcesBuildPhase section */
426 /* Begin PBXSourcesBuildPhase section */
427 AF9F83C81A5F0D21004B62C0 /* Sources */ = {
428 isa = PBXSourcesBuildPhase;
429 buildActionMask = 2147483647;
432 # Reference all compilable source files by their build UUID
433 for file
in source_files
do add
"""
434 {{{file.build_uuid}}} /* {{{file.doc}}} */,
438 runOnlyForDeploymentPostprocessing = 0;
440 AF9F83E51A5F0D21004B62C0 /* Sources */ = {
441 isa = PBXSourcesBuildPhase;
442 buildActionMask = 2147483647;
444 AF9F83F01A5F0D21004B62C0 /* {{{name}}}Tests.m in Sources */,
446 runOnlyForDeploymentPostprocessing = 0;
448 /* End PBXSourcesBuildPhase section */
450 /* Begin PBXTargetDependency section */
451 AF9F83EB1A5F0D21004B62C0 /* PBXTargetDependency */ = {
452 isa = PBXTargetDependency;
453 target = AF9F83CB1A5F0D21004B62C0 /* {{{name}}} */;
454 targetProxy = AF9F83EA1A5F0D21004B62C0 /* PBXContainerItemProxy */;
456 /* End PBXTargetDependency section */
458 /* Begin PBXVariantGroup section */
459 AF9F83DD1A5F0D21004B62C0 /* Main.storyboard */ = {
460 isa = PBXVariantGroup;
462 AF9F83DE1A5F0D21004B62C0 /* Base */,
464 name = Main.storyboard;
465 sourceTree = "<group>";
467 AF9F83E21A5F0D21004B62C0 /* LaunchScreen.xib */ = {
468 isa = PBXVariantGroup;
470 AF9F83E31A5F0D21004B62C0 /* Base */,
472 name = LaunchScreen.xib;
473 sourceTree = "<group>";
475 /* End PBXVariantGroup section */
477 /* Begin XCBuildConfiguration section */
478 AF9F83F11A5F0D21004B62C0 /* Debug */ = {
479 isa = XCBuildConfiguration;
481 ALWAYS_SEARCH_USER_PATHS = NO;
482 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
483 CLANG_CXX_LIBRARY = "libc++";
484 CLANG_ENABLE_MODULES = YES;
485 CLANG_ENABLE_OBJC_ARC = YES;
486 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
487 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
488 "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
489 COPY_PHASE_STRIP = NO;
490 ENABLE_STRICT_OBJC_MSGSEND = YES;
491 GCC_C_LANGUAGE_STANDARD = gnu99;
492 GCC_DYNAMIC_NO_PIC = NO;
493 GCC_OPTIMIZATION_LEVEL = 0;
494 GCC_PREPROCESSOR_DEFINITIONS = (
498 GCC_SYMBOLS_PRIVATE_EXTERN = NO;
499 GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
500 GCC_WARN_UNDECLARED_SELECTOR = YES;
501 GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
502 IPHONEOS_DEPLOYMENT_TARGET = 8.1;
503 MTL_ENABLE_DEBUG_INFO = YES;
504 ONLY_ACTIVE_ARCH = YES;
506 TARGETED_DEVICE_FAMILY = "1,2";
510 AF9F83F21A5F0D21004B62C0 /* Release */ = {
511 isa = XCBuildConfiguration;
513 ALWAYS_SEARCH_USER_PATHS = NO;
514 CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
515 CLANG_CXX_LIBRARY = "libc++";
516 CLANG_ENABLE_MODULES = YES;
517 CLANG_ENABLE_OBJC_ARC = YES;
518 CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
519 CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
520 "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
521 COPY_PHASE_STRIP = YES;
522 ENABLE_NS_ASSERTIONS = NO;
523 ENABLE_STRICT_OBJC_MSGSEND = YES;
524 GCC_C_LANGUAGE_STANDARD = gnu99;
525 GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
526 GCC_WARN_UNDECLARED_SELECTOR = YES;
527 GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
528 IPHONEOS_DEPLOYMENT_TARGET = 8.1;
529 MTL_ENABLE_DEBUG_INFO = NO;
531 TARGETED_DEVICE_FAMILY = "1,2";
532 VALIDATE_PRODUCT = YES;
536 AF9F83F41A5F0D21004B62C0 /* Debug */ = {
537 isa = XCBuildConfiguration;
539 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
540 INFOPLIST_FILE = {{{name}}}/Info.plist;
541 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
542 PRODUCT_NAME = "$(TARGET_NAME)";
546 AF9F83F51A5F0D21004B62C0 /* Release */ = {
547 isa = XCBuildConfiguration;
549 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
550 INFOPLIST_FILE = {{{name}}}/Info.plist;
551 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
552 PRODUCT_NAME = "$(TARGET_NAME)";
556 AF9F83F71A5F0D21004B62C0 /* Debug */ = {
557 isa = XCBuildConfiguration;
559 BUNDLE_LOADER = "$(TEST_HOST)";
560 FRAMEWORK_SEARCH_PATHS = (
561 "$(SDKROOT)/Developer/Library/Frameworks",
564 GCC_PREPROCESSOR_DEFINITIONS = (
568 INFOPLIST_FILE = {{{name}}}Tests/Info.plist;
569 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
570 PRODUCT_NAME = "$(TARGET_NAME)";
571 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/{{{name}}}.app/{{{name}}}";
575 AF9F83F81A5F0D21004B62C0 /* Release */ = {
576 isa = XCBuildConfiguration;
578 BUNDLE_LOADER = "$(TEST_HOST)";
579 FRAMEWORK_SEARCH_PATHS = (
580 "$(SDKROOT)/Developer/Library/Frameworks",
583 INFOPLIST_FILE = {{{name}}}Tests/Info.plist;
584 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
585 PRODUCT_NAME = "$(TARGET_NAME)";
586 TEST_HOST = "$(BUILT_PRODUCTS_DIR)/{{{name}}}.app/{{{name}}}";
590 /* End XCBuildConfiguration section */
592 /* Begin XCConfigurationList section */
593 AF9F83C71A5F0D21004B62C0 /* Build configuration list for PBXProject "{{{name}}}" */ = {
594 isa = XCConfigurationList;
595 buildConfigurations = (
596 AF9F83F11A5F0D21004B62C0 /* Debug */,
597 AF9F83F21A5F0D21004B62C0 /* Release */,
599 defaultConfigurationIsVisible = 0;
600 defaultConfigurationName = Release;
602 AF9F83F31A5F0D21004B62C0 /* Build configuration list for PBXNativeTarget "{{{name}}}" */ = {
603 isa = XCConfigurationList;
604 buildConfigurations = (
605 AF9F83F41A5F0D21004B62C0 /* Debug */,
606 AF9F83F51A5F0D21004B62C0 /* Release */,
608 defaultConfigurationIsVisible = 0;
610 AF9F83F61A5F0D21004B62C0 /* Build configuration list for PBXNativeTarget "{{{name}}}Tests" */ = {
611 isa = XCConfigurationList;
612 buildConfigurations = (
613 AF9F83F71A5F0D21004B62C0 /* Debug */,
614 AF9F83F81A5F0D21004B62C0 /* Release */,
616 defaultConfigurationIsVisible = 0;
618 /* End XCConfigurationList section */
620 rootObject = AF9F83C41A5F0D21004B62C0 /* Project object */;
626 # Template for a property list used by XCode for iOS projects
631 var package_name
: String
636 <?xml version="1.0" encoding="UTF-8"?>
637 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
638 <plist version="1.0">
640 <key>CFBundleDevelopmentRegion</key>
642 <key>CFBundleExecutable</key>
643 <string>$(EXECUTABLE_NAME)</string>
644 <key>CFBundleIdentifier</key>
645 <string>{{{package_name}}}.$(PRODUCT_NAME:rfc1034identifier)</string>
646 <key>CFBundleInfoDictionaryVersion</key>
648 <key>CFBundleName</key>
649 <string>$(PRODUCT_NAME)</string>
650 <key>CFBundlePackageType</key>
651 <string>APPL</string>
652 <key>CFBundleShortVersionString</key>
654 <key>CFBundleSignature</key>
655 <string>\\?\\?\\?\\?</string>
656 <key>CFBundleVersion</key>
658 <key>LSRequiresIPhoneOS</key>
660 <key>UIRequiredDeviceCapabilities</key>
662 <string>armv7</string>
664 <key>UISupportedInterfaceOrientations</key>
666 <string>UIInterfaceOrientationPortrait</string>
667 <string>UIInterfaceOrientationLandscapeLeft</string>
668 <string>UIInterfaceOrientationLandscapeRight</string>
670 <key>UISupportedInterfaceOrientations~ipad</key>
672 <string>UIInterfaceOrientationPortrait</string>
673 <string>UIInterfaceOrientationPortraitUpsideDown</string>
674 <string>UIInterfaceOrientationLandscapeLeft</string>
675 <string>UIInterfaceOrientationLandscapeRight</string>