Bug 212451 - [Cocoa] Pass all defines from Platform.h to various scripts, not just the ones from .xcconfig
Summary: [Cocoa] Pass all defines from Platform.h to various scripts, not just the one...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
: 212500 (view as bug list)
Depends on: 212531
Blocks: 212418 212420 212500 233304
  Show dependency treegraph
 
Reported: 2020-05-27 18:21 PDT by Darin Adler
Modified: 2021-11-17 20:56 PST (History)
13 users (show)

See Also:


Attachments
Patch (32.89 KB, patch)
2020-05-27 20:01 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (31.25 KB, patch)
2020-05-27 20:12 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (31.19 KB, patch)
2020-05-27 20:22 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (31.72 KB, patch)
2020-05-28 08:18 PDT, Darin Adler
sam: review+
Details | Formatted Diff | Diff
Patch (34.40 KB, patch)
2020-05-29 10:58 PDT, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 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.
Comment 1 Darin Adler 2020-05-27 20:01:39 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-05-27 20:04:25 PDT
Hmm, seems like there’s a problem in JavaScriptCore. I’ll fix and upload a new patch.
Comment 3 Darin Adler 2020-05-27 20:12:58 PDT Comment hidden (obsolete)
Comment 4 Darin Adler 2020-05-27 20:13:23 PDT
OK, it’s going to work now.
Comment 5 Darin Adler 2020-05-27 20:22:57 PDT Comment hidden (obsolete)
Comment 6 Darin Adler 2020-05-28 08:18:47 PDT
Created attachment 400461 [details]
Patch
Comment 7 Sam Weinig 2020-05-28 09:05:56 PDT
Comment on attachment 400461 [details]
Patch

Nice.
Comment 8 Sam Weinig 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?
Comment 9 Darin Adler 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.
Comment 10 Darin Adler 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.
Comment 11 Darin Adler 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!
Comment 12 Darin Adler 2020-05-28 09:56:15 PDT
Committed r262245: <https://trac.webkit.org/changeset/262245>
Comment 13 Radar WebKit Bug Importer 2020-05-28 09:57:28 PDT
<rdar://problem/63722207>
Comment 14 Sam Weinig 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.
Comment 15 David Kilzer (:ddkilzer) 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/
Comment 16 Darin Adler 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?
Comment 17 David Kilzer (:ddkilzer) 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.
Comment 18 David Kilzer (:ddkilzer) 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>
Comment 19 Andy Estes 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
Comment 20 Yusuke Suzuki 2020-05-29 10:40:01 PDT
Re-opened since this is blocked by bug 212531
Comment 21 Darin Adler 2020-05-29 10:48:32 PDT
Preparing a new patch that uses ":=" to fix the performance problem.
Comment 22 Darin Adler 2020-05-29 10:58:25 PDT
Created attachment 400602 [details]
Patch
Comment 23 Andy Estes 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!
Comment 24 Darin Adler 2020-05-29 12:01:50 PDT
Committed r262309: <https://trac.webkit.org/changeset/262309>
Comment 25 Andy Estes 2020-05-29 12:37:24 PDT
*** Bug 212500 has been marked as a duplicate of this bug. ***