Skip to content
Permalink
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
Sam Weinig authored and webkit-commit-queue committed Oct 24, 2017
1 parent c1b8c01 commit fa7c2b0bbc926f9b3a4655af5bb5fa04c43b4877
Showing 9 changed files with 1,502 additions and 455 deletions.
@@ -902,6 +902,21 @@ list(APPEND WebKit_HEADERS
${DERIVED_SOURCES_WEBKIT_DIR}/WebAutomationSessionProxyScriptSource.h
)

set(WebKit_WEB_PREFERENCES_TEMPLATES
${WEBKIT_DIR}/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb
)

add_custom_command(
OUTPUT ${DERIVED_SOURCES_WEBKIT_DIR}/WebPreferencesDefinitions.h
MAIN_DEPENDENCY ${WEBKIT_DIR}/Shared/WebPreferences.yaml
DEPENDS ${WebKit_WEB_PREFERENCES_TEMPLATES}
COMMAND ${RUBY_EXECUTABLE} ${WEBKIT_DIR}/Scripts/GeneratePreferences.rb --input ${WEBKIT_DIR}/Shared/WebPreferences.yaml --outputDir "${DERIVED_SOURCES_WEBKIT_DIR}"
VERBATIM)

list(APPEND WebKit_HEADERS
${DERIVED_SOURCES_WEBKIT_DIR}/WebPreferencesDefinitions.h
)

list(APPEND WebKit_SOURCES ${WebKit_DERIVED_SOURCES})

WEBKIT_FRAMEWORK(WebKit)
@@ -1,3 +1,40 @@
2017-10-24 Sam Weinig <sam@webkit.org>

[Settings] Add initial support for generating preferences related code
https://bugs.webkit.org/show_bug.cgi?id=178656

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.

2017-10-24 Matt Lewis <jlewis3@apple.com>

Unreviewed, rolling out r223889.
@@ -284,3 +284,15 @@ all : $(firstword $(AUTOMATION_PROTOCOL_OUTPUT_FILES))
$(DELETE) $(basename $(notdir $<)).min.js

all : WebAutomationSessionProxyScriptSource.h

# WebPreferences generation

WEB_PREFERENCES_TEMPLATES = \
$(WebKit2)/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb \
#

all : WebPreferencesDefinitions.h

WebPreferencesDefinitions%h : $(WebKit2)/Scripts/GeneratePreferences.rb $(WEB_PREFERENCES_TEMPLATES) $(WebKit2)/Shared/WebPreferences.yaml
$(RUBY) $< --input $(WebKit2)/Shared/WebPreferences.yaml

@@ -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"))
@@ -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) \
\

0 comments on commit fa7c2b0

Please sign in to comment.