Daily Build is of great help to the quality of software. If a runable version is released every day, the test can be started. Detect bugs as soon as possible and modify them as soon as possible. This will ensure the quality of the code without increasing the workload. It is better than staying up late at last.XCODEBUILD
The following Daily Build iOS project. Xcode has a command tool named xcodebuild. This tool can be used to compile Xcode projects using command lines.
Then let's take a look at what xcodebuild can do. Enter the man xcodebuild command:
Powerful functions! However, we currently only need to use a small part of it. A little bit.
Switch to the directory where your project is located
cd /Users/username/Desktop/MyiOSApp/
Try this sentence
xcodebuild -configuration Distribution clean build
Finally, we can see this sentence.** Build succeeded **Even if the command is successfully executed. You can find a new folder build in your directory. in this folder, you can find the compiled and packaged app:YourProjectName. app. That's right. This pack is in the app format. We need to get the ipa package. Is it swollen. Look down.
xcodebuild -scheme MyiOSApp archive -archivePath /Users/username/Desktop/MyiOSApp.xcarchive
Xcodebuild command. Here we use-scheme to package it into xcarchive. Then.
xcodebuild -exportArchive -exportFormat ipa -archivePath /Users/username/Desktop/MyiOSApp.xcarchive -exportPath /Users/username/Desktop/MyiOSApp.ipa
After the command is executed, you will find the ipa package of your app in the build folder you just generated.
Automated
How can I use shell to concatenate xcodebuild commands? No. Use Python. Python can be used for shell and shell. In addition, python is easy to learn. Anyone who brings it can learn it in minutes. Most importantly, many linux systems have pre-installed python. Mac is no exception. Now, the Python2.7 environment is installed on mac by default. Therefore, the following code is based on Python2.7.
The above describes how to install an elephant in a refrigerator in three steps. One by one using Python code.
Preparations
The following example uses the command line to pass in the content that needs to be specified during the three-step process. Python is executed like this:
python yourFileName.py command line
The parameters to be passed in include the name of scheme and the directory of the project. There are other things that are used currently. For example:
python yourFileName.py --scheme=[your scheme name] -x [project path] [out put path.format]
With the command, we should parse it:
opts, args = getopt.getopt(sys.argv[1:], x, [scheme=])
The parameter value starts from the second value.Sys. argv [1:]Because the first one isYourFileName. py. The getopt method returns long parameter names 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, which is equivalent[Project path] [out put path. format]String Array that is split by space.
Take three steps, 1.cd...
Go to the project directory. For more information, see import OS. system (ls) to run the ls command. However, the "cd" command cannot be executed. Because the working directory of the main python process cannot be modified. Use this:
import osdirectory = your ios project pathos.chdir(directory)
2. archive
import subprocessarchiveCmd = xcodebuild -scheme + targetName + archive -archivePath + directory + targetName + .xcarchivesubprocess.Popen(archiveCmd, shell=True)
The first sentence is to spell a string. An xcodebuild command string, which is then executed in subprocess.
3. package it into ipa
ipaCmd = xcodebuild -exportArchive -exportFormat ipa + -archivePath + directory + / + targetName + .xcarchive + -exportPath + directory + / + targetName + .ipasubprocess.Popen(ipaCmd, shell=True)
Like the second part, splice a string to repackage the xcarchive package in the previous step into ipa and output it.
So far so good?
These commands are executed separately. A build directory is generated under the project directory. You can find the xcarchive file and the final output ipa file in the previous two commands. Well, they are all stored in python files and executed once as scheduled.Python yourFileName. py-scheme yourSchemeName-x youriOSPeojectPath. After execution, the output content of xcodebuild that is full of screens is output. But there is no ipa file in the project folder!
It turns out that when subprocess executes the command, the xcodebuild command is returned if it is not completed. That is, the command in the previous step has not been executed while the command in ipa package is executed, and xcarchive has not yet been generated. This is a good solution. python provides a wait Method for subprocess. After all the commands are executed, execute the next step.
process = subprocess.Popen(archiveCmd, shell=True)process.wait()
So far so good!
In this case, all the problems are solved. The code is here. The Python language is flexible. Other functions can be easily extended in this Code. For example, scheduled execution, compilation, or packaging failure, and sending a notification email.