Title: [290227] trunk
Revision
290227
Author
[email protected]
Date
2022-02-20 08:01:42 -0800 (Sun, 20 Feb 2022)

Log Message

Generate compile_commands.json on macOS Builds
https://bugs.webkit.org/show_bug.cgi?id=235686

Patch by Brandon Stewart <[email protected]> on 2022-02-20
Reviewed by Saam Barati.

Add support for generating compile_commands.json file to WebKit.

compile_commands.json can be used by tools like clangd to provide code complete,
refactoring, formatting, and cross references.

Steps to generate the compile commands file:
make d EXPORT_COMPILE_COMMANDS=YES
generate-compile-commands WebKitBuild/Debug

.:

* Makefile.shared:

Source/WebKit:

* UIProcess/API/C/WKPageUIClient.h:

Tools:

* Scripts/build-jsc:
* Scripts/build-webkit:
* Scripts/generate-compile-commands: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (290226 => 290227)


--- trunk/ChangeLog	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/ChangeLog	2022-02-20 16:01:42 UTC (rev 290227)
@@ -1,3 +1,21 @@
+2022-02-20  Brandon Stewart  <[email protected]>
+
+        Generate compile_commands.json on macOS Builds
+        https://bugs.webkit.org/show_bug.cgi?id=235686
+
+        Reviewed by Saam Barati.
+
+        Add support for generating compile_commands.json file to WebKit.
+
+        compile_commands.json can be used by tools like clangd to provide code complete,
+        refactoring, formatting, and cross references.
+        
+        Steps to generate the compile commands file:
+        make d EXPORT_COMPILE_COMMANDS=YES
+        generate-compile-commands WebKitBuild/Debug
+
+        * Makefile.shared:
+
 2022-02-19  Philippe Normand  <[email protected]>
 
         [WPE][GTK] Enable Thunder and remove old Clearkey CDM/Decryptor

Modified: trunk/Makefile.shared (290226 => 290227)


--- trunk/Makefile.shared	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/Makefile.shared	2022-02-20 16:01:42 UTC (rev 290227)
@@ -47,6 +47,13 @@
 	endif
 endif
 
+ifneq (,$(EXPORT_COMPILE_COMMANDS))
+		XCODE_OPTIONS += OTHER_CFLAGS='$$(inherited) -gen-cdb-fragment-path $$(BUILT_PRODUCTS_DIR)/compile_commands'
+		XCODE_OPTIONS += GCC_PRECOMPILE_PREFIX_HEADER=NO
+		XCODE_OPTIONS += CLANG_ENABLE_MODULE_DEBUGGING=NO
+		XCODE_OPTIONS += COMPILER_INDEX_STORE_ENABLE=NO
+endif
+
 DEFAULT_VERBOSITY := $(shell defaults read org.webkit.BuildConfiguration BuildTranscriptVerbosity 2>/dev/null || echo "default")
 VERBOSITY ?= $(DEFAULT_VERBOSITY)
 

Modified: trunk/Source/WebKit/ChangeLog (290226 => 290227)


--- trunk/Source/WebKit/ChangeLog	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/Source/WebKit/ChangeLog	2022-02-20 16:01:42 UTC (rev 290227)
@@ -1,3 +1,21 @@
+2022-02-20  Brandon Stewart  <[email protected]>
+
+        Generate compile_commands.json on macOS Builds
+        https://bugs.webkit.org/show_bug.cgi?id=235686
+
+        Reviewed by Saam Barati.
+
+        Add support for generating compile_commands.json file to WebKit.
+
+        compile_commands.json can be used by tools like clangd to provide code complete,
+        refactoring, formatting, and cross references.
+        
+        Steps to generate the compile commands file:
+        make d EXPORT_COMPILE_COMMANDS=YES
+        generate-compile-commands WebKitBuild/Debug
+
+        * UIProcess/API/C/WKPageUIClient.h:
+
 2022-02-19  Chris Dumez  <[email protected]>
 
         Optimize DOM storage event dispatch

Modified: trunk/Source/WebKit/UIProcess/API/C/WKPageUIClient.h (290226 => 290227)


--- trunk/Source/WebKit/UIProcess/API/C/WKPageUIClient.h	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPageUIClient.h	2022-02-20 16:01:42 UTC (rev 290227)
@@ -135,8 +135,8 @@
 typedef void (*WKPageDidResignInputElementStrongPasswordAppearanceCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
 typedef bool (*WKPageShouldAllowDeviceOrientationAndMotionAccessCallback)(WKPageRef page, WKSecurityOriginRef securityOrigin, WKFrameInfoRef frame, const void *clientInfo);
 
-typedef void (*WKPageRunWebAuthenticationPanelCallback)();
-typedef void (*WKPageRequestWebAuthenticationNoGestureCallback)();
+typedef void (*WKPageRunWebAuthenticationPanelCallback)(void);
+typedef void (*WKPageRequestWebAuthenticationNoGestureCallback)(void);
 typedef void (*WKPageDecidePolicyForSpeechRecognitionPermissionRequestCallback)(WKPageRef page, WKSecurityOriginRef topOrigin, WKSpeechRecognitionPermissionCallbackRef callback);
 
 typedef void (*WKPageDecidePolicyForMediaKeySystemPermissionRequestCallback)(WKPageRef page, WKSecurityOriginRef topOrigin, WKStringRef keySystem, WKMediaKeySystemPermissionCallbackRef callback);

Modified: trunk/Tools/ChangeLog (290226 => 290227)


--- trunk/Tools/ChangeLog	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/Tools/ChangeLog	2022-02-20 16:01:42 UTC (rev 290227)
@@ -1,3 +1,23 @@
+2022-02-20  Brandon Stewart  <[email protected]>
+
+        Generate compile_commands.json on macOS Builds
+        https://bugs.webkit.org/show_bug.cgi?id=235686
+
+        Reviewed by Saam Barati.
+
+        Add support for generating compile_commands.json file to WebKit.
+
+        compile_commands.json can be used by tools like clangd to provide code complete,
+        refactoring, formatting, and cross references.
+        
+        Steps to generate the compile commands file:
+        make d EXPORT_COMPILE_COMMANDS=YES
+        generate-compile-commands WebKitBuild/Debug
+
+        * Scripts/build-jsc:
+        * Scripts/build-webkit:
+        * Scripts/generate-compile-commands: Added.
+
 2022-02-17  Jonathan Bedard  <[email protected]>
 
         [EWS] Enable iOS Simulator queues for PRs

Modified: trunk/Tools/Scripts/build-jsc (290226 => 290227)


--- trunk/Tools/Scripts/build-jsc	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/Tools/Scripts/build-jsc	2022-02-20 16:01:42 UTC (rev 290227)
@@ -61,6 +61,7 @@
 my $buildDir = "";
 my $startTime = time();
 my $useCCache = -1;
+my $exportCompileCommands = 0;
 
 my @features = getFeatureOptionList();
 
@@ -93,6 +94,7 @@
   --build-dir=<path>            Build out of tree in directory at <path>
 
   --[no-]use-ccache             Enable (or disable) CCache, if available
+  --export-compile-commands     Generate compile_commands.json (Apple platforms only)
 EOF
 
 my %options = (
@@ -105,7 +107,8 @@
     'makeargs=s' => \$makeArgs,
     'cmakeargs=s' => \@cmakeArgs,
     'build-dir=s' => \$buildDir,
-    'use-ccache!' => \$useCCache
+    'use-ccache!' => \$useCCache,
+    'export-compile-commands' => \$exportCompileCommands
 );
 
 foreach (@features) {
@@ -142,6 +145,8 @@
     $ENV{'WK_USE_CCACHE'} = "NO";
 }
 
+$ENV{'EXPORT_COMPILE_COMMANDS'} = "YES" if $exportCompileCommands;
+
 checkRequiredSystemConfig();
 setConfiguration();
 chdirWebKit();

Modified: trunk/Tools/Scripts/build-webkit (290226 => 290227)


--- trunk/Tools/Scripts/build-webkit	2022-02-20 15:45:26 UTC (rev 290226)
+++ trunk/Tools/Scripts/build-webkit	2022-02-20 16:01:42 UTC (rev 290227)
@@ -80,6 +80,7 @@
 my $archs32bit = 0;
 my $skipLibraryUpdate = 0;
 my $useCCache = -1;
+my $exportCompileCommands = 0;
 
 my @features = getFeatureOptionList();
 
@@ -146,6 +147,8 @@
 
   --[no-]use-ccache                 Enable (or disable) CCache, if available
 
+  --export-compile-commands         Generate compile_commands.json (Apple platforms only)
+
 EOF
 
 my %options = (
@@ -167,6 +170,7 @@
     'use-workspace!' => \$useWorkspace,
     'skip-library-update' => \$skipLibraryUpdate,
     'use-ccache!' => \$useCCache,
+    'export-compile-commands' => \$exportCompileCommands
 );
 
 # Build usage text and options list from features
@@ -191,6 +195,7 @@
     $ENV{'WK_USE_CCACHE'} = "NO";
 }
 
+$ENV{'EXPORT_COMPILE_COMMANDS'} = "YES" if $exportCompileCommands;
 
 my $productDir = productDir();
 

Added: trunk/Tools/Scripts/generate-compile-commands (0 => 290227)


--- trunk/Tools/Scripts/generate-compile-commands	                        (rev 0)
+++ trunk/Tools/Scripts/generate-compile-commands	2022-02-20 16:01:42 UTC (rev 290227)
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2022 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.
+# 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+#     its contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+
+# Script to generate compile_commands.json file
+
+import re
+import os
+import sys
+import glob
+import json
+
+# Change to the root of WebKit Directory
+file_dir = os.path.dirname(os.path.realpath(__file__))
+base_dir = file_dir + "/../../"
+os.chdir(base_dir)
+
+# Check compile_commands folder exists
+compile_commands_dir = sys.argv[1] + "/compile_commands/"
+
+if not os.path.exists(compile_commands_dir):
+    print("Please specify the build directory with compile_commands.")
+    print("Example: generate-compile-commands WebKitBuild/Release")
+    exit(1)
+
+# Generate compile_commands.json
+
+# For things not to horribly break for users during normal use we need to validate the compiler is spitting out
+# valid json files. Sometimes if a compile error happens or the user stops the build part way through
+# there will be a very invalid json file sitting in the directory. When we go to bundle it up into the final
+# compile_commands.json file, we now have an invalid compile_commands.json file and clangd will not work.
+# To prevent this from happening we should check that every json file we add is valid, and also ensure there are no 
+# duplicate entries. We will build a map of all the valid files.
+
+# Key   - JSON file contents
+# Value - Timestamp contents
+files = dict()
+
+# Do not index third party code.
+# Most people probably do not need it.
+third_party_regex = re.compile('Source/ThirdParty')
+
+for j_file_name in glob.glob(compile_commands_dir + "/*.json"):
+    j_file = open(j_file_name, "r")
+    json_contents = j_file.read()
+
+    if third_party_regex.search(json_contents):
+        continue
+
+    # Try to load JSON File
+    try: 
+        # -2 gets rid of the comma at the end of the file.
+        json.loads(json_contents[:-2])
+    except Exception:
+        print("Invalid JSON File: " + j_file_name)
+        continue
+
+    # Validate if the json file already exists in the map.
+    if json_contents in files:
+        pass
+    else:
+        files[json_contents] = os.path.getmtime(j_file_name)
+
+# Remove any previous compile_commands.json
+try:
+    os.remove("compile_commands.json")
+except Exception:
+    pass
+
+# Write the new compile_commands.json file
+new_compile_commands_file = open("compile_commands.json", 'w')
+new_compile_commands_file.write("[\n")
+
+# We should probably remove the trailing comma in the last entry, but
+# clangd does not seem to mind.
+for key in files.keys():
+    new_compile_commands_file.write(key)
+
+new_compile_commands_file.write("]\n")
+new_compile_commands_file.close()
+
+print("Generated Compile Commands!")
Property changes on: trunk/Tools/Scripts/generate-compile-commands
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to