IOS continuous integration: Create a project using the command line

Source: Internet
Author: User
Tags sourcetree

IOS continuous integration: Create a project using the command line

When developing iOS applications, Zookeeper mostly uses Xcode for development. However, sometimes it is necessary to use command lines to create projects, such as ci continuous integration, you can only use the command line method. At this time, you need to understand the composition of the project file. We know that the information about the project file is saved in project. pbxproj. Therefore, we can create the pbxproj file through a script to complete the basic project creation.

Pbxproj

The following section describes the pbxproj file. You can drag the. xcodeproj file to the text editor, such as sublime, to view the composition of the pbxproj file, including:
* PBXBuildFile PBXFileReference
The two sections store the information related to the project file, including the file type, path, and name.

/* Begin PBXBuildFile section */    F60CC2A114D4EA0500A005E4 /* SocketOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F60CC2A014D4EA0500A005E4 /* SocketOperation.m */; };/* End PBXBuildFile section *//* Begin PBXFileReference section *    F60CC2A014D4EA0500A005E4 /* SocketOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SocketOperation.m; sourceTree = 
  
   ; };/* End PBXFileReference section */
  
PBXGroup
This section stores the group information of the project file: The group name and the Files contained in the group. For example, in the following example, A TestChat group contains a Supporting Files subgroup, this group also contains AppDelegate. h and. m files. The corresponding path of the group is TestChat:
* Begin PBXGroup section */        F62417EA14D52F3C003CE997 /* TestChat */ = {            isa = PBXGroup;            children = (                F62417EB14D52F3C003CE997 /* Supporting Files */,                F62417F314D52F3C003CE997 /* AppDelegate.h */,                F62417F414D52F3C003CE997 /* AppDelegate.m */,            );            path = TestChat;            sourceTree = 
  
   ;        };/* End PBXGroup section */
  
PBXNativeTarget
This section stores the target information created by the project, including the configuration information, creation rules, dependencies, names, and types of the target.
/* Begin PBXNativeTarget section */CAC8612E08B161103B6C9DC7 /* UIModuleExample */ = {            isa = PBXNativeTarget;            buildConfigurationList = 56006E5E8040DE2B3965BE91 /* Build configuration list for PBXNativeTarget UIModuleExample */;            buildPhases = (                58D3152C3900AA8B62A79D47 /* Sources */,                A5BF724742232AA0E86F3339 /* Frameworks */,            );            buildRules = (            );            dependencies = (            );            name = UIModuleExample;            productName = UIModuleExample;            productReference = 377070E96E22438316AB8879 /* UIModuleExample.app */;            productType = com.apple.product-type.application;        };/* End PBXNativeTarget section */
XCBuildConfiguration XCConfigurationList
The two sections store the configuration information related to the project: the configuration information in debug mode is shown below. The section contains the search path of CODE_SIGN_IDENTITY, sdk, and framework.
/* Begin XCBuildConfiguration section */        F62417FD14D52F3C003CE997 /* Debug */ = {            isa = XCBuildConfiguration;            buildSettings = {                CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer;                FRAMEWORK_SEARCH_PATHS = (                    $(inherited),                    $(DEVELOPER_FRAMEWORKS_DIR),                );                GCC_PRECOMPILE_PREFIX_HEADER = YES;                GCC_PREFIX_HEADER = TestChat/TestChat-Prefix.pch;                INFOPLIST_FILE = TestChat/TestChat-Info.plist;                IPHONEOS_DEPLOYMENT_TARGET = 5.0;                OTHER_LDFLAGS = -ObjC;                PRODUCT_NAME = $(TARGET_NAME);                TARGETED_DEVICE_FAMILY = 1,2;                WRAPPER_EXTENSION = app;            };            name = Debug;        };/* End XCBuildConfiguration section */

The above analysis of a pbxproj file shows that to create a project, you must first add the relevant file, and then set the target to be generated and the corresponding configuration information.

Command Line to generate pbxproj

The above describes the overall structure of a pbxproj file. to generate such a file, you can write it in the corresponding format or use some script tools. Here we recommend cocoapods Xcodeproj, project address: Xcodeproj. This tool is implemented in ruby. You can use it to modify and create the pbxproj file. The following is a sample code for generating a project file using ruby:

# Create Example. xcodeproj Project file, and save Xcodeproj: Project. new (. /Example. xcodeproj ). save # Open the created Example. xcodeproj file proj = Xcodeproj: Project. open (. /Example. xcodeproj) # create a group named Example and the corresponding path is. /Example exampleGroup = proj. main_group.new_group (Example ,. /Example) # Add a file reference exampleGroup to the Example group. new_reference (AppDelegate. h) ref1 = exampleGroup. new_reference (AppDelegate. m) ref2 = exampleGroup. new_reference (Images. xcassets) exampleGroup. new_reference (Base. lproj/LaunchScreen. xib) # create a subgroup named Supporting Files under the Example group and add main and info to the subgroup. the plist file references supportingGroup = exampleGroup. new_group (Supporting Files) ref3 = supportingGroup. new_reference (main. m) supportingGroup. new_reference (Info. plist) # create a target. The main parameter type: application: dynamic_library framework: static_library is everyone's understanding. # name: target name # platform: ios or: osx target = proj. new_target (: application, Example,: ios) # Add target configuration information target. build_configuration_list.set_setting ('infoplist _ file', $ (SRCROOT)/Example/Info. plist) # Add related file references to target so that it can be referenced to target during compilation. add_file_references ([ref1, ref2, ref3]) testGroup = proj. main_group.new_group (ExampleTests ,. /ExampleTests) ref4 = testGroup. new_reference (ExampleTests. m) supportingGroup = testGroup. new_group (Supporting Files) supportingGroup. new_reference (Info. plist) # create test target testTarget = proj. new_target (: unit_test_bundle, ExampleTests,: ios, nil, proj. products_group) testRefrence = testTarget. product_reference testRefrence. set_explicit_file_type ('wrapper. cfbundle ') testRefrence. name = ExampleTests. xctest testTarget. add_file_references ([ref4]) # Save proj. save

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.