1e41f4b71Sopenharmony_ci# HPM Part Development 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## HPM Part Development Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciYou can search for common development resources on [DevEco Marketplace](https://repo.harmonyos.com) and import required resources to your projects through dependencies. If you cannot find the desired resources there, develop the resources on your own and publish them in the form of an HPM Part. To develop HPM Parts, install the hpm-cli tool first. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci> **NOTE** 9e41f4b71Sopenharmony_ci> 10e41f4b71Sopenharmony_ci> You are advised to perform the following operations on Ubuntu 18.04 or later. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Installing hpm-cli 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThe hpm-cli tool is developed based on Node.js. Therefore, you must install Node.js and then use npm to install hpm-cli. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### Installing Node.js and hpm-cli 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci1. Install Node.js. 21e41f4b71Sopenharmony_ci Download Node.js from its official website and install it on your local PC. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci You are advised to install the latest LTS version (not earlier than 12.x) of [Node.js](https://nodejs.org/). 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci2. Install the hpm-cli tool using **npm** delivered with **Node.js**. Run the following command: 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci ``` 28e41f4b71Sopenharmony_ci npm install -g @ohos/hpm-cli 29e41f4b71Sopenharmony_ci ``` 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci3. Run the following command to check whether the installation is successful. If a hpm version is displayed, the installation is successful. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci ``` 34e41f4b71Sopenharmony_ci hpm -V or hpm --version 35e41f4b71Sopenharmony_ci ``` 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci4. (Optional) Run the following command to update the hpm version if needed: 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci ``` 40e41f4b71Sopenharmony_ci npm update -g @ohos/hpm-cli 41e41f4b71Sopenharmony_ci ``` 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci### (Optional) Configuring hpm-cli 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciAfter hpm-cli is installed, run the following command to view the hpm configuration: 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci``` 50e41f4b71Sopenharmony_cihpm config 51e41f4b71Sopenharmony_ci``` 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci The default hpm configuration is displayed upon successful command execution. You can modify the default configuration as required. The following lists the common hpm configuration: 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci``` 56e41f4b71Sopenharmony_ciregistry = https://hpm.harmonyos.com 57e41f4b71Sopenharmony_ci### login Settings 58e41f4b71Sopenharmony_ci# loginUser = invitation_code 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci#### Path Settings 61e41f4b71Sopenharmony_cishellPath = C:\WINDOWS\System32\cmd.exe 62e41f4b71Sopenharmony_ci# shellPath = C:\Program Files\Git\bin\sh.exe 63e41f4b71Sopenharmony_ci# globalRepo = C:\Users\username\.hpm\global 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci#### Network Settings 66e41f4b71Sopenharmony_ci# no_proxy = *.server.com 67e41f4b71Sopenharmony_ci# http_proxy = http://user:pwd@proxy_server:port 68e41f4b71Sopenharmony_ci# https_proxy = http://user:pwd@proxy_server:port 69e41f4b71Sopenharmony_ci# strictSsl = true 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci#### Other Settings 72e41f4b71Sopenharmony_ci# privateSupport = true|false 73e41f4b71Sopenharmony_ci# ignoreBundles = @ohos/llvm,@ohos/gn, 74e41f4b71Sopenharmony_ci# OSPlatform = Auto|linux|darwin|win32 75e41f4b71Sopenharmony_ci``` 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci## Creating an HPM Part 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciYou can create an HPM Part by using a template or define an existing project as an HPM Part. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci### Creating an HPM Part Using a Template 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci1. Run the following command to create a directory: 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci ``` 88e41f4b71Sopenharmony_ci hpm init -t default mybundle 89e41f4b71Sopenharmony_ci ``` 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci >  **NOTE** 92e41f4b71Sopenharmony_ci > -In the preceding command, **default** indicates that the **default** template is used. You can use another template such as **simple** or **dist**. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci The generated directory structure is as follows: 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci ``` 97e41f4b71Sopenharmony_ci / 98e41f4b71Sopenharmony_ci ├── headers # Header file (example) 99e41f4b71Sopenharmony_ci │ └── main.h 100e41f4b71Sopenharmony_ci └── src # Source code (example) 101e41f4b71Sopenharmony_ci │ └─ main.c 102e41f4b71Sopenharmony_ci ├── bundle.json # Metadata declaration file 103e41f4b71Sopenharmony_ci └── LICENSE # License 104e41f4b71Sopenharmony_ci └── Makefile # Build description file (example) 105e41f4b71Sopenharmony_ci └── README.md # Readme file 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci ``` 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci2. Write the code and build script of the HPM Part. 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci ``` 112e41f4b71Sopenharmony_ci hpm init -t {templatename} -d {dir} {name} 113e41f4b71Sopenharmony_ci ``` 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci >  **NOTE** 116e41f4b71Sopenharmony_ci > - -**t {templatename}** indicates the template name. 117e41f4b71Sopenharmony_ci > 118e41f4b71Sopenharmony_ci > - -**d {dir}** indicates the path for storing the HPM Part to be created. 119e41f4b71Sopenharmony_ci > 120e41f4b71Sopenharmony_ci > - **name** indicates the name of the HPM Part to be created. 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ciThe hpm-cli tool provides a few default templates. More templates are available on [DevEco Marketplace](https://repo.harmonyos.com). You can run the **hpm search -t template** command to search for a template stored on [DevEco Marketplace](https://repo.harmonyos.com). 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci### Defining an Existing Project as an HPM Part 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciIf you have a code project and need to distribute it on the HPM platform, run the following command in the project directory, for example, **mybundle2**: 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci``` 133e41f4b71Sopenharmony_cihpm init 134e41f4b71Sopenharmony_ci``` 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci1. Enter an HPM Part name (**mybundle2** for example) and press **Enter**. 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci2. Enter the version and description. A **bundle.json** file will be generated in the current directory. 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci3. Open the **bundle.json** file. 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci ``` 143e41f4b71Sopenharmony_ci $ hpm init 144e41f4b71Sopenharmony_ci Your bundle will be created in directory ~\demo\mybundle2 145e41f4b71Sopenharmony_ci ? bundle name mybundle2 146e41f4b71Sopenharmony_ci ? version 1.0.0 147e41f4b71Sopenharmony_ci ... 148e41f4b71Sopenharmony_ci Initialization finished. 149e41f4b71Sopenharmony_ci ``` 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci4. Modify other information (such as the author, code repository, code directories, scripts, and dependencies) in **bundle.json**. An example is shown below: 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci ``` 154e41f4b71Sopenharmony_ci { 155e41f4b71Sopenharmony_ci "name": "mybundle2", 156e41f4b71Sopenharmony_ci "version": "1.0.0", 157e41f4b71Sopenharmony_ci "publishAs": "code-segment", 158e41f4b71Sopenharmony_ci "dirs":{ 159e41f4b71Sopenharmony_ci ".":["README.md"], 160e41f4b71Sopenharmony_ci "src":["test.c"], 161e41f4b71Sopenharmony_ci "header":["header/test.h" ], 162e41f4b71Sopenharmony_ci "src/common":["src/common/foobar.txt"] 163e41f4b71Sopenharmony_ci }, 164e41f4b71Sopenharmony_ci "scripts": { 165e41f4b71Sopenharmony_ci "build": "make -${args}" 166e41f4b71Sopenharmony_ci }, 167e41f4b71Sopenharmony_ci "dependencies": { 168e41f4b71Sopenharmony_ci "@ohos/cjson": "^1.0.0", 169e41f4b71Sopenharmony_ci "@ohos/foobar": "^1.2.0" 170e41f4b71Sopenharmony_ci } 171e41f4b71Sopenharmony_ci } 172e41f4b71Sopenharmony_ci ``` 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci## Defining a Distribution 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ciIn the distribution metadata file, define the dependent HPM Parts and how to build and link them to generate image files. 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ciThe following uses the **bundle.json** file as an example. In this example, the **dist** command uses the **hb** framework. 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci``` 183e41f4b71Sopenharmony_ci{ 184e41f4b71Sopenharmony_ci "name": "@your/dist_name", 185e41f4b71Sopenharmony_ci "version": "2.2.0", 186e41f4b71Sopenharmony_ci "publishAs": "distribution", 187e41f4b71Sopenharmony_ci "description": "describe it", 188e41f4b71Sopenharmony_ci "scripts": { 189e41f4b71Sopenharmony_ci "config_hb": "hb set -root $DEP_BUNDLE_BASE", 190e41f4b71Sopenharmony_ci "dist": "PATH=/root/.local/bin:${DEP_OHOS_gn}:${DEP_OHOS_ninja}/ninja:${DEP_OHOS_llvm}/llvm/bin:${DEP_OHOS_hc_gen}/hc-gen:${PATH} && ./scripts/dist.sh" 191e41f4b71Sopenharmony_ci }, 192e41f4b71Sopenharmony_ci "envs": { 193e41f4b71Sopenharmony_ci "debug": false 194e41f4b71Sopenharmony_ci }, 195e41f4b71Sopenharmony_ci "dirs": { 196e41f4b71Sopenharmony_ci "scripts": "scripts/*" 197e41f4b71Sopenharmony_ci }, 198e41f4b71Sopenharmony_ci "dependencies": { 199e41f4b71Sopenharmony_ci "@ohos/build_lite": "2.2.0", 200e41f4b71Sopenharmony_ci "@ohos/gn": "1.1.1", 201e41f4b71Sopenharmony_ci "@ohos/llvm": "1.1.1", 202e41f4b71Sopenharmony_ci "@ohos/hc_gen": "1.1.0", 203e41f4b71Sopenharmony_ci "@ohos/ninja": "1.1.0", 204e41f4b71Sopenharmony_ci ...... 205e41f4b71Sopenharmony_ci }, 206e41f4b71Sopenharmony_ci "ohos": { 207e41f4b71Sopenharmony_ci "os": "2.2-Beta", 208e41f4b71Sopenharmony_ci "board": "hi3516", 209e41f4b71Sopenharmony_ci "kernel": "liteos-a" 210e41f4b71Sopenharmony_ci }, 211e41f4b71Sopenharmony_ci "keywords": ["hispark", "hi3516"], 212e41f4b71Sopenharmony_ci "repository": "https://gitee.com/openharmony/your-project", 213e41f4b71Sopenharmony_ci "license": "Apache V2" 214e41f4b71Sopenharmony_ci} 215e41f4b71Sopenharmony_ci``` 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci## Building an HPM Part 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ciIf the code of an HPM Part can be independently built, you can configure the build tool and scripts to generate binary files. 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ciThe hpm-cli tool supports command integration so that you can select any build tool (such as make, gcc, and gn) suitable for your project. You only need to define the **build** command in **scripts** in the **bundle.json** file of your project, and then run the **hpm build** command to start the build. 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci### Defining the Build Script 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ciThis section describes how to build an executable file named **helloworld** in the **app** directory. 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci``` 231e41f4b71Sopenharmony_ciapp 232e41f4b71Sopenharmony_ci├── BUILD.gn 233e41f4b71Sopenharmony_ci├── include 234e41f4b71Sopenharmony_ci│ └── helloworld.h 235e41f4b71Sopenharmony_ci└── src 236e41f4b71Sopenharmony_ci └── helloworld.c 237e41f4b71Sopenharmony_ci``` 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ciCreate a **BUILD.gn** file in the same directory as **helloworld.c**. 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci``` 243e41f4b71Sopenharmony_citouch BUILD.gn 244e41f4b71Sopenharmony_civim BUILD.gn 245e41f4b71Sopenharmony_ci``` 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ciThe following is an example of **BUILD.gn**: 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci``` 251e41f4b71Sopenharmony_ciexecutable("hello_world") { 252e41f4b71Sopenharmony_ci sources = [ 253e41f4b71Sopenharmony_ci "src/helloworld.c" 254e41f4b71Sopenharmony_ci ] 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci include_dirs = [ 257e41f4b71Sopenharmony_ci "include" 258e41f4b71Sopenharmony_ci ] 259e41f4b71Sopenharmony_ci} 260e41f4b71Sopenharmony_ci``` 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci> **NOTE** 263e41f4b71Sopenharmony_ci> 264e41f4b71Sopenharmony_ci> - **executable** is a built-in template of gn. You can run the **gn help executable** command to view how to use this template. 265e41f4b71Sopenharmony_ci> 266e41f4b71Sopenharmony_ci> - **sources** represents the source code path, and **include_dirs** represents the header file path. 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci### Executing the Build Script 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ciRun the following command to start the build: 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci``` 275e41f4b71Sopenharmony_cihpm build 276e41f4b71Sopenharmony_ci``` 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ciAfter all build operations are complete, the message "build succeed" is displayed. You need to check the build result. 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci### Building an Image 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ciRun the following command in the root directory of the current distribution: 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci``` 289e41f4b71Sopenharmony_cihpm dist 290e41f4b71Sopenharmony_ci``` 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ciThe hpm-cli tool automatically starts the build. After the build is complete, an image file will be generated, as shown below: 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci``` 296e41f4b71Sopenharmony_ciout 297e41f4b71Sopenharmony_ci|-xxdist.img 298e41f4b71Sopenharmony_ci|-xx.file 299e41f4b71Sopenharmony_ci``` 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci## Publishing an HPM Part 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ciTo publish an HPM Part, you must obtain an account and create an organization (or join an existing organization). For details, see the online help on [DevEco Marketplace](https://repo.harmonyos.com). 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ciAfter that, generate a public key on the local PC based on your invitation code (which can be obtained on the **My profile** page on [DevEco Marketplace](https://repo.harmonyos.com)), and configure the public key on the **My profile** page. 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci``` 310e41f4b71Sopenharmony_cihpm config set loginUser {your-invitation-code} 311e41f4b71Sopenharmony_cihpm gen-keys 312e41f4b71Sopenharmony_ci``` 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ciThe generated file will be stored in **~\Users\yourname\.hpm\key**. Copy the content in the public key file **publicKey_your-account.pem** to the SSH public key on your **My profile** page. 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ciNow you have the permission to publish HPM Parts in your organization. 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ciIn the directory where the HPM Part is located, run the following command to pack and publish the HPM Part: 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci``` 322e41f4b71Sopenharmony_cihpm publish 323e41f4b71Sopenharmony_ci``` 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci> **NOTE** 326e41f4b71Sopenharmony_ci> 327e41f4b71Sopenharmony_ci> - To avoid HPM Part name conflicts, name an HPM Part in the format of **\@org_name/bundle_name**. 328e41f4b71Sopenharmony_ci> 329e41f4b71Sopenharmony_ci> - Your account must also be a member of **org_name** so that you can publish or update HPM Parts in the organization. 330e41f4b71Sopenharmony_ci> 331e41f4b71Sopenharmony_ci> - The published HPM Parts take effect only after security and content reviews. 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci## Using an HPM Part 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci### Using a Part 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ciWhen developing a project, you usually need to reference other HPM Parts to accelerate development of specific functions. Installing dependencies could be a good way. 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciVisit [DevEco Marketplace](https://repo.harmonyos.com), search for HPM Parts that meet your service requirements by keywords, and then introduce them to your project. The typical operation procedure is as follows: 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci1. Run the **hpm init** command to create a bundle description file named **bundle.json**, which contains dependencies and other metadata such as the name and version. 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci2. Run the **hpm install <name>** command to install the dependency. The dependency will be written into the **dependencies** field in **bundle.json**. 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci3. Reference the header file in the code to implement the function. 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci4. Run the **hpm build** command to perform build and output the build result. 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci Run the following command in your project. Make sure that the project directory contains the **bundle.json** file. 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci``` 354e41f4b71Sopenharmony_ci$ hpm install @scope/the_bundle 355e41f4b71Sopenharmony_ci``` 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci The referenced HPM Part will be installed under **ohos_bundle** in the directory where your project is located. The directory structure is as follows: 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci``` 360e41f4b71Sopenharmony_ciproject 361e41f4b71Sopenharmony_ci├── ohos_bundle 362e41f4b71Sopenharmony_ci│ └── scope 363e41f4b71Sopenharmony_ci│ └─ the_bundle # <--- Referenced HPM Part 364e41f4b71Sopenharmony_ci└── src 365e41f4b71Sopenharmony_ci│ └─ main.c 366e41f4b71Sopenharmony_ci├── bundle.json # Metadata declaration file 367e41f4b71Sopenharmony_ci└── LICENSE 368e41f4b71Sopenharmony_ci└── Makefile 369e41f4b71Sopenharmony_ci└── README.md 370e41f4b71Sopenharmony_ci``` 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ciOpen the **bundle.json** file. You will see that the HPM Part has been introduced to the dependencies of your project. 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci``` 376e41f4b71Sopenharmony_ci{ 377e41f4b71Sopenharmony_ci "dependencies": { 378e41f4b71Sopenharmony_ci "@scope/the_bundle": "^1.0.0" 379e41f4b71Sopenharmony_ci } 380e41f4b71Sopenharmony_ci} 381e41f4b71Sopenharmony_ci``` 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ciYou can edit the dependencies of multiple HPM Parts in this file. 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci``` 387e41f4b71Sopenharmony_ci{ 388e41f4b71Sopenharmony_ci "dependencies": { 389e41f4b71Sopenharmony_ci "@scope/the_bundle1": "^1.0.0", 390e41f4b71Sopenharmony_ci "@scope/the_bundle2": "^2.0.0", 391e41f4b71Sopenharmony_ci "@scope/the_bundle3": "^3.0.0", 392e41f4b71Sopenharmony_ci "@scope/the_bundle4": "^1.1.0" 393e41f4b71Sopenharmony_ci } 394e41f4b71Sopenharmony_ci} 395e41f4b71Sopenharmony_ci``` 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ciRun the **hpm install** command again to download and install all HPM Parts that have not been installed. 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci### Installing Global HPM Parts 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ciIf the referenced HPM Part is shared by multiple projects, for example, the compiler toolchain, you can install it globally. 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ciRun the following command in your project. Make sure that the project directory contains the **bundle.json** file. 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci``` 407e41f4b71Sopenharmony_ci$ hpm install -g @scope/the_tool 408e41f4b71Sopenharmony_ci``` 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ciThe referenced HPM Part will be installed in the directory specified by the **globalRepo** parameter of the **hpm config** command. 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci``` 413e41f4b71Sopenharmony_ci~\.hpm\global\ohos_bundles 414e41f4b71Sopenharmony_ci│ └── scope 415e41f4b71Sopenharmony_ci│ └─ the_tool # <--- Referenced HPM Part 416e41f4b71Sopenharmony_ci``` 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci> **NOTE** 419e41f4b71Sopenharmony_ci> 420e41f4b71Sopenharmony_ci> - For an HPM Part installed in a project, you can reference it using the environment variable **DEP_SCOPE_bundle_name** when running the hpm build command. 421e41f4b71Sopenharmony_ci> For example, after you run **hpm i \@opensource/gn** to install an HPM Part, edit the build script in the **bundle.json** file as follows: 422e41f4b71Sopenharmony_ci> 423e41f4b71Sopenharmony_ci> ``` 424e41f4b71Sopenharmony_ci> "scripts": { 425e41f4b71Sopenharmony_ci> "build": "${DEP_OPENSOURCE_gn}/gn --version" 426e41f4b71Sopenharmony_ci> }, 427e41f4b71Sopenharmony_ci> ``` 428e41f4b71Sopenharmony_ci> 429e41f4b71Sopenharmony_ci> Then, you can run the **hpm build** command to call gn functions. 430e41f4b71Sopenharmony_ci> 431e41f4b71Sopenharmony_ci> - For a globally installed HPM Part, you can directly call the HPM Part using an environment variable or reference the HPM Part using the **${key}/tool_name** parameter in the **hpm config set key value** command. Example: 432e41f4b71Sopenharmony_ci> 433e41f4b71Sopenharmony_ci> ``` 434e41f4b71Sopenharmony_ci> hpm i -g @ohos/opensource/gn 435e41f4b71Sopenharmony_ci> hpm config BUILD_SYS_GN ~/.hpm/global/ohos_bundles/opensource/gn 436e41f4b71Sopenharmony_ci> ``` 437e41f4b71Sopenharmony_ci> 438e41f4b71Sopenharmony_ci> You can edit the build script in the **bundle.json** file as follows: 439e41f4b71Sopenharmony_ci> 440e41f4b71Sopenharmony_ci> ``` 441e41f4b71Sopenharmony_ci> "scripts": { 442e41f4b71Sopenharmony_ci> "build": "${BUILD_SYS_GN}/gn --version" 443e41f4b71Sopenharmony_ci> }, 444e41f4b71Sopenharmony_ci> ``` 445e41f4b71Sopenharmony_ci> 446e41f4b71Sopenharmony_ci> Then, you can run the **hpm build** command to call gn functions. 447