Build Process (objc), build process objc

Source: Internet
Author: User

Build Process (objc), build process objc

Read this article and take notes.

We 've been spoiled in recent days-we just need to click a button in Xcode (this button looks a bit like playing some music). After a few seconds, our program will run, unless there are some errors, this is amazing.

In this article, we will explain the Build process from a more advanced perspective, and explore the relationship between the project setting information exposed in the Xcode interface and the Build process. I will introduce some other articles in this article to further explore the actual implementation of each step in the Build process.

Decrypt Build logs

To understand the internal working principles of Xcode build, we first aim at the complete log file. Open Log Navigator and select a Build from the list. Xcode will display the log file perfectly.

By default, a large amount of information is hidden in the Xcode interface. By selecting a task and clicking the expand button on the right, you can see the details of each task. Another option is to select one or more tasks in the list and then select Cmd-C, which copies all plain text information to the clipboard. Finally, we can select "Copy transcript for shown results" in the Editor menu to Copy all the log information to the clipboard.

In the example given in this article, there are nearly 10,000 lines of log information (in fact, most of the log information is generated when OpenSSL is compiled, not the code we wrote ). Let's get started!

Observe the output log information. First, we will find that the log information is divided into several different sections, which correspond to the targets in our project:

Build target Pods-SSZipArchive...Build target Makefile-openssl...Build target Pods-AFNetworking...Build target crypto...Build target Pods...Build target ssl...Build target objcio

The project involved in this article has several dependencies: AFNetworking and SSZipArchive are included in Pods, while OpenSSL is included in the project as a Child Project.

For each target in the project, Xcode performs a series of operations to convert the source code to machine-readable binary files based on the selected platform. Next we will take a closer look at the first target: SSZipArchive.

In the log information output for this target, we can see the details of each task being executed. For example, the first task is to process a pre-compiled header file (to enhance log information readability, I omitted many details ):

(1) ProcessPCH /.../Pods-SSZipArchive-prefix.pch.pch Pods-SSZipArchive-prefix.pch normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler    (2) cd /.../Dev/objcio/Pods        setenv LANG en_US.US-ASCII        setenv PATH "..."    (3) /.../Xcode.app/.../clang             (4) -x objective-c-header             (5) -arch armv7             ... configuration and warning flags ...            (6) -DDEBUG=1 -DCOCOAPODS=1             ... include paths and more ...            (7) -c             (8) /.../Pods-SSZipArchive-prefix.pch             (9) -o /.../Pods-SSZipArchive-prefix.pch.pch

During the build process, each task will see the log information similar to the above, so we can learn more through the above log information.

  1. Similar to each log information block above, a log is used to describe related tasks as the starting point.
  2. Then, three lines of log information with indentation are output, listing the statements executed by the task. Here, the working directory has changed and the LANG and PATH environment variables are set.
  3. This is a miracle. To process.pchFile, clang is called, and many options are attached. The complete call process and all parameters are shown in the output log. Let's take a look at several of the parameters...
  4. -xThe identifier is used to specify the language in use.objective-c-header.
  5. Specify the target architecturearmv7.
  6. Suggestion#definesHas been added.
  7. -cThe identifier is used to tell clang what to do.-cRun the pre-processor, lexical analyzer, type check, LLVM generation and optimization, and target to specify the generation stage of assembly code. Finally, run the assembler to generate.o.
  8. Input File.
  9. Output file.

Although there is a large amount of log information, I will not detail each task. Our focus is to give you a comprehensive understanding of which tools will be called and what parameters will be used in the build process.

For this target, although there is only one.pchFile, but in factobjective-c-headerFile processing involves two tasks. By observing the specific output log information, we can know the details:

ProcessPCH /.../Pods-SSZipArchive-prefix.pch.pch Pods-SSZipArchive-prefix.pch normal armv7 objective-c ...ProcessPCH /.../Pods-SSZipArchive-prefix.pch.pch Pods-SSZipArchive-prefix.pch normal armv7s objective-c ...

From the above log information, we can see that target has built the armv7 and armv7s for the two architectures. Therefore, clang processes the files twice, each of which targets one architecture.

After processing the pre-compiled header file, you can see that there are several other task types for SSZipArchive target.

CompileC ...Libtool ...CreateUniversalBinary ...

As the name implies:CompileCUsed for compilation.mAnd.cFile,LibtoolUsed to build a library from the target file, andCreateUniversalBinaryThe two.aFiles (each file corresponds to a schema) are merged into a common binary file, which can be run on both armv7 and armv7s.

Then, some other dependencies in the project will also take such similar steps. After AFNetworking is compiled, it is linked to SSZipArchive as the pod library. After OpenSSL is compiled, it processes crypto and ssl target.

After all the dependencies are built, it is our program's target. When building this target, the output log information will contain some very valuable content that has not been shown before:

PhaseScriptExecution ...DataModelVersionCompile ...Ld ...GenerateDSYMFile ...CopyStringsFile ...CpResource ...CopyPNGFile ...CompileAssetCatalog ...ProcessInfoPlistFile ...ProcessProductPackaging /.../some-hash.mobileprovision ...ProcessProductPackaging objcio/objcio.entitlements ...CodeSign ...

In the preceding task list, the unique task that cannot be distinguished by name may beLd,LdIs the name of a linker toollibtoolVery similar. Actually,libtoolIt is also a simple callldAndlipo. 'Ld 'is used to build executable files, whilelibtoolIs used to build library files. Read two articles, Daniel and Chris.

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.