Hivgor script file
During the build lifecycle Hvigor uses two script files to accomplish the registration of plugins, tasks, and lifecycle hooks:
- : This file only exists in the root directory of the entire project, it is not required for the build and does not exist by default, you can create it yourself if you need to, it is parsed and executed earlier and can be used to manipulate certain data at the beginning of the Hvigor lifecycle.
- : This file has a copy under each node and is a mandatory file for the build, in which you can register plugins, tasks, and lifecycle hooks, among other operations.
Tasks and task dependency diagrams
Hvigor automates the build of your project based on tasks. A task is the basic unit of work in the Hvigor build process, it defines the specific work that needs to be performed when building a project. Tasks can perform a variety of operations, such as source code compilation tasks, packaging tasks or signing tasks. The execution logic of each task is provided by a plugin, which can be the default task logic provided by hvigor-ohos-plugin, or can be customized by you.
One thing to note is that tasks have dependencies, Hvigor constructs a task dependency graph before executing any task, and all the tasks form a directed acyclic graph (DAG), as shown in the following example diagram, where the dependencies between tasks are represented by arrows:
Both the hvigor plugin (hvigor-ohos-plugin) and the build scripts in the file will make an impact on the task dependency graph through the task dependency mechanism.
hvigor-ohos-plugin
hvigor-ohos-plugin is the default build plugin to provide business logic support for the completion of the task (Task), such as providing Hvigor with tasks such as Hap, Har, and Hsp packaging services, etc. The specific execution logic for each type of task is provided by different plugins in the module.
Hvigor versus hvigor-ohos-plugin
The overview section mentions that Hvigor provides task management mechanisms such as task registration and scheduling as well as configuration management, which is responsible for controlling the execution process of tasks, but does not contain the specific business logic of each task, which is provided by hvigor-ohos-plugin.
The relationship between Hvigor and hvigor-ohos-plugin can be illustrated by the following diagram. Hvigor accepts the registration of tasks and schedules the order of task execution, and calls the plugins in hvigor-ohos-plugin to execute the tasks in order. If you customize your own task logic plugin and register it, hvigor-ohos-plugin will also call your personalized plugin to complete the compilation build process.
In the process of building Hvigor, hvigor-ohos-plugin will register tasks with Hvigor, and Hvigor will call the corresponding plugins to perform the corresponding tasks according to the built task execution vector diagram, and Hvigor will formally complete the build after completing a series of tasks such as compiling, packaging, and signing.
Hvigor life cycle
The lifecycle shows how the Hvigor compile and build system performs a complete compile and build process.Hvigor's compile and build process has three distinct phases, divided into initialization, configuration, and execution, and Hvigor runs these phases sequentially.
- initialization: The main purpose of this phase is to initialize the compilation parameters of the project and construct a tree data model of the project structure, with each node being an HvigorNode object.
- configure: At the beginning of this phase, all the nodes have been loaded, but the plugin, task, and DAG graph have not been loaded in each node, and the main purpose of this phase is to load them out.
- fulfillment: Dependencies between tasks determine the order in which tasks are executed, and tasks can be executed in parallel
Life cycle and hook points
In the life cycle of Hvigor, the following hooks are available for you to use to call certain logic at the right time. In the following figure, all the green-marked wireframes are the available hooks.