Skip to content
Permalink
Browse files
[WPE][GTK] Improve dependency tracking of PDF.js files (and other GRe…
…sources)

https://bugs.webkit.org/show_bug.cgi?id=240535

Patch by Michael Catanzaro <mcatanzaro@redhat.com> on 2022-05-19
Reviewed by Adrian Perez de Castro.

This commit does two things. First, for each use of
glib-compile-resources, it adds the --dependency-file argument in order
to make the build command depend on the files included in the GResource
manifest, to ensure the resource is automatically recompiled whenever
any of its source files change. Second, for PDF.js only, it replaces the
GLOB_RECURSE command with a list of source files. The
generate-pdfjs-gresource-manifest.py script is adapted to create CMake
file lists in addition to GResource manifests, and renamed from
-gresource-manifest.py to -resource-manifest.py. The web inspector
GResource would benefit from similar work, but that will be a problem
for another day.

* Tools/TestWebKitAPI/glib/CMakeLists.txt:
* Tools/glib/generate-pdfjs-resource-manifest.py: Renamed from Tools/glib/generate-pdfjs-gresource-manifest.py.
(get_filenames):
(get_filenames.resource_name):
(is_compressible):
(write_cmake_file):
(write_gresource_manifest):
* Source/ThirdParty/pdfjs/PdfJSFiles.cmake: Added.
* Source/ThirdParty/pdfjs/README.webkit:
* Source/WebKit/InspectorGResources.cmake:
* Source/WebKit/PdfJSGResources.cmake:
* Source/WebKit/PlatformGTK.cmake:
* Source/WebKit/PlatformWPE.cmake:
* CMakeLists.txt:
* Source/cmake/OptionsGTK.cmake:
* Source/cmake/OptionsWPE.cmake:

Canonical link: https://commits.webkit.org/250761@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
mcatanzaro authored and webkit-commit-queue committed May 19, 2022
1 parent f6f5627 commit 6cd89696b5d406c1a3d9a7a9bbb18fda9284fa1f
Showing 11 changed files with 434 additions and 26 deletions.
@@ -13,6 +13,11 @@
cmake_minimum_required(VERSION 3.12)
project(WebKit)

# Remove this cmake_policy() after upgrading cmake_minimum_required() to 3.20.
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20")
cmake_policy(SET CMP0116 OLD)
endif ()

# -----------------------------------------------------------------------------
# Common configuration
#------------------------------------------------------------------------------

Large diffs are not rendered by default.

@@ -6,4 +6,6 @@ To update to a newer version:
2. Grab a new official release (*-dist.zip, modern browsers version) distributed at GitHub and extract everything into this directory.
3. Delete the sourcemap (.js.map) files (currently viewer.js.map, pdf.js.map, pdf.worker.js.map, and pdf.sandbox.js.map).
4. Delete the example PDF file, compressed.tracemonkey-pldi-09.pdf.
5. Sanity-check the result by loading https://www.irs.gov/pub/irs-pdf/i1040gi.pdf (big PDF) and https://www.irs.gov/pub/irs-pdf/f1040.pdf (PDF with forms)
5. From top source dir, run: 'Tools/glib/generate-pdfjs-resource-manifest.py --cmake --input=Source/ThirdParty/pdfjs --output=Source/ThirdParty/pdfjs/PdfJSFiles.cmake'
6. Build WebKit, your favorite port will do
7. Sanity-check by loading https://www.irs.gov/pub/irs-pdf/i1040gi.pdf (big PDF) and https://www.irs.gov/pub/irs-pdf/f1040.pdf (PDF with forms)
@@ -9,9 +9,10 @@ macro(WEBKIT_BUILD_INSPECTOR_GRESOURCES _derived_sources_dir)
)

add_custom_command(
OUTPUT ${_derived_sources_dir}/InspectorGResourceBundle.c
OUTPUT ${_derived_sources_dir}/InspectorGResourceBundle.c ${_derived_sources_dir}/InspectorGResourceBundle.deps
DEPENDS ${_derived_sources_dir}/InspectorGResourceBundle.xml
COMMAND glib-compile-resources --generate --sourcedir=${_derived_sources_dir}/InspectorResources/WebInspectorUI --target=${_derived_sources_dir}/InspectorGResourceBundle.c ${_derived_sources_dir}/InspectorGResourceBundle.xml
DEPFILE {_derived_sources_dir}/InspectorGResourceBundle.deps
COMMAND glib-compile-resources --generate --sourcedir=${_derived_sources_dir}/InspectorResources/WebInspectorUI --target=${_derived_sources_dir}/InspectorGResourceBundle.c --dependency-file=${_derived_sources_dir}/InspectorGResourceBundle.deps ${_derived_sources_dir}/InspectorGResourceBundle.xml
VERBATIM
)
endmacro()
@@ -1,4 +1,4 @@
file(GLOB_RECURSE PdfJSFiles CONFIGURE_DEPENDS ${THIRDPARTY_DIR}/pdfjs/*)
include(../ThirdParty/pdfjs/PdfJSFiles.cmake)

set(PdfJSExtraFiles
${WEBCORE_DIR}/Modules/pdfjs-extras/content-script.js
@@ -7,29 +7,28 @@ set(PdfJSExtraFiles
macro(WEBKIT_BUILD_PDFJS_GRESOURCES _derived_sources_dir)
add_custom_command(
OUTPUT ${_derived_sources_dir}/PdfJSGResourceBundle.xml
DEPENDS ${TOOLS_DIR}/glib/generate-pdfjs-gresource-manifest.py
${PdfJSFiles}
COMMAND ${PYTHON_EXECUTABLE} ${TOOLS_DIR}/glib/generate-pdfjs-gresource-manifest.py --input=${THIRDPARTY_DIR}/pdfjs --output=${_derived_sources_dir}/PdfJSGResourceBundle.xml
DEPENDS ${TOOLS_DIR}/glib/generate-pdfjs-resource-manifest.py ${PdfJSFiles}
COMMAND ${PYTHON_EXECUTABLE} ${TOOLS_DIR}/glib/generate-pdfjs-resource-manifest.py --gresource --input=${THIRDPARTY_DIR}/pdfjs --output=${_derived_sources_dir}/PdfJSGResourceBundle.xml
VERBATIM
)

add_custom_command(
OUTPUT ${_derived_sources_dir}/PdfJSGResourceBundle.c
OUTPUT ${_derived_sources_dir}/PdfJSGResourceBundle.c ${_derived_sources_dir}/PdfJSGResourceBundle.deps
DEPENDS ${_derived_sources_dir}/PdfJSGResourceBundle.xml
COMMAND glib-compile-resources --generate --sourcedir=${THIRDPARTY_DIR}/pdfjs --target=${_derived_sources_dir}/PdfJSGResourceBundle.c ${_derived_sources_dir}/PdfJSGResourceBundle.xml
DEPFILE ${_derived_sources_dir}/PdfJSGResourceBundle.deps
COMMAND glib-compile-resources --generate --sourcedir=${THIRDPARTY_DIR}/pdfjs --target=${_derived_sources_dir}/PdfJSGResourceBundle.c --dependency-file=${_derived_sources_dir}/PdfJSGResourceBundle.deps ${_derived_sources_dir}/PdfJSGResourceBundle.xml
VERBATIM
)

add_custom_command(
OUTPUT ${_derived_sources_dir}/PdfJSGResourceBundleExtras.xml
DEPENDS ${TOOLS_DIR}/glib/generate-pdfjs-gresource-manifest.py
${PdfJSExtraFiles}
COMMAND ${PYTHON_EXECUTABLE} ${TOOLS_DIR}/glib/generate-pdfjs-gresource-manifest.py --input=${WEBCORE_DIR}/Modules/pdfjs-extras --output=${_derived_sources_dir}/PdfJSGResourceBundleExtras.xml
DEPENDS ${TOOLS_DIR}/glib/generate-pdfjs-resource-manifest.py ${PdfJSExtraFiles}
COMMAND ${PYTHON_EXECUTABLE} ${TOOLS_DIR}/glib/generate-pdfjs-resource-manifest.py --gresource --input=${WEBCORE_DIR}/Modules/pdfjs-extras --output=${_derived_sources_dir}/PdfJSGResourceBundleExtras.xml
VERBATIM
)

add_custom_command(
OUTPUT ${_derived_sources_dir}/PdfJSGResourceBundleExtras.c
OUTPUT ${_derived_sources_dir}/PdfJSGResourceBundleExtras.c ${_derived_sources_dir}/PdfJSGResourceBundleExtras.deps
DEPENDS ${_derived_sources_dir}/PdfJSGResourceBundleExtras.xml
COMMAND glib-compile-resources --generate --sourcedir=${WEBCORE_DIR}/Modules/pdfjs-extras --target=${_derived_sources_dir}/PdfJSGResourceBundleExtras.c ${_derived_sources_dir}/PdfJSGResourceBundleExtras.xml
VERBATIM
@@ -597,9 +597,10 @@ file(WRITE ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
)

add_custom_command(
OUTPUT ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c
OUTPUT ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.deps
DEPENDS ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
COMMAND glib-compile-resources --generate --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/Resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/platform/audio/resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebKit/Resources/gtk --target=${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
DEPFILE ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.deps
COMMAND glib-compile-resources --generate --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/Resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/platform/audio/resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebKit/Resources/gtk --target=${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c --dependency-file=${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.deps ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
VERBATIM
)

@@ -280,9 +280,10 @@ file(WRITE ${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
)

add_custom_command(
OUTPUT ${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c
OUTPUT ${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.deps
DEPENDS ${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
COMMAND glib-compile-resources --generate --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/Resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/platform/audio/resources --target=${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c ${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
DEPFILE ${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.deps
COMMAND glib-compile-resources --generate --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/Resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/platform/audio/resources --target=${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.c --dependency-file=${WebKit2Gtk_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.deps ${WebKit_DERIVED_SOURCES_DIR}/WebKitResourcesGResourceBundle.xml
VERBATIM
)

@@ -5,6 +5,11 @@ WEBKIT_OPTION_BEGIN()

SET_PROJECT_VERSION(2 37 0)

# This is required because we use the DEPFILE argument to add_custom_command().
# Remove after upgrading cmake_minimum_required() to 3.20.
if (${CMAKE_VERSION} VERSION_LESS "3.20" AND NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
message(FATAL_ERROR "Building with Makefiles requires CMake 3.20 or newer. Either enable Ninja by passing -GNinja, or upgrade CMake.")
endif ()

set(USER_AGENT_BRANDING "" CACHE STRING "Branding to add to user agent string")

@@ -3,6 +3,12 @@ include(VersioningUtils)

SET_PROJECT_VERSION(2 35 1)

# This is required because we use the DEPFILE argument to add_custom_command().
# Remove after upgrading cmake_minimum_required() to 3.20.
if (${CMAKE_VERSION} VERSION_LESS "3.20" AND NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
message(FATAL_ERROR "Building with Makefiles requires CMake 3.20 or newer. Either enable Ninja by passing -GNinja, or upgrade CMake.")
endif ()

set(USER_AGENT_BRANDING "" CACHE STRING "Branding to add to user agent string")

find_package(Cairo 1.14.0 REQUIRED)
@@ -119,13 +119,16 @@ if (COMPILER_IS_GCC_OR_CLANG)
endif ()

add_custom_command(
OUTPUT ${TEST_RESOURCES_DIR}/webkitglib-tests-resources.gresource
OUTPUT ${TEST_RESOURCES_DIR}/webkitglib-tests-resources.gresource ${TEST_RESOURCES_DIR}/webkitglib-tests-resources.deps
DEPENDS ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/resources/webkitglib-tests.gresource.xml
${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/resources/link-title.js
DEPFILE ${TEST_RESOURCES_DIR}/webkitglib-tests-resources.deps
COMMAND glib-compile-resources
--target=${TEST_RESOURCES_DIR}/webkitglib-tests-resources.gresource
--sourcedir=${CMAKE_SOURCE_DIR}
--dependency-file=${TEST_RESOURCES_DIR}/webkitglib-tests-resources.deps
${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/resources/webkitglib-tests.gresource.xml
VERBATIM
)

add_custom_target(test-gresource-bundle
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# Copyright (C) 2022 Igalia S.L.
# Copyright (C) 2022 Red Hat Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -24,6 +25,7 @@
BASE_DIRS = {'pdfjs/', 'pdfjs-extras/'}

IGNORE = {'LICENSE',
'PdfJSFiles.cmake',
'README.webkit',
'web/cmaps/LICENSE',
'web/standard_fonts/LICENSE_FOXIT',
@@ -44,6 +46,8 @@ def resource_name(filename):
dirs.sort()
files.sort()
for file in files:
# FIXME: Find a more sophisticated way to ignore unwanted
# port-specific files, so this will work for Cocoa ports too.
if os.path.basename(root) == 'cocoa':
continue
filename = os.path.join(root, file)
@@ -57,7 +61,7 @@ def resource_name(filename):
name = name.replace(os.sep, '/')
if name not in IGNORE:
if os.path.splitext(name)[1] not in VALID_EXTENSIONS:
print('Unexpected file %s, please teach generate-pdfjs-gresource-manifest.py how to handle it' % filename, file=sys.stderr)
print('Unexpected file %s, please teach generate-pdfjs-resource-manifest.py how to handle it' % filename, file=sys.stderr)
sys.exit(1)
filenames.append(name)

@@ -68,15 +72,15 @@ def is_compressible(filename):
return os.path.splitext(filename)[1] in COMPRESSIBLE_EXTENSIONS


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate a GResources file for pdfjs.')
parser.add_argument('--input', type=str,
help='the input directory')
parser.add_argument('--output', nargs='?', type=argparse.FileType('w'), default=sys.stdout,
help='the output file')
def write_cmake_file(args):
args.output.write("# This file was generated by Tools/glib/generate-pdfjs-resource-manifest.py. Do not modify manually.\n")
args.output.write('set(PDFJSFiles\n')
for filename in get_filenames(args.input):
args.output.write(' ${THIRDPARTY_DIR}/pdfjs/%s\n' % filename)
args.output.write(')')

args = parser.parse_args(sys.argv[1:])

def write_gresource_manifest(args):
args.output.write("""<?xml version=1.0 encoding=UTF-8?>
<gresources>
<gresource prefix="/org/webkit/pdfjs">
@@ -96,3 +100,28 @@ def is_compressible(filename):
args.output.write(""" </gresource>
</gresources>
""")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate a GResources file for pdfjs.')
parser.add_argument('--input', type=str,
help='the input directory')
parser.add_argument('--output', nargs='?', type=argparse.FileType('w'), default=sys.stdout,
help='the output file')
parser.add_argument('--cmake', action='store_true',
help='generate CMake file list')
parser.add_argument('--gresource', action='store_true',
help='generate GResource manifest')

args = parser.parse_args(sys.argv[1:])

if args.cmake and args.gresource:
print('Cannot pass both --cmake and --gresource at the same time', file=sys.stderr)
sys.exit(1)
elif args.cmake:
write_cmake_file(args)
elif args.gresource:
write_gresource_manifest(args)
else:
print('Must pass either --cmake or --gresource', file=sys.stderr)
sys.exit(1)

0 comments on commit 6cd8969

Please sign in to comment.