術語
範圍
本文件說明如何定義索引,以便將執行個體 ID 對應至捷徑。這項對應對使用獨立儲存空間功能的元件來說非常重要。
總覽
元件執行個體 ID 的索引的目標是將穩定的 ID 指派給元件執行個體。方法是將執行個體 ID 對應至路徑名稱。為元件執行個體指派 ID 時,系統會使用此執行個體 ID 在磁碟上識別其永久資源。這樣一來,即使元件的資源仍歸因於該索引,也能變更元件的網址或領域,但前提是這項索引也會更新。
當元件執行階段發現執行個體 ID -> 路徑名稱對應時,會自動移動元件執行個體的現有儲存空間目錄,使其在執行個體 ID 底下建立索引鍵。
只有使用儲存空間功能的元件才能包含在索引中。測試元件不應包含在索引中。
定義新索引
索引檔案是 JSON5 格式的檔案,可將元件的執行個體 ID 對應至其路徑名稱。建構樹狀結構中可能會有多個索引檔案,但這些檔案會合併成單一索引檔案,而這個合併的檔案將可供元件執行階段使用。這個合併的索引檔案無法變更,而且只能透過其他系統更新進行更新。
以下範例說明索引檔案的結構定義:
// Index files are written in JSON5, so you may use comments!
{
// A list of entries, where each entry maps an instance ID to a moniker.
instances: [
// An entry, mapping an instance ID to a moniker.
{
// Instance IDs are randomly generated, 256-bits of base-16 encoded
// strings (in lower case). To generate a new instance ID, set this to
// an empty string (or other invalid value) and run the build; the build
// will fail and suggest a new instance ID which you can copy-paste here.
instance_id: "2bd6cc2bd10243354b873a4ddb8a188b1d29171e26eebac06567bcdc36614af6",
// The `instance_id` above is associated to the following moniker:
moniker: "/core/account/credential_manager",
},
// More than one entry can be included. However, all entries must be distinct:
// * Two entries cannot reference the same `instance_id`
// * Two entries cannot reference the same `moniker`
{
instance_id: "7db7e88479772e241229682b47f1794e12ac5d692f8d67421acd9d7ff318a975",
moniker: "/core/account/password_authenticator",
}
]
}
如要為建構提供索引檔案,請使用 component_id_index() GN 範本:
component_id_index("my_component_id_index") {
source = "my_component_id_index.json5"
}
將元件新增至索引
找出適當的索引檔案
如要將元件新增至索引,您必須在適當的索引檔案中插入項目。目前,core_component_id_index.json5 索引檔案會列出 fuchsia.git
的元件。
將項目新增至索引
第一步是決定元件執行個體的路徑名稱。您可以執行 ffx component show
,在特定產品的工程版本中找到元件的路徑名稱。
然後,利用元件的路徑名稱,將項目附加至 instances
清單。將 instance_id
欄位設為無效值 (例如空白字串),即可讓建構失敗,並建議可以使用的新值。
範例
在這個範例中,元件 fuchsia-pkg://example.com/my_other_package#meta/my_other_component.cm
會新增至索引。
如要判斷元件執行個體的路徑名稱,您可以執行 ffx component show fuchsia-pkg://example.com/my_other_package#meta/my_other_component.cm
:
$ ffx component show fuchsia-pkg://example.com/my_other_package#meta/my_other_component.cm
Moniker: /core/my_other_component
URL: fuchsia-pkg://example.com/my_other_package#meta/my_other_component.cm
...
上述輸出內容顯示此例項的路徑名稱為 /core/my_other_component
將這個項目附加至 core_component_id_index.json5 的 instances
清單,其中含有無效的空白 instance_id
,藉此將 /core/my_other_component
新增至索引:
{
instance_id: "",
moniker: "/core/my_other_component"
}
現在請執行建構作業。建構作業將會失敗,建議新的執行個體 ID:
$ fx build
.
.
Product Assembly Failed
...
4. parsing obj/bundles/assembly/resources/core_component_id_index.json5
5. Invalid instance ID: invalid length; must be 64 characters
Here is a valid, randomly generated ID: 4251833a8d2e47b473732a23de84437e0b346a151ec1e7bdfd43b91e02f894a7
複製建議的 instance_id
欄位來更新已新增的項目。建構作業現在應會通過。
在系統組合中加入元件 ID 索引
本節的目標對像是指設定系統組合的產品擁有者
本節說明如何在系統組合中納入元件 ID 索引。
如果系統組合內含使用獨立儲存空間的元件,則組合應包含元件 ID 索引。以 core
產品為基礎的任何產品在組合中已有元件 ID 索引,因此可能不需要下列操作說明。
系統建構中的所有 component_id_index()
會使用 component_id_index_config()
範本合併在一起。這個範本目前用於 assembled_system.gni
中;如果您連同 assembled_system.gni
中的範本一起定義,組譯會失敗。
操作步驟
- 定義任何您想要納入系統的
component_id_index()
。 - 將這些目標新增為
assembled_system()
目標中的base_packages
依附元件。