Chromium Chronicle #15: ターゲットの公開設定の制限

エピソード 15: ジョー メイソン、メキシコ、モントリオール(2020 年 11 月)
前のエピソード

Chrome は多数のサブシステムを持つ大規模なプロジェクトです。通常、コンテナ イメージには、 あるコンポーネントについて記述したものの、他の場所では役立ちますが、 あります。安全のため、危険な機能への外部アクセスを制限します。 たとえば、特定のパフォーマンス ニーズに合わせてチューニングされたカスタム関数は次のようになります。

// Blazing fast for 2-char strings, O(n^3) otherwise.
std
::string ConcatShortStringsFast(const std::string& a, const std::string& b);

アクセスを制限する方法はいくつかあります。GN 公開設定ルールの停止コード ターゲットへの依存からコンポーネントの外側に置くことができます。デフォルトでは すべてのユーザーに対して表示されますが、次のように変更することもできます。

# In components/restricted_component/BUILD.gn
visibility
= [
 
# Applies to all targets in this file.
 
# Only the given targets can depend on them.
 
"//components/restricted_component:*",
 
"//components/authorized_other_component:a_single_target",
]
source_set
("internal") {
 
# This dangerous target should be locked down even more.
  visibility
= [ "//components/restricted_component:privileged_target" ]
}

公開設定の宣言は、gn check で検証されます。これは、 必要があります。

もう 1 つのメカニズムは、ヘッダー ファイルへのアクセスを制限する DEPS include_rules です。 すべてのディレクトリは親から include_rules を継承し、それらを変更できます 独自の DEPS ファイルに記述します。外部から含まれるすべてのヘッダー ファイル ディレクトリが include_rules によって許可されている必要があります。

# In //components/authorized_other_component/DEPS
include_rules
= [
 
# Common directories like //base are inherited from
 
# //components/DEPS or //DEPS. Also allow includes from
 
# restricted_component, but not restricted_component/internal.
 
"+components/restricted_component",
 
"-components/restricted_component/internal",
 
# But do allow a single header from internal, for testing.
 
"+components/restricted_component/internal/test_support.h",
]

これらの依存関係が適切であることを確認するには、ディレクトリを追加する そのディレクトリの OWNERS によって承認される必要がありますinclude_rules× include_rules を使用してディレクトリを制限するには承認が必要です。Google Chat では コンポーネントを変更するすべてのメンバーが、特定のコンポーネントを ヘッダーに対して禁止する include_rule を追加します。

include_rules は presubmit によってチェックされるため、 エラーが発生することがあります。include_rulesbuildtools/checkdeps/checkdeps.py <directory> を実行します。

リソース