1e41f4b71Sopenharmony_ci# Component
2e41f4b71Sopenharmony_ci### Configuration Rules
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe **bundle.json** file of a component is stored in the root directory of the component source code. The following example shows how to configure the sensor service component of the pan-sensor subsystem:
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci```shell
7e41f4b71Sopenharmony_ci{
8e41f4b71Sopenharmony_ci    "name": "@ohos/sensor_lite",		                                 # OpenHarmony Package Manager (HPM) component name, in the "@Organization/Component name" format.
9e41f4b71Sopenharmony_ci    "description": "Sensor services",		                             # Description of the component function.
10e41f4b71Sopenharmony_ci    "version": "3.1",			                                         # Version, which must be the same as the version of OpenHarmony.
11e41f4b71Sopenharmony_ci    "license": "MIT",			                                         # Component license.
12e41f4b71Sopenharmony_ci    "publishAs": "code-segment", 		                                 # HPM package release mode. The default value is code-segment.
13e41f4b71Sopenharmony_ci    "segment": {										
14e41f4b71Sopenharmony_ci        "destPath": ""			
15e41f4b71Sopenharmony_ci    },					                                                 # Code restoration path (source code path) set when publishAs is code-segment.
16e41f4b71Sopenharmony_ci    "dirs": {"base/sensors/sensor_lite"},	                             # Directory structure of the HPM package. This field is mandatory and can be left empty.
17e41f4b71Sopenharmony_ci    "scripts": {},			                                             # Scripts to be executed. This field is mandatory and can be left empty.
18e41f4b71Sopenharmony_ci    "licensePath": "COPYING",			
19e41f4b71Sopenharmony_ci    "readmePath": {
20e41f4b71Sopenharmony_ci        "en": "README.rst"
21e41f4b71Sopenharmony_ci    },
22e41f4b71Sopenharmony_ci    "component": { 			                                             # Component attributes.
23e41f4b71Sopenharmony_ci        "name": "sensor_lite",			                                 # Component name.
24e41f4b71Sopenharmony_ci        "subsystem": "",		                                         # Subsystem to which the component belongs.
25e41f4b71Sopenharmony_ci        "syscap": [], 				                                     # System capabilities provided by the component for applications.
26e41f4b71Sopenharmony_ci        "features": [],                                                  # List of external configurable features of the component. Generally, this parameter corresponds to sub_component in build.
27e41f4b71Sopenharmony_ci        "adapted_system_type": [],		                                 # Types of adapted systems, which can be mini, small, standard, or their combinations.
28e41f4b71Sopenharmony_ci        "rom": "92KB",                                                   # Component ROM size.
29e41f4b71Sopenharmony_ci        "ram": "~200KB",                                                 # Component RAM size.
30e41f4b71Sopenharmony_ci        "deps": {                      
31e41f4b71Sopenharmony_ci        "components": [                                                  # Other components on which this component depends.
32e41f4b71Sopenharmony_ci          "samgr_lite",
33e41f4b71Sopenharmony_ci          "ipc_lite"
34e41f4b71Sopenharmony_ci        ],
35e41f4b71Sopenharmony_ci        "third_party": [                                                 # Third-party open-source software on which this component depends.
36e41f4b71Sopenharmony_ci          "bounds_checking_function"
37e41f4b71Sopenharmony_ci        ],
38e41f4b71Sopenharmony_ci        "hisysevent_config": []                                          # Build entry of the HiSysEvent configuration file.
39e41f4b71Sopenharmony_ci      }         
40e41f4b71Sopenharmony_ci        "build": {				                                         # Build-related configurations.
41e41f4b71Sopenharmony_ci            "sub_component": [
42e41f4b71Sopenharmony_ci                ""//base/sensors/sensor_lite/services:sensor_service"",  # Component build entry.
43e41f4b71Sopenharmony_ci            ],			                                                 # Component build entry. Configure modules here.
44e41f4b71Sopenharmony_ci            "inner_kits": [],						                     # APIs between components.
45e41f4b71Sopenharmony_ci            "test": [] 						                             # Entry for building the component's test cases.
46e41f4b71Sopenharmony_ci        }
47e41f4b71Sopenharmony_ci    }
48e41f4b71Sopenharmony_ci }
49e41f4b71Sopenharmony_ci```
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci> **CAUTION**
52e41f4b71Sopenharmony_ci>
53e41f4b71Sopenharmony_ci> Existing components on the LiteOS are configured in the JSON file of the corresponding subsystem in the **build/lite/components** directory. The directory is named in the **{Domain}/{Subsystem}/{Component}** format. The component directory structure is as follows:
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci```shell
56e41f4b71Sopenharmony_cicomponent
57e41f4b71Sopenharmony_ci├── interfaces
58e41f4b71Sopenharmony_ci│   ├── innerkits  # APIs exposed internally among components
59e41f4b71Sopenharmony_ci│   └── kits       # APIs provided for application developers
60e41f4b71Sopenharmony_ci├── frameworks     # Framework implementation
61e41f4b71Sopenharmony_ci├── services       # Service implementation
62e41f4b71Sopenharmony_ci├── BUILD.gn       # Build script
63e41f4b71Sopenharmony_ci```
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ciYou need to configure the component name, source code path, function description, mandatory or not, build target, RAM, ROM, output, adapted kernel, configurable features, and dependencies.
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci> **NOTE**
68e41f4b71Sopenharmony_ci>
69e41f4b71Sopenharmony_ci> For details about how to use the HiSysEvent configuration file in component configuration, see [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md).
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciWhen adding a component, you must add the component definition to the JSON file of the corresponding subsystem. The component configured for a product must have been defined in a subsystem. Otherwise, the verification will fail.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci### Adding and Building a Component
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci1. Add a component.
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci   The following use a custom component as an example to describe how to compile a library, executable file, and configuration file.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci   In this example, **partA** consists of **feature1**, **feature2**, and **feature3**, which represent a dynamic library, an executable file, and an etc configuration file, respectively.
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci   Add **partA** to a subsystem, for example, **subsystem_examples** (defined in the **test/examples/** directory).
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci   The directory structure of **partA** is as follows:
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci   ```shell
86e41f4b71Sopenharmony_ci   test/examples/partA
87e41f4b71Sopenharmony_ci   ├── feature1
88e41f4b71Sopenharmony_ci   │   ├── BUILD.gn
89e41f4b71Sopenharmony_ci   │   ├── include
90e41f4b71Sopenharmony_ci   │   │   └── helloworld1.h
91e41f4b71Sopenharmony_ci   │   └── src
92e41f4b71Sopenharmony_ci   │       └── helloworld1.cpp
93e41f4b71Sopenharmony_ci   ├── feature2
94e41f4b71Sopenharmony_ci   │   ├── BUILD.gn
95e41f4b71Sopenharmony_ci   │   ├── include
96e41f4b71Sopenharmony_ci   │   │   └── helloworld2.h
97e41f4b71Sopenharmony_ci   │   └── src
98e41f4b71Sopenharmony_ci   │       └── helloworld2.cpp
99e41f4b71Sopenharmony_ci   └── feature3
100e41f4b71Sopenharmony_ci       ├── BUILD.gn
101e41f4b71Sopenharmony_ci       └── src
102e41f4b71Sopenharmony_ci           └── config.conf
103e41f4b71Sopenharmony_ci   ```
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci   (a) Configure **test/examples/partA/feature1/BUILD.gn** for the dynamic library.
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci   ```shell
108e41f4b71Sopenharmony_ci   config("helloworld_lib_config") {
109e41f4b71Sopenharmony_ci    include_dirs = [ "include" ]
110e41f4b71Sopenharmony_ci   }
111e41f4b71Sopenharmony_ci   
112e41f4b71Sopenharmony_ci   ohos_shared_library("helloworld_lib") {
113e41f4b71Sopenharmony_ci     sources = [
114e41f4b71Sopenharmony_ci       "include/helloworld1.h",
115e41f4b71Sopenharmony_ci       "src/helloworld1.cpp",
116e41f4b71Sopenharmony_ci     ]
117e41f4b71Sopenharmony_ci     public_configs = [ ":helloworld_lib_config" ]
118e41f4b71Sopenharmony_ci     part_name = "partA"
119e41f4b71Sopenharmony_ci   }
120e41f4b71Sopenharmony_ci   ```
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci   (b) Configure **test/examples/partA/feature2/BUILD.gn** for the executable file.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci   ```shell
125e41f4b71Sopenharmony_ci   ohos_executable("helloworld_bin") {
126e41f4b71Sopenharmony_ci     sources = [
127e41f4b71Sopenharmony_ci       "src/helloworld2.cpp"
128e41f4b71Sopenharmony_ci     ]
129e41f4b71Sopenharmony_ci     include_dirs = [ "include" ]
130e41f4b71Sopenharmony_ci     deps = [                                # Dependent modules in the component
131e41f4b71Sopenharmony_ci       "../feature1:helloworld_lib"
132e41f4b71Sopenharmony_ci     ]
133e41f4b71Sopenharmony_ci     external_deps = [ "partB:module1" ]     # (Optional) Dependent modules of another component are named in the Component name:Module name format.
134e41f4b71Sopenharmony_ci     install_enable = true                   # By default, executable programs are not installed. Set this parameter to true if an executable program needs to be installed.
135e41f4b71Sopenharmony_ci     part_name = "partA"
136e41f4b71Sopenharmony_ci   }
137e41f4b71Sopenharmony_ci   ```
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci   (c) Configure **test/examples/partA/feature3/BUILD.gn** for the etc module.
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci   ```shell
142e41f4b71Sopenharmony_ci   ohos_prebuilt_etc("feature3_etc") {
143e41f4b71Sopenharmony_ci     source = "src/config.conf"
144e41f4b71Sopenharmony_ci     relative_install_dir = "init"    # (Optional) Relative directory for installing the module. The default installation directory is /system/etc.
145e41f4b71Sopenharmony_ci     part_name = "partA"
146e41f4b71Sopenharmony_ci   }
147e41f4b71Sopenharmony_ci   ```
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci   (d) Add the module configuration **test/examples/bundle.json** to the **bundle.json** file of the component. Each component has a **bundle.json** file in the root directory of the component. For details, see the [component bundle.json file](subsys-build-component.md#configuration-rules).
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci2. Add the component to the product configuration file.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci    Add the component to **//vendor/{*product_company*}/{*product_name*}/config.json**.
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci    The following uses **vendor/hisilicon/hispark_taurus_standard/config.json** as an example:
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci    ```shell
158e41f4b71Sopenharmony_ci      {
159e41f4b71Sopenharmony_ci        "product_name": "hispark_taurus_standard",
160e41f4b71Sopenharmony_ci        "device_company": "hisilicon",
161e41f4b71Sopenharmony_ci        "device_build_path": "device/board/hisilicon/hispark_taurus/linux",
162e41f4b71Sopenharmony_ci        "target_cpu": "arm",
163e41f4b71Sopenharmony_ci        "type": "standard",
164e41f4b71Sopenharmony_ci        "version": "3.0",
165e41f4b71Sopenharmony_ci        "board": "hispark_taurus",
166e41f4b71Sopenharmony_ci        "inherit": [ "productdefine/common/base/standard_system.json",
167e41f4b71Sopenharmony_ci                    "productdefine/common/inherit/ipcamera.json"
168e41f4b71Sopenharmony_ci        ],
169e41f4b71Sopenharmony_ci        "enable_ramdisk": true,
170e41f4b71Sopenharmony_ci        "subsystems": [
171e41f4b71Sopenharmony_ci          {
172e41f4b71Sopenharmony_ci            "subsystem": "subsystem_examples",                              # Subsystem to which the component belongs.
173e41f4b71Sopenharmony_ci            "components": [
174e41f4b71Sopenharmony_ci              {
175e41f4b71Sopenharmony_ci                "component": "partA",                                       # Component name.
176e41f4b71Sopenharmony_ci                "features": []                                              # Configurable features of the component.
177e41f4b71Sopenharmony_ci              }
178e41f4b71Sopenharmony_ci            ]
179e41f4b71Sopenharmony_ci          },
180e41f4b71Sopenharmony_ci        ···
181e41f4b71Sopenharmony_ci      }
182e41f4b71Sopenharmony_ci    ```
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci    The configuration file contains information about the the product name and chip vendor. **inherit** specifies the dependent, and **subsystems** specifies the components other than the common components.
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci    For example, add "subsystem_examples:partA" to the product **config.json** file. Then, **partA** will be built and packaged into the distribution.
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci3. Start the build.
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci   You can start the build by using the [CLI or hb tool](subsys-build-all.md#build-commands). The following uses the CLI as an example:
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci   You can run '**--build-target *componentName***' to build a component separately. For example, to build the musl component of hispark_taurus_standard, run the following command:
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci   ```
195e41f4b71Sopenharmony_ci   ./build.sh --product-name hispark_taurus_standard --build-target musl --ccache
196e41f4b71Sopenharmony_ci   ```
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci   You can also build a product. For example, to build hispark_taurus_standard, run the following command:
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci   ```shell
201e41f4b71Sopenharmony_ci   ./build.sh --product-name hispark_taurus_standard --ccache
202e41f4b71Sopenharmony_ci   ```
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci4. Obtain the build result.
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci    You can obtain the generated files from the **out/hispark_taurus/** directory and the image in the **out/hispark_taurus/packages/phone/images/** directory.
207