Bug 236683 - [XCBuild] Use native build phases to copy PAL's headers
Summary: [XCBuild] Use native build phases to copy PAL's headers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Elliott Williams
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-15 18:06 PST by Elliott Williams
Modified: 2022-02-21 12:44 PST (History)
2 users (show)

See Also:


Attachments
Native PAL Headers via build rules (178.15 KB, patch)
2022-02-15 19:08 PST, Elliott Williams
no flags Details | Formatted Diff | Diff
Native PAL Headers via build rules v2 (170.60 KB, patch)
2022-02-15 21:25 PST, Elliott Williams
ap: review+
Details | Formatted Diff | Diff
Use a legacy-only script phase to share more of the codepath (184.40 KB, patch)
2022-02-16 15:45 PST, Elliott Williams
no flags Details | Formatted Diff | Diff
Native PAL Headers via build rules + a legacy-only script phase, v2 (184.19 KB, patch)
2022-02-16 18:47 PST, Elliott Williams
no flags Details | Formatted Diff | Diff
Rebase and fix conflicts (184.20 KB, patch)
2022-02-18 14:18 PST, Elliott Williams
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Elliott Williams 2022-02-15 18:06:55 PST
Similar to WTF in https://bugs.webkit.org/show_bug.cgi?id=235744, we need to use native build system tasks to copy PAL's headers, instead of relying on an rsync-based script.
Comment 1 Elliott Williams 2022-02-15 19:08:43 PST
Created attachment 452123 [details]
Native PAL Headers via build rules

See the ChangeLog for more details, but I figured out a way to do nested headers without adding a bunch of copy file phases, like was done for WTF. This makes the project easier for devs to understand (all headers go in the same phase), plus, PAL has more nested directories than WTF does.

The key idea is that if you know the *depth* of a nested header, you can use build setting macros to produce its relative path. For example, given:

    PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/pal
    INPUT_FILE_DIR = Source/WebCore/PAL/pal/text
    INPUT_FILE_NAME = EncodingTables.h
    
the path for <pal/text/EncodingTables.h> is:

    $(PRIVATE_HEADERS_FOLDER_PATH)/$(INPUT_FILE_DIR:dir:standardizepath:base)/$(INPUT_FILE_NAME)

For deeper headers like <pal/crypto/tasn1/Utilities.h>, we give the last *two* directory components:

    $(PRIVATE_HEADERS_FOLDER_PATH)/$(INPUT_FILE_DIR:dir:standardizepath:dir:standardizepath:base)/$(INPUT_FILE_DIR:dir:standardizepath:base)/$(INPUT_FILE_NAME)

and so on.

These paths form the outputs of separate build rules which match each depth of nested header we need.
Comment 2 Radar WebKit Bug Importer 2022-02-15 19:09:19 PST
<rdar://problem/89001407>
Comment 3 Elliott Williams 2022-02-15 21:25:56 PST
Created attachment 452143 [details]
Native PAL Headers via build rules v2

For compatibility, this patch keeps the "Copy PAL Headers" rsync script and and runs it when using the legacy build system.
Comment 4 Alexey Proskuryakov 2022-02-16 10:05:13 PST
Comment on attachment 452143 [details]
Native PAL Headers via build rules v2

Supporting two different code paths until we completely drop the legacy build system support seems potentially troublesome. I did not think through this patch enough to have a feel of how likely it is to break the build in just one build system when making changes.
Comment 5 Elliott Williams 2022-02-16 15:11:40 PST
(In reply to Alexey Proskuryakov from comment #4)
> Comment on attachment 452143 [details]
> Native PAL Headers via build rules v2
> 
> Supporting two different code paths until we completely drop the legacy
> build system support seems potentially troublesome. I did not think through
> this patch enough to have a feel of how likely it is to break the build in
> just one build system when making changes.

Agreed, I don't like it either. This codepath will be tested in production builds which use XCBuild, and by the builds.webkit.org bot we are setting up in https://bugs.webkit.org/show_bug.cgi?id=236726.

An alternative approach I tried was to have the legacy build system copy to a flattened directory (/usr/local/include/pal_flattened), and then have a script go through and "nest" those headers back to their proper hierarchy. It's still quite a bit different from the XCBuild code path, but does ensure that all the headers PAL is using are part of Headers phase. I'll put that patch up too and we can decide which is best.
Comment 6 Elliott Williams 2022-02-16 15:45:07 PST
Created attachment 452262 [details]
Use a legacy-only script phase to share more of the codepath
Comment 7 Elliott Williams 2022-02-16 18:47:45 PST
Created attachment 452285 [details]
Native PAL Headers via build rules + a legacy-only script phase, v2

Per offline discussion, I think we should move forward with an approach that deletes the rsync script entirely, and uses a legacy-only script phase to un-flatten the headers. This has the benefit of enforcing that, on the legacy build system, all headers must be part of the target's Headers phase.
Comment 8 Alexey Proskuryakov 2022-02-16 22:02:28 PST
Comment on attachment 452285 [details]
Native PAL Headers via build rules + a legacy-only script phase, v2

View in context: https://bugs.webkit.org/attachment.cgi?id=452285&action=review

> Source/WebCore/PAL/Configurations/PAL.xcconfig:51
> +PRIVATE_HEADERS_FOLDER_PATH_legacy = /usr/local/include/pal_flattened;

This is a temporary directory, correct? I feel like there must be a more appropriate place for intermediate files.
Comment 9 Elliott Williams 2022-02-17 12:32:45 PST
(In reply to Alexey Proskuryakov from comment #8)
> Comment on attachment 452285 [details]
> Native PAL Headers via build rules + a legacy-only script phase, v2
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=452285&action=review
> 
> > Source/WebCore/PAL/Configurations/PAL.xcconfig:51
> > +PRIVATE_HEADERS_FOLDER_PATH_legacy = /usr/local/include/pal_flattened;
> 
> This is a temporary directory, correct? I feel like there must be a more
> appropriate place for intermediate files.

I'll try again to find a way to put this in TARGET_TEMP_DIR, but the problem seems to be that Headers phases are Special, and Xcode insists on copying them into BUILT_PRODUCTS_DIR or DSTROOT (for non-install or install builds respectively).

This is why it isn't trying to copy them into the system's `/usr/local` directory even though that's what PRIVATE_HEADERS_FOLDER_PATH specifies.
Comment 10 EWS 2022-02-18 13:16:14 PST
Tools/Scripts/svn-apply failed to apply attachment 452285 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 11 Elliott Williams 2022-02-18 14:18:44 PST
Created attachment 452581 [details]
Rebase and fix conflicts
Comment 12 Elliott Williams 2022-02-18 14:19:15 PST
Comment on attachment 452581 [details]
Rebase and fix conflicts

This patch resolves conflicts only, no need for additional review.
Comment 13 Elliott Williams 2022-02-18 17:38:08 PST
Comment on attachment 452581 [details]
Rebase and fix conflicts

Windows test failure looks like a flake.
Comment 14 Elliott Williams 2022-02-21 09:46:34 PST
Comment on attachment 452581 [details]
Rebase and fix conflicts

Mac test failures were fixed in r290192, back to cq+
Comment 15 EWS 2022-02-21 12:12:38 PST
Committed r290260 (?): <https://commits.webkit.org/r290260>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 452581 [details].