laitimes

知乎 iOS 客户端工程化工具 - Venom

author:Flash Gene

Preface

From the beginning, the Zhihu iOS client has been a comprehensive content production and consumption platform covering multiple business lines such as feeds, members, businesses, articles, and ideas. The complexity of the project is already in the realm of super apps. Weekly releases and parallel business development have gradually become mainstream. At the same time, on the Zhihu iOS platform, the technology selection has always been relatively open. Swift was introduced earlier for business development, and ComponentKit was introduced as the core engine for the list, which requires OC++. Therefore, in this kind of multi-business team, complex technical form, large number of component warehouses and other scenarios, it also encounters some problems faced by various super app teams.

The questions are as follows:

  • How to unify the development environment
  • Improve compilation speed
  • Increase packing speed
  • Binary component debugging
  • Joint debugging of multiple components
  • Multi-component joint packaging
  • constrain component dependencies, etc

Of course, before thinking about solving the above problems, the Zhihu iOS project has also experienced componentization work. In contrast to many component-based splitting schemes, the business is divided, the main repository code is emptied, and the business line and SDK are managed in an independent warehouse. The introduction of mechanisms such as route-based and protocol-based communication between components will not be repeated here.

Brief introduction

The title of the project introduced at the core is Venom, which is inspired by the movie Venom. Venom's client is a Mac app for developers that includes a full set of Ruby Gems and Cocoapods for project builds. The core goal is to solve a series of tedious and time-consuming tasks in the development process, such as engineering builds, binary builds, component management, debugging tools, etc.

知乎 iOS 客户端工程化工具 - Venom

So when a brand new Mac computer wants to run a project, it only takes 3 steps:

  1. 安装 Venom For Mac 客户端。
  2. Open the project with Venom and click the Make button.
  3. Once the build is complete, click the XCode button to open the project. (Of course, XCode is installed by default)

Say goodbye to Ruby, wrong cocoapods versions, gem issues, bundle issues, and permission issues. Because the build environment is built-in, the build environment is isolated from the engineer's local environment, which greatly reduces the cost of engineering setup.

The full Venom consists of 3 parts:

  1. Venom App
  2. Venom 内核
  3. Venom Server
知乎 iOS 客户端工程化工具 - Venom

The following will focus on client-side and kernel-related technical solutions, and data services currently only provide API support for additional information about components.

Introduction to the Venom kernel

Prior to the introduction of Venom, Cocoapods' Podfiles were used for component references. However, if you want to extend the DSL of the pod command, you find that it is not convenient enough. Simply build your own component profiles on top of Cocoapods, and each profile will eventually be converted into a pod call to a podfile.

知乎 iOS 客户端工程化工具 - Venom

As shown in the figure above, a project integrated using Venom consists of a composition profile in the VenomFiles directory.

Component description file

VenomFile.new do |v|
  v.name = 'XXModuleA'
  v.git = '[email protected]:Team-iOS-Module/XXModule.git'
  v.tag = '1.0.0'
  v.binary = false
  v.use_module_map = true
  v.XX...
end           

The component description file can be understood as a superset of pod commands, which extend other functions (glue code creation, binarization, source switching, etc.) on top of the original functionality of the pod.

Component debugging

At the same time, a Customization.yml file is also designed at the same level as VenomFile. During development, if you need to switch the source code binary, the source code path, or the version reference of a component, you will not directly change the VenomFile, but will change the Customization.yml. Priority in the build process, Customization.yml > Venomfile. In order that each engineer's changes don't affect each other, Customization.yml is not git-hosted. Files in VenomFiles will only be updated if the version number or other configuration changes are updated.

Build process

All components are managed in the main project repository through Venomfile files, and the components are hierarchically managed through directories.

知乎 iOS 客户端工程化工具 - Venom

The original Podfile file takes over the build responsibilities by embedding Venom.

知乎 iOS 客户端工程化工具 - Venom

After using Venom, the actual process of pod install is as follows:

知乎 iOS 客户端工程化工具 - Venom

Overall, the Venom kernel provides a set of profiles that extend pod properties, and can be built in customization.yml during development with configurable builds. During the build process, the unique identity of the Venomfile file is relied on for the association between the binary library and the source code. Switching between binary and source references is achieved through the hook of the Cocoapods build process. For binary solutions, please refer to:

Xinyu Zhao:知乎 iOS 基于 CocoaPods 实现的二进制化方案40 赞同 · 15 评论文章

Command interface

In addition to the main build responsibilities, the Venom kernel also provides a series of ipc commands. With these ipc commands, the upper-level Venom client can more easily manipulate each component and customize the development organization. to build the project.

For example:

// 修改组件二进制使用方式,使用二进制
venom ipc customization \
    --path /Users/abc/Developer/zhihu/abc/def \
    --edit \
    --name ZHModuleABC \
    --binary
// 修改组件二进制使用方式,使用源码
venom ipc customization \
    --path /Users/abc/Developer/zhihu/abc/def \
    --edit \
    --name ZHModuleABC \
    --source
// 修改 yml 文件中指定组件的路径
venom ipc customization \
    --path /Users/abc/Developer/zhihu/abc/def \
    --edit \
    --name ZHModuleABC \
    --pod_path /path/to/ZHModuleABC
// reset 某个组件在 customization 中的 change,不指定 name 参数会给整个文件置成空
venom ipc customization \
    --path /xxx \
    --reset \
    --name ZHModuleABC           

Venom App 介绍

Through a brief introduction to the Venom kernel, it can be assumed that most of the functions can be achieved only through the command-line version of the tool. However, because the actual development situation generally does not allow one person to work on one module at a time, it is hoped that the WYSIWYG method will allow business engineers to learn commands without caring about the logic of the lower levels. The ability to set up a development environment quickly is our main goal.

知乎 iOS 客户端工程化工具 - Venom

The main module of the client

Venom App 内置了全套的 guby gem 环境来运行命令。 通过 CLITask 来访问 Venom-core 以及 git 等其他命令(venom 内核一样内置在 Venom App 内)。

知乎 iOS 客户端工程化工具 - Venom

This gives a good control over the environment for the execution of orders, especially for new employees.

Core features

Development component associations

Normally, there is no code in the main project (shell project) that clone down, only empty project files and component description files. The Venom tool is divided into 2 areas, common components and custom components.

知乎 iOS 客户端工程化工具 - Venom

Because each developer maintains a limited number of components, the source code is generally placed in a fixed directory, so the automatic scanning path of the client is set. On the Venom interface, if a related component is found in the QR code scanning path, you can associate the local directory component with one click, so that the component will switch to the custom component mode for development.

Version-specific associations

知乎 iOS 客户端工程化工具 - Venom

During development, it is sometimes necessary to debug or concatenate a specific version of a dependent library. Therefore, it also supports switching and associating specific source code through tag, commit, branch, etc.

Source code and binary switching

知乎 iOS 客户端工程化工具 - Venom

In some special scenarios, you may want the project to be built in source code for troubleshooting. Then it is also possible to switch between 2 different build modes with one click. (Of course, it takes a lot of patience to build the full source code once)

Search and debug in binary mode

After binary, most of the time it works in binary mode, but sometimes when you search the source code, you want to be able to search globally. Therefore, during the build process, the source code directory of the current version will also be referenced to the project directory.

知乎 iOS 客户端工程化工具 - Venom

So when it comes to retrieving code in the project, it's perfectly fine. With the source code, when you package the binary in the cloud, you can rewrite the source code path of the Debug mode in the binary file with the parameter fdebug-prefix-map (Clang command line argument reference). This allows you to directly associate the source code for breakpoint debugging, even in binary mode.

Component dependency analysis

When there are many components, some engineers will not know enough about the hierarchy of the components, resulting in dependency confusion. Therefore, after the build is completed, the component dependency level will be judged by checking the component level.

知乎 iOS 客户端工程化工具 - Venom

summary

After promoting the use of the Venom client by all engineers, it is equivalent to having a strong grip on the development process. Due to the automatic update function of the app, developers can be provided with more tools under the platform, and developers only need to update the client to use. Through the development of the tooled client, we reconstructed the original scattered footsteps, and the tools were centrally integrated. It makes the maintenance of development tools more uniform, the update is more timely, and the cost of getting started by developers is lower.

The core of Venom is to manage the development environment, organize and build engineering, and improve engineering efficiency. But after going live, we've continued to offer some other features on top of that.

  • Multi-warehouse MR auto-populates submissions
  • Unit testing of local non-independent business repositories
  • Personal developer account real machine debugging
  • Useless picture scanning tools
  • Lightweight app network and log viewing, etc

Author: Fu San

Source: https://zhuanlan.zhihu.com/p/69526642

Read on