Bug 212451

Summary: [Cocoa] Pass all defines from Platform.h to various scripts, not just the ones from .xcconfig
Product: WebKit Reporter: Darin Adler <darin>
Component: Tools / TestsAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, andersca, ddkilzer, ews-watchlist, hi, keith_miller, mark.lam, msaboff, saam, sam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=212436
Bug Depends on: 212531    
Bug Blocks: 212418, 212420, 212500, 233304    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
sam: review+
Patch none

Darin Adler
Reported 2020-05-27 18:21:56 PDT
I’d like to move things from .xcconfig to PlatformEnableCocoa.h files. To make that possible the makefile needs to pass defines from there to the various derived sources scripts, not just the ones from the .xcconfig file. Found a good way to do it.
Attachments
Patch (32.89 KB, patch)
2020-05-27 20:01 PDT, Darin Adler
no flags
Patch (31.25 KB, patch)
2020-05-27 20:12 PDT, Darin Adler
no flags
Patch (31.19 KB, patch)
2020-05-27 20:22 PDT, Darin Adler
no flags
Patch (31.72 KB, patch)
2020-05-28 08:18 PDT, Darin Adler
sam: review+
Patch (34.40 KB, patch)
2020-05-29 10:58 PDT, Darin Adler
no flags
Darin Adler
Comment 1 2020-05-27 20:01:39 PDT Comment hidden (obsolete)
Darin Adler
Comment 2 2020-05-27 20:04:25 PDT
Hmm, seems like there’s a problem in JavaScriptCore. I’ll fix and upload a new patch.
Darin Adler
Comment 3 2020-05-27 20:12:58 PDT Comment hidden (obsolete)
Darin Adler
Comment 4 2020-05-27 20:13:23 PDT
OK, it’s going to work now.
Darin Adler
Comment 5 2020-05-27 20:22:57 PDT Comment hidden (obsolete)
Darin Adler
Comment 6 2020-05-28 08:18:47 PDT
Sam Weinig
Comment 7 2020-05-28 09:05:56 PDT
Comment on attachment 400461 [details] Patch Nice.
Sam Weinig
Comment 8 2020-05-28 09:09:41 PDT
One thing I was considering when I looked into this problem space earlier this year was trying to move away from doing any preprocessing of input files at all, and moving to a model where the script phases always produce the same output, but with the correct #ifdefs inserted into them. The potential benefit here would be that when doing something like switching from building iOS to building macOS, the generated files would not have to be regenerated (something that continues to take too long). I am curious if you think that is a direction worth pursing?
Darin Adler
Comment 9 2020-05-28 09:29:22 PDT
(In reply to Sam Weinig from comment #8) > One thing I was considering when I looked into this problem space earlier > this year was trying to move away from doing any preprocessing of input > files at all, and moving to a model where the script phases always produce > the same output, but with the correct #ifdefs inserted into them. The > potential benefit here would be that when doing something like switching > from building iOS to building macOS, the generated files would not have to > be regenerated (something that continues to take too long). > > I am curious if you think that is a direction worth pursing? I tried this first, but found too many cases that were hard to convert, so it wasn’t easy to do yet.
Darin Adler
Comment 10 2020-05-28 09:53:28 PDT
I have a fancier version of this patch that uses -MD to figure out the contents of FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES, but I am having trouble making that work without unwanted paths to specific files in the SDK finding their way into .xcfilelist files, so I will set it aside for now.
Darin Adler
Comment 11 2020-05-28 09:54:26 PDT
(In reply to Darin Adler from comment #9) > (In reply to Sam Weinig from comment #8) > > I am curious if you think that is a direction worth pursing? > > I tried this first, but found too many cases that were hard to convert, so > it wasn’t easy to do yet. To be clear, I do find this direction appealing, but it seems to be a moderately long road. We have a lot of different kinds of generated code!
Darin Adler
Comment 12 2020-05-28 09:56:15 PDT
Radar WebKit Bug Importer
Comment 13 2020-05-28 09:57:28 PDT
Sam Weinig
Comment 14 2020-05-28 10:29:41 PDT
(In reply to Darin Adler from comment #11) > (In reply to Darin Adler from comment #9) > > (In reply to Sam Weinig from comment #8) > > > I am curious if you think that is a direction worth pursing? > > > > I tried this first, but found too many cases that were hard to convert, so > > it wasn’t easy to do yet. > > To be clear, I do find this direction appealing, but it seems to be a > moderately long road. We have a lot of different kinds of generated code! Oh for sure. Just wanted to make sure we were thinking of a similar long term goal, even if it is far out in time. Glad we are on the same page.
David Kilzer (:ddkilzer)
Comment 15 2020-05-28 10:40:24 PDT
Comment on attachment 400461 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=400461&action=review > Source/JavaScriptCore/DerivedSources.make:34 > +FRAMEWORK_FLAGS = $(shell echo $(BUILT_PRODUCTS_DIR) $(FRAMEWORK_SEARCH_PATHS) $(SYSTEM_FRAMEWORK_SEARCH_PATHS) | $(PERL) -e 'print "-F " . join(" -F ", split(" ", <>));') > +HEADER_FLAGS = $(shell echo $(BUILT_PRODUCTS_DIR) $(HEADER_SEARCH_PATHS) $(SYSTEM_HEADER_SEARCH_PATHS) | $(PERL) -e 'print "-I" . join(" -I", split(" ", <>));') > +FEATURE_DEFINE_FLAGS = $(shell echo $(FEATURE_DEFINES) | $(PERL) -e 'print "-D" . join(" -D", split(" ", <>));') You could use map() instead of join() to remove the need to specify strings like "-F", "-I" and "-D" twice: $ echo "A B C D" | perl -e 'print "-I" . join(" -I", split(" ", <>));' -IA -IB -IC -ID $ echo "A B C D" | perl -e 'print join(" ", map("-I$_", split(" ", <>)));' -IA -IB -IC -ID Not necessary to change to land the patch. I think it's easier to read the code using map() because it treats every string the same way rather than trying to be clever. > Source/JavaScriptCore/DerivedSources.make:48 > +# FIXME: Should generate the list of everything included by Platform.h as a side effect of the above command. > +FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = Configurations/FeatureDefines.xcconfig DerivedSources.make Here's one way to do that (may need to adjust the grep string). Note that "-H" replaces "-E -P -dM". $ clang -H [args] -include "wtf/Platform.h" /dev/null 2>&1 | sed -e 's/^\.\.* //' | grep /Source/WTF/ > Source/WebCore/DerivedSources.make:36 > +FRAMEWORK_FLAGS = $(shell echo $(BUILT_PRODUCTS_DIR) $(FRAMEWORK_SEARCH_PATHS) $(SYSTEM_FRAMEWORK_SEARCH_PATHS) | perl -e 'print "-F " . join(" -F ", split(" ", <>));') > +HEADER_FLAGS = $(shell echo $(BUILT_PRODUCTS_DIR) $(HEADER_SEARCH_PATHS) $(SYSTEM_HEADER_SEARCH_PATHS) | perl -e 'print "-I" . join(" -I", split(" ", <>));') > +FEATURE_DEFINE_FLAGS = $(shell echo $(FEATURE_DEFINES) | perl -e 'print "-D" . join(" -D", split(" ", <>));') Ditto re: using map(). > Source/WebCore/DerivedSources.make:40 > +ifneq ($(SDKROOT),) > + SDK_FLAGS=-isysroot $(SDKROOT) > +endif Source/WebCore/Scripts/generate-derived-sources.sh passes SDKROOT on the make command-line, so this will NOT cause the same issue as Bug 212436. > Source/WebCore/DerivedSources.make:50 > +# FIXME: Should generate the list of everything included by Platform.h as a side effect of the above command. > +FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = Configurations/FeatureDefines.xcconfig DerivedSources.make Here's one way to do that (may need to adjust the grep string). Note that "-H" replaces "-E -P -dM". $ clang -H [args] -include "wtf/Platform.h" /dev/null 2>&1 | sed -e 's/^\.\.* //' | grep /Source/WTF/ > Source/WebKitLegacy/mac/MigrateHeaders.make:32 > +FRAMEWORK_FLAGS = $(shell echo $(BUILT_PRODUCTS_DIR) $(FRAMEWORK_SEARCH_PATHS) $(SYSTEM_FRAMEWORK_SEARCH_PATHS) | $(PERL) -e 'print "-F " . join(" -F ", split(" ", <>));') > +HEADER_FLAGS = $(shell echo $(BUILT_PRODUCTS_DIR) $(HEADER_SEARCH_PATHS) $(SYSTEM_HEADER_SEARCH_PATHS) | $(PERL) -e 'print "-I" . join(" -I", split(" ", <>));') > +FEATURE_DEFINE_FLAGS = $(shell echo $(FEATURE_DEFINES) | $(PERL) -e 'print "-D" . join(" -D", split(" ", <>));') Ditto re: using map(). > Source/WebKitLegacy/mac/MigrateHeaders.make:36 > +ifneq ($(SDKROOT),) > + SDK_FLAGS=-isysroot $(SDKROOT) > +endif Source/WebKitLegacy//mac/migrate-headers.sh does NOT include SDKROOT="$(SDKROOT)" when invoking make, so this could cause the same regression as Bug 212436. > Source/WebKitLegacy/mac/MigrateHeaders.make:46 > +# FIXME: Should generate the list of everything included by Platform.h as a side effect of the above command. > +FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = Configurations/FeatureDefines.xcconfig DerivedSources.make Here's one way to do that (may need to adjust the grep string). Note that "-H" replaces "-E -P -dM". $ clang -H [args] -include "wtf/Platform.h" /dev/null 2>&1 | sed -e 's/^\.\.* //' | grep /Source/WTF/
Darin Adler
Comment 16 2020-05-28 10:50:48 PDT
Comment on attachment 400461 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=400461&action=review >> Source/JavaScriptCore/DerivedSources.make:34 >> +FEATURE_DEFINE_FLAGS = $(shell echo $(FEATURE_DEFINES) | $(PERL) -e 'print "-D" . join(" -D", split(" ", <>));') > > You could use map() instead of join() to remove the need to specify strings like "-F", "-I" and "-D" twice: > > $ echo "A B C D" | perl -e 'print "-I" . join(" -I", split(" ", <>));' > -IA -IB -IC -ID > > $ echo "A B C D" | perl -e 'print join(" ", map("-I$_", split(" ", <>)));' > -IA -IB -IC -ID > > Not necessary to change to land the patch. I think it's easier to read the code using map() because it treats every string the same way rather than trying to be clever. I’d welcome this refinement, although I probably won’t do it myself. I just followed the pattern that was already present. >> Source/JavaScriptCore/DerivedSources.make:48 >> +FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = Configurations/FeatureDefines.xcconfig DerivedSources.make > > Here's one way to do that (may need to adjust the grep string). Note that "-H" replaces "-E -P -dM". > > $ clang -H [args] -include "wtf/Platform.h" /dev/null 2>&1 | sed -e 's/^\.\.* //' | grep /Source/WTF/ I have a local set of changes that make this work using "-MD -MF Platform.deps" in the compile line. Good to generate the dependencies with the same command that is actually used, so we don’t have flags differences or that sort of thing: FEATURE_AND_PLATFORM_DEFINES = $(shell $(CC) -std=gnu++1z -x c++ -E -P -dM $(SDK_FLAGS) $(TARGET_TRIPLE_FLAGS) $(FRAMEWORK_FLAGS) $(HEADER_FLAGS) $(FEATURE_DEFINE_FLAGS) -MD -MF Platform.deps -include "wtf/Platform.h" /dev/null | $(PERL) -ne "print if s/\#define ((HAVE_|USE_|ENABLE_|WTF_PLATFORM_)\w+) 1/\1/") FEATURE_AND_PLATFORM_DEFINE_DEPENDENCIES = Configurations/FeatureDefines.xcconfig DerivedSources.make $(shell $(PERL) -ne "s| \\||; print if m|$BUILT_PRODUCTS_DIR|" Platform.deps) However, I don’t plan to pursue this any time soon. You are welcome to if you like. >> Source/WebCore/DerivedSources.make:36 >> +FEATURE_DEFINE_FLAGS = $(shell echo $(FEATURE_DEFINES) | perl -e 'print "-D" . join(" -D", split(" ", <>));') > > Ditto re: using map(). Yes, there are three copies of the identical code in these three makefiles. >> Source/WebKitLegacy/mac/MigrateHeaders.make:32 >> +FEATURE_DEFINE_FLAGS = $(shell echo $(FEATURE_DEFINES) | $(PERL) -e 'print "-D" . join(" -D", split(" ", <>));') > > Ditto re: using map(). Yes, third copy of the same code. >> Source/WebKitLegacy/mac/MigrateHeaders.make:36 >> +endif > > Source/WebKitLegacy//mac/migrate-headers.sh does NOT include SDKROOT="$(SDKROOT)" when invoking make, so this could cause the same regression as Bug 212436. Would you be willing to fix that for me, or would you like me to handle it?
David Kilzer (:ddkilzer)
Comment 17 2020-05-28 12:04:40 PDT
(In reply to Darin Adler from comment #16) > Comment on attachment 400461 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=400461&action=review > > >> Source/WebKitLegacy/mac/MigrateHeaders.make:36 > >> +endif > > > > Source/WebKitLegacy//mac/migrate-headers.sh does NOT include SDKROOT="$(SDKROOT)" when invoking make, so this could cause the same regression as Bug 212436. > > Would you be willing to fix that for me, or would you like me to handle it? Yes. I have to now to fix my build: [...] === BUILD TARGET WebKitLegacy OF PROJECT WebKitLegacy WITH CONFIGURATION Debug === Check dependencies PhaseScriptExecution Migrate\ Headers /var/build/WebKitLegacy.build/Debug/WebKitLegacy.build/Script-1C6CB0510AA63EB000D23BFD.sh cd /Users/ddkilzer/Data/WebKit.git/Source/WebKitLegacy /bin/sh -c /var/build/WebKitLegacy.build/Debug/WebKitLegacy.build/Script-1C6CB0510AA63EB000D23BFD.sh clang: warning: no such sysroot directory: 'macosx.internal' [-Wmissing-sysroot] In file included from <built-in>:1: In file included from /var/build/Debug/usr/local/include/wtf/Platform.h:44: /var/build/Debug/usr/local/include/wtf/PlatformOS.h:36:10: fatal error: 'Availability.h' file not found #include <Availability.h> ^~~~~~~~~~~~~~~~ 1 error generated. sed -E -e 's/<WebCore\//<WebKitLegacy\//' -e "s/(^ *)WEBCORE_EXPORT /\1/" /var/build/Debug/DerivedSources/WebKitLegacy/WebCorePrivateHeaders/WebKitAvailability.h > /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders/WebKitAvailability.h; touch /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders sed -E -e 's/<WebCore\//<WebKitLegacy\//' -e "s/(^ *)WEBCORE_EXPORT /\1/" /var/build/Debug/DerivedSources/WebKitLegacy/WebCorePrivateHeaders/WebScriptObject.h > /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders/WebScriptObject.h; touch /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders sed -E -e 's/<WebCore\//<WebKitLegacy\//' -e "s/(^ *)WEBCORE_EXPORT /\1/" /var/build/Debug/DerivedSources/WebKitLegacy/WebCorePrivateHeaders/npapi.h > /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders/npapi.h; touch /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders sed -E -e 's/<WebCore\//<WebKitLegacy\//' -e "s/(^ *)WEBCORE_EXPORT /\1/" /var/build/Debug/DerivedSources/WebKitLegacy/WebCorePrivateHeaders/npfunctions.h > /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders/npfunctions.h; touch /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders sed -E -e 's/<WebCore\//<WebKitLegacy\//' -e "s/(^ *)WEBCORE_EXPORT /\1/" /var/build/Debug/DerivedSources/WebKitLegacy/WebCorePrivateHeaders/npruntime.h > /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders/npruntime.h; touch /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders sed -E -e 's/<WebCore\//<WebKitLegacy\//' -e "s/(^ *)WEBCORE_EXPORT /\1/" /var/build/Debug/DerivedSources/WebKitLegacy/WebCorePrivateHeaders/nptypes.h > /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders/nptypes.h; touch /var/build/Debug/WebKitLegacy.framework/Versions/A/PrivateHeaders clang: warning: no such sysroot directory: 'macosx.internal' [-Wmissing-sysroot] In file included from <built-in>:1: In file included from /var/build/Debug/usr/local/include/wtf/Platform.h:44: /var/build/Debug/usr/local/include/wtf/PlatformOS.h:36:10: fatal error: 'Availability.h' file not found #include <Availability.h> ^~~~~~~~~~~~~~~~ 1 error generated. make[4]: Nothing to be done for `reexport_headers'. Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure [...] Will commit as a follow-up/build fix to this momentarily.
David Kilzer (:ddkilzer)
Comment 18 2020-05-28 12:17:26 PDT
(In reply to Darin Adler from comment #12) > Committed r262245: <https://trac.webkit.org/changeset/262245> Follow-up build fix: Committed r262253: <https://trac.webkit.org/changeset/262253>
Andy Estes
Comment 19 2020-05-28 16:07:39 PDT
With this change, WebCore's "Check .xcfilelists" build phase went from taking less than a second to run on a no-op incremental build to taking over 95 seconds. Filed <https://webkit.org/b/212500> REGRESSION (r262245): WebCore's "Check .xcfilelists" build phase is ~100x slower
Yusuke Suzuki
Comment 20 2020-05-29 10:40:01 PDT
Re-opened since this is blocked by bug 212531
Darin Adler
Comment 21 2020-05-29 10:48:32 PDT
Preparing a new patch that uses ":=" to fix the performance problem.
Darin Adler
Comment 22 2020-05-29 10:58:25 PDT
Andy Estes
Comment 23 2020-05-29 11:13:37 PDT
(In reply to Darin Adler from comment #21) > Preparing a new patch that uses ":=" to fix the performance problem. Can confirm your latest patch fixes the performance problem. Thanks!
Darin Adler
Comment 24 2020-05-29 12:01:50 PDT
Andy Estes
Comment 25 2020-05-29 12:37:24 PDT
*** Bug 212500 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.