1e41f4b71Sopenharmony_ci# Feature
2e41f4b71Sopenharmony_ci### Configuration Rules
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThis document describes how to declare, define, and use features.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci- Declare a feature
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci  Declare the features of a component in **feature_list** of the **bundle.json** file of the component. Each feature must start with the **{component_name}**. 
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci  The following is an example:
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci  ```
13e41f4b71Sopenharmony_ci  {
14e41f4b71Sopenharmony_ci    "name": "@ohos/xxx",
15e41f4b71Sopenharmony_ci    "component": {
16e41f4b71Sopenharmony_ci      "name": "partName",
17e41f4b71Sopenharmony_ci      "subsystem": "subsystemName",
18e41f4b71Sopenharmony_ci      "features": [
19e41f4b71Sopenharmony_ci        "{partName}_feature_A"
20e41f4b71Sopenharmony_ci      ]
21e41f4b71Sopenharmony_ci    }
22e41f4b71Sopenharmony_ci  }
23e41f4b71Sopenharmony_ci  ```
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci   You can declare multiple features in **features** for a component.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci- Define a feature
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci  You can define the default value of a feature as follows:
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci  ```
32e41f4b71Sopenharmony_ci  declare_args() {
33e41f4b71Sopenharmony_ci    {partName}_feature_A = true
34e41f4b71Sopenharmony_ci  }
35e41f4b71Sopenharmony_ci  ```
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci  The value defined is the default value of the feature for this component. The product can overload the feature default values in the component list.
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci  If a feature is used by multiple modules of a component, you are advised to define the feature in the global .gni file of the component and import the .gni file to the **BUILD.gn** file of each module.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci- Use a feature
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci  In the **BUILD.gn** file, determine the code or modules to build based on features.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci  ```
46e41f4b71Sopenharmony_ci  if ({partName}_feature_A) {
47e41f4b71Sopenharmony_ci      sources += [ "xxx.c" ]
48e41f4b71Sopenharmony_ci  }
49e41f4b71Sopenharmony_ci  
50e41f4b71Sopenharmony_ci  # Dependency introduced by a feature can be isolated by feature.
51e41f4b71Sopenharmony_ci  if ({partName}_feature_A) {
52e41f4b71Sopenharmony_ci      deps += [ "xxx" ]
53e41f4b71Sopenharmony_ci      external_deps += [ "xxx" ]
54e41f4b71Sopenharmony_ci  }
55e41f4b71Sopenharmony_ci  
56e41f4b71Sopenharmony_ci  # The **bundle.json** file does not support the if statement. If the sub_component contained in the **bundle.json** file needs to be deleted, define group().
57e41f4b71Sopenharmony_ci  group("testGroup") {
58e41f4b71Sopenharmony_ci    deps = []
59e41f4b71Sopenharmony_ci    if ({partName}_feature_A) {
60e41f4b71Sopenharmony_ci      deps += [ "xxx" ]
61e41f4b71Sopenharmony_ci    }
62e41f4b71Sopenharmony_ci  }
63e41f4b71Sopenharmony_ci  ```
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci  You can also define code macros for modules in the following way to implement differentiated configuration:
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci  ```
68e41f4b71Sopenharmony_ci  if ({partName}_feature_A) {
69e41f4b71Sopenharmony_ci      defines += ["FEATUREA_DEFINE"]
70e41f4b71Sopenharmony_ci  }
71e41f4b71Sopenharmony_ci  ```
72