Add daily Build for iOS project

Source: Internet
Author: User

Many people always like to endorse when it comes to daily build. Endorsement on the endorsement of it, always than in the software industry even books have not seen strong. A long time ago, I met a wonderful flower. Every time to the code to submit a test notice on the hurried panic urged the crew to work hurriedly, began serious overtime, dinner will not eat ... Occasionally, you need to open the night. But even so, there will be no good feedback at the end. That's how the team is doing the project all the way to eternity. If the project's related people can back agile development books, presumably the situation will always improve.

I believe that all of you have met, then why daily build for such a situation has improved it?

    1. Quick positioning error. The problem with the daily build that day was the code that was inherited into the system that day. The code that has check in to SVN must be a convention that can be compiled. Daily build is the best guarantee for the code to work.
    2. Give customers the software they want. Early to put the code can be run to the customer to see. Users can see the available features in a timely manner, and can provide early development and the need to understand inconsistent content. This customer is not necessarily a trait of party a. It can also be understood as other departments, such as products that demand the development department. in general, if you finally give "customer" an "unexpected" software, this may not be what the customer wants.
    3. Development progress is about 60. Software development This thing just can't see the obvious result like building a house. How much is a%60? Daily build makes it very clear to people who need to know the progress of the development.
    4. The Daily build also helps with the quality of the software. A running version comes out every day and the test is ready to be tested. Detect bugs as early as possible and revise them as early as possible. These will guarantee the quality of the code without a significant increase in workload. It's better than staying up late in the last night and not knowing how much.

Xcodebuild

Below daily Build iOS project. Xcode has a command tool xcodebuild. Use this tool to compile the Xcode project using the command line.

Then let's see what this xcodebuild can do. Enter the man xcodebuild command:

The function is very powerful! But what we're going to use now is just a small part of it. A little bit of looking.

Switch to the directory where your project is located

cd/users/username/desktop/myiosapp/

Try this sentence.

Xcodebuild-configuration Distribution Clean Build

Finally see this sentence * * BUILD succeeded * * even if the command executed successfully. You can find a new folder build in your directory where you can find the compiled and packaged app:Yourprojectname.app. That's right. The package is in app format. When we get the IPA bag, it's swollen. Look down.

Xcodebuild-scheme Myiosapp archive-archivepath/users/username/desktop/myiosapp.xcarchive

Xcodebuild command, which uses-scheme to package into xcarchive. And then.

Xcodebuild-exportarchive-exportformat IPA-archivepath    "/users/username/desktop/ Myiosapp.xcarchive" -exportpath    "/users/username/desktop/myiosapp.ipa "

Once this command is completed, you will find your app's IPA package in the build folder that you just generated.

Automate them

String up the Xcodebuild command with the shell? No, use Python. With Python you can do what the shell can do, and you can do what the shell doesn't. And Python is easy to learn, who can take the minute to learn. Most critical of all, many Linux systems have been preloaded with Python. Mac is no exception. Now the MAC is installed by default when the Python2.7 environment. Therefore, the following code is based on Python2.7.

It says "elephant pack refrigerator" three steps away. One by one is implemented in Python code.

Preparatory work

The following is the way to receive the command line in the three-step walk to specify the content. This is what Python does at the time of execution:

Python yourfilename.py command line

The parameters we want to pass in include the scheme name, the directory where the project resides, and so on. There is something else that is currently used mainly in these two. For example:

Python yourfilename.py--scheme=[your scheme name]-X [Project Path] [out put Path.format]

With the order, it should be resolved:

getopt. getopt (sys.argv[1"x", ["scheme="])

The parameter is calculated from the second sys.argv[1:], because the first one is yourfilename.py. The Getopt method takes the name of the long parameter to the OPTs array. Each element in the OPTs array is a tuple structure, the first element is the name of the long parameter, and the second element is the value corresponding to the long parameter. The parameters after-X are placed in the args array. Each element of args is a string, equivalent to a string array of "[Project Path] [out put Path.format]" strings split into spaces.

Walk three steps, 1.cd ...

Jump to the directory where the project is located. Refer to the Import OS os.system ("ls") to execute the LS command. However, this does not execute the "CD" command. Because the working directory of the Python master process cannot be modified. Use this:

Import OS
Directory = "Your iOS Project path" Os.chdir (directory)

2. Archive

Import subprocess
"""" ". Xcarchive"subprocess. Popen (archivecmd, Shell=true)

The first sentence is to spell a string. A xcodebuild command string, which is then placed in subprocess to execute.

3. Package as IPA

Ipacmd ="Xcodebuild-exportarchive-exportformat IPA"+"-archivepath"+ Directory +"/"+ TargetName +". Xcarchive"+"-exportpath"+ Directory +"/"+ TargetName +". IPA"subprocess. Popen (ipacmd, Shell=true)

As in the second part, spell a string to repackage the xcarchive in the previous step into an IPA and output.

So far so good?

These commands are executed separately and there is really no problem. A build directory is generated in the project directory, where we can find the Xcarchive file and the final output of the IPA file that we obtained in the previous two commands. Well, all in Python files are executed once in the way we intended. python yourfilename.py-scheme yourschemename-x youriospeojectpath. The output of the Xcodebuild full screen will be output after execution. But look under the project folder, no IPA file!

It turns out that when Subprocess executes the command, the Xcodebuild command is returned without execution. That is, the order of the IPA package is executed, the previous command has not been executed, Xcarchive has not yet been generated. This is a good solution, and Python provides a wait method for subprocess. Wait until the command is all done and then proceed to the next step.

Process = subprocess. Popen (Archivecmd, shell=True) process. wait ()

So far so good!

All the problems are solved by this time. The code is here. The Python language itself is very flexible. Other functions can easily be extended on this generation of code. such as timed execution, compilation or packaging does not successfully send notification messages.

Add daily Build for iOS project

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.