chromium 添加features特性编译参数开关
具体参考gn的说明。
1,在全局里面设置编译参数的值:electron/build/args/testing.gn里面设置开关:
enable_desktop_capturer=false 会覆盖调定义时的值
也可使直接使用:
gn --args="enable_doom_melon=true enable_teleporter=false"
2,在使用它的模块中定义它,用declare_args()。
electron模块:\src\electron\buildflags\buildflags.gni
# Copyright (c) 2018 GitHub, Inc.
# Use of this source code is governed by the MIT license that can be
# found in the LICENSE file.
declare_args() {
enable_desktop_capturer = true
# Enable Chrome extensions support.
enable_electron_extensions = true
# Enable Spellchecker support
enable_builtin_spellchecker = true
}
打印模块src\printing\buildflags\buildflags.gni
import("//build/config/chromecast_build.gni")
import("//build/config/chromeos/args.gni")
import("//build/config/features.gni")
import("//build/config/sanitizers/sanitizers.gni")
declare_args() {
# Enable basic printing support and UI.
enable_basic_printing = !is_chromecast && !is_ios && !is_fuchsia
}
3,在c++中引用:
#include "electron/buildflags/buildflags.h"
4,gn,gni文件引用它直接用 import("//printing/buildflags/buildflags.gni")
gni中:
if (enable_print_preview) { sources += [ "$root_gen_dir/chrome/print_preview_resources.pak" ] deps += [ "//chrome/browser/resources:print_preview_resources" ] }
原理:
将\src\printing\buildflags\buildflags.gni
在c++中,它会生成在gen目录,ENABLE_PDF_VIEWER的头文件在 D:\dev\electron9\src\out\Testing\gen\electron\buildflags\buildflags.h这里。
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
#endif
这个buildflag宏的产生需要:
D:\dev\electron9\src\out\Testing\gen\printing\buildflags\buildflags.h
// Generated by build/write_buildflag_header.py
// From "//printing/buildflags:buildflags"
#ifndef PRINTING_BUILDFLAGS_BUILDFLAGS_H_
#define PRINTING_BUILDFLAGS_BUILDFLAGS_H_
#include "build/buildflag.h"
#define BUILDFLAG_INTERNAL_ENABLE_PRINTING() (1)
#define BUILDFLAG_INTERNAL_ENABLE_PRINT_PREVIEW() (1)
#define BUILDFLAG_INTERNAL_ENABLE_TAGGED_PDF() (1)
#endif // PRINTING_BUILDFLAGS_BUILDFLAGS_H_
pdf的一次electron提交:
SHA-1: d590f2efe3abaeda909885855c2b901345284b55
* feat: enable pdf viewer (#21794)