Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[Settings] Add initial support for generating preferences related code
https://bugs.webkit.org/show_bug.cgi?id=178656 Patch by Sam Weinig <sam@webkit.org> on 2017-10-24 Reviewed by Dean Jackson. As a first step towards getting off the macros in WebPreferencesDefinitions.h and reducing the overhead of adding a preference, this change generates adds WebPreferences.yaml where preference changes will go, and generates much of WebPreferencesDefinitions.h from it (all the custom defaults moved to WebPreferencesDefinitionsBase.h). Subsequent changes will remove the need for the macros in WebPreferencesDefinitions.h entirely. * CMakeLists.txt: * DerivedSources.make: * WebKit.xcodeproj/project.pbxproj: Add new files / rules to generate WebPreferencesDefinitions.h. * Scripts/GeneratePreferences.rb: Added. * Scripts/PreferencesTemplates: Added. * Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb: Added. Add scripts and template to generate WebPreferencesDefinitions.h from WebPreferences.yaml. * Shared/WebPreferences.yaml: Added. Configuration file for preferences. * Shared/WebPreferencesDefinitions.h: Removed. * Shared/WebPreferencesDefinitionsBase.h: Copied from Source/WebKit/Shared/WebPreferencesDefinitions.h. Moved custom defaults to new WebPreferencesDefinitionsBase.h. Removed the need for FOR_EACH_WEBKIT_STRING_PREFERENCE by using custom defaults for the font family values. Canonical link: https://commits.webkit.org/194899@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223903 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
1,502 additions
and 455 deletions.
- +15 −0 Source/WebKit/CMakeLists.txt
- +37 −0 Source/WebKit/ChangeLog
- +12 −0 Source/WebKit/DerivedSources.make
- +140 −0 Source/WebKit/Scripts/GeneratePreferences.rb
- +102 −0 Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb
- +1,007 −0 Source/WebKit/Shared/WebPreferences.yaml
- +0 −451 Source/WebKit/Shared/WebPreferencesDefinitions.h
- +179 −0 Source/WebKit/Shared/WebPreferencesDefinitionsBase.h
- +10 −4 Source/WebKit/WebKit.xcodeproj/project.pbxproj
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,140 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# Copyright (c) 2017 Apple Inc. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
# THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
require "fileutils" | ||
require 'erb' | ||
require 'optparse' | ||
require 'yaml' | ||
|
||
options = { | ||
:input => nil, | ||
:outputDirectory => nil | ||
} | ||
optparse = OptionParser.new do |opts| | ||
opts.banner = "Usage: #{File.basename($0)} --input file" | ||
|
||
opts.separator "" | ||
|
||
opts.on("--input input", "file to generate settings from") { |input| options[:input] = input } | ||
opts.on("--outputDir output", "directory to generate file in") { |output| options[:outputDirectory] = output } | ||
end | ||
|
||
optparse.parse! | ||
|
||
if !options[:input] | ||
puts optparse | ||
exit -1 | ||
end | ||
|
||
if !options[:outputDirectory] | ||
options[:outputDirectory] = Dir.getwd | ||
end | ||
|
||
FileUtils.mkdir_p(options[:outputDirectory]) | ||
|
||
parsedPreferences = begin | ||
YAML.load_file(options[:input]) | ||
rescue ArgumentError => e | ||
puts "Could not parse input file: #{e.message}" | ||
exit(-1) | ||
end | ||
|
||
class Preference | ||
attr_accessor :name | ||
attr_accessor :type | ||
attr_accessor :defaultValue | ||
attr_accessor :humanReadableName | ||
attr_accessor :humanReadableDescription | ||
attr_accessor :webkitOnly | ||
attr_accessor :category | ||
|
||
def initialize(name, opts) | ||
@name = name | ||
@type = opts["type"] | ||
@defaultValue = opts["defaultValue"] | ||
@humanReadableName = '"' + (opts["humanReadableName"] || "") + '"' | ||
@humanReadableDescription = '"' + (opts["humanReadableDescription"] || "") + '"' | ||
@webkitOnly = opts["webkitOnly"] | ||
@category = opts["category"] | ||
@getter = opts["getter"] | ||
end | ||
|
||
def nameLower | ||
if @getter | ||
@getter | ||
elsif @name.start_with?("CSS", "XSS", "FTP", "DOM", "DNS", "PDF", "ICE") | ||
@name[0..2].downcase + @name[3..@name.length] | ||
elsif @name.start_with?("HTTP") | ||
@name[0..3].downcase + @name[4..@name.length] | ||
else | ||
@name[0].downcase + @name[1..@name.length] | ||
end | ||
end | ||
end | ||
|
||
class Conditional | ||
attr_accessor :condition | ||
attr_accessor :preferences | ||
|
||
def initialize(condition, settings) | ||
@condition = condition | ||
@preferences = preferences | ||
end | ||
end | ||
|
||
class Preferences | ||
attr_accessor :preferences | ||
|
||
def initialize(hash) | ||
@preferences = [] | ||
hash.each do |name, options| | ||
@preferences << Preference.new(name, options) | ||
end | ||
@preferences.sort! { |x, y| x.name <=> y.name } | ||
|
||
@boolPreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "bool" } | ||
@doublePreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "double" } | ||
@intPreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "uint32_t" } | ||
@stringPreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "String" } | ||
@stringPreferencesNotDebugNotInWebKit = @preferences.select { |p| !p.category && p.webkitOnly && p.type == "String" } | ||
|
||
@boolPreferencesDebug = @preferences.select { |p| p.category == "debug" && !p.webkitOnly && p.type == "bool" } | ||
@intPreferencesDebug = @preferences.select { |p| p.category == "debug" && !p.webkitOnly && p.type == "uint32_t" } | ||
|
||
@experimentalFeature = @preferences.select { |p| p.category == "experimental" && !p.webkitOnly } | ||
end | ||
|
||
def renderToFile(template, file) | ||
template = File.join(File.dirname(__FILE__), template) | ||
|
||
output = ERB.new(File.read(template), 0, "-").result(binding) | ||
File.open(file, "w+") do |f| | ||
f.write(output) | ||
end | ||
end | ||
end | ||
|
||
preferences = Preferences.new(parsedPreferences) | ||
preferences.renderToFile("PreferencesTemplates/WebPreferencesDefinitions.h.erb", File.join(options[:outputDirectory], "WebPreferencesDefinitions.h")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,102 @@ | ||
/* | ||
* THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. | ||
* | ||
* Copyright (C) 2017 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "WebPreferencesDefinitionsBase.h" | ||
|
||
// macro(KeyUpper, KeyLower, TypeNameUpper, TypeName, DefaultValue, HumanReadableName, HumanReadableDescription) | ||
|
||
#define FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \ | ||
<%- for @pref in @boolPreferencesNotDebug do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Bool, bool, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
#define FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \ | ||
<%- for @pref in @doublePreferencesNotDebug do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Double, double, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
#define FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \ | ||
<%- for @pref in @intPreferencesNotDebug do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, UInt32, uint32_t, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
#define FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \ | ||
<%- for @pref in @stringPreferencesNotDebug do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, String, String, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
#define FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \ | ||
<%- for @pref in @stringPreferencesNotDebugNotInWebKit do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, String, String, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
|
||
// Debug Preferences | ||
|
||
#define FOR_EACH_WEBKIT_DEBUG_BOOL_PREFERENCE(macro) \ | ||
<%- for @pref in @boolPreferencesDebug do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Bool, bool, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
#define FOR_EACH_WEBKIT_DEBUG_UINT32_PREFERENCE(macro) \ | ||
<%- for @pref in @intPreferencesDebug do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, UInt32, uint32_t, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
|
||
// Experimental Features | ||
|
||
#define FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(macro) \ | ||
<%- for @pref in @experimentalFeature do -%> | ||
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Bool, bool, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \ | ||
<%- end -%> | ||
\ | ||
|
||
|
||
|
||
#define FOR_EACH_WEBKIT_DEBUG_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_DEBUG_BOOL_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_DEBUG_UINT32_PREFERENCE(macro) \ | ||
\ | ||
|
||
#define FOR_EACH_WEBKIT_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \ | ||
FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \ | ||
\ | ||
|
Oops, something went wrong.