Bug 238409 - [XCBuild] WebKitLegacy's "Migrated headers" script does not emit task information
Summary: [XCBuild] WebKitLegacy's "Migrated headers" script does not emit task informa...
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: 238639
Blocks:
  Show dependency treegraph
 
Reported: 2022-03-25 21:45 PDT by Elliott Williams
Modified: 2022-04-04 10:00 PDT (History)
3 users (show)

See Also:


Attachments
Patch (42.30 KB, patch)
2022-03-25 22:16 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Patch (44.49 KB, patch)
2022-03-28 10:13 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Build fixes + review feedback (47.98 KB, patch)
2022-03-29 09:51 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Patch (48.02 KB, patch)
2022-03-29 15:48 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Patch (49.08 KB, patch)
2022-03-30 10:25 PDT, Elliott Williams
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (49.07 KB, patch)
2022-03-30 11:16 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Patch (45.90 KB, patch)
2022-03-30 16:38 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Fix typo, pre-approved (45.92 KB, patch)
2022-03-31 11:06 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
[fast-cq] Rebase with trunk (45.86 KB, patch)
2022-03-31 14:32 PDT, Elliott Williams
no flags Details | Formatted Diff | Diff
Fix symlinks modifying BUILT_PRODUCTS_DIR (45.95 KB, patch)
2022-04-01 16:16 PDT, Elliott Williams
no flags 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-03-25 21:45:05 PDT
Similar to https://bugs.webkit.org/show_bug.cgi?id=238213, we'll need to use a build rule + file references to replace the Makefile that implements WebCore -> WebKitLegacy migration logic. This will be unique, however, in that we need to run tapi-reexport on the migrated WebCore headers, and ensure that WebKitLegacy's exported symbols do not change.
Comment 1 Radar WebKit Bug Importer 2022-03-25 21:45:33 PDT
<rdar://problem/90869551>
Comment 2 Elliott Williams 2022-03-25 22:16:59 PDT
Created attachment 455826 [details]
Patch
Comment 3 Elliott Williams 2022-03-28 10:13:08 PDT
Created attachment 455924 [details]
Patch
Comment 4 Alexey Proskuryakov 2022-03-29 09:05:52 PDT
Comment on attachment 455924 [details]
Patch

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

Marking r- because this breaks the build.

> Source/WebKitLegacy/ChangeLog:25
> +        multicore machine it should be faster than blocking WebKitLegacy's build process on the

This matches my instincts, yet I'm curious if you measured the difference.

> Source/WebKitLegacy/mac/ChangeLog:11
> +        USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES, so that the "Generate Export Files" phase can

I didn't know this existed!

> Source/WebKitLegacy/mac/Configurations/WebKitLegacy.xcconfig:38
> +// WebEventRegion.h is migrated when building for an iOS family target with an internal SDKâ¦
> +INCLUDED_MIGRATED_HEADERS_YES_cocoatouch = WebEventRegion.h;
> +// â¦or when --ios-touch-events was passed to build-webkit manually.

I'm guessing these are ellipses? Not sure how I feel about them, would probably use ASCII.

> Source/WebKitLegacy/mac/Configurations/WebKitLegacy.xcconfig:42
> +// The "Generate Export Files" build pahse needs this setting to rerun when any migrated header changes:

typo: pahse.

> Tools/ChangeLog:11
> +        script should check PrivateHeaders/ too.

Not sure if this comment matches what the change does. The change switches from "Headers" to "PrivateHeaders", so it's not obvious why it's a "too".
Comment 5 Elliott Williams 2022-03-29 09:51:23 PDT
Created attachment 456034 [details]
Build fixes + review feedback
Comment 6 Elliott Williams 2022-03-29 11:50:19 PDT
(In reply to Alexey Proskuryakov from comment #4)
> Comment on attachment 455924 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=455924&action=review
> 
> Marking r- because this breaks the build.
> 
> > Source/WebKitLegacy/ChangeLog:25
> > +        multicore machine it should be faster than blocking WebKitLegacy's build process on the
> 
> This matches my instincts, yet I'm curious if you measured the difference.

I did some back-of-napkin calculations earlier, but here's some actual data (measuring CPU time in seconds) over 6 builds. These were generated using "Build with Timing Summary" in Xcode:

Style       Build time (Median) RuleScriptExecution (Median)    PhaseScriptExecution (Median)
Build rule  34.8                14.754                          4.213
Make        33.6                10.844                          4.715

On my 12-core machine, the extra 3.91 sec in RuleScriptExecution should be 0.32 sec of CPU time, which is less than the 0.50 sec execution time of the build phase. In practice, the actual build time was slightly higher for the rule phases, which may be explained by the build system having additional overhead or the script phase being able to execute while other targets in the workspace are building. Still, it seems like this is a scalable approach.


> > Source/WebKitLegacy/mac/ChangeLog:11
> > +        USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES, so that the "Generate Export Files" phase can
> 
> I didn't know this existed!

Neither did I! It's documented in https://developer.apple.com/documentation/xcode-release-notes/xcode-11-release-notes but not surfaced in the build settings UI.
Comment 7 Elliott Williams 2022-03-29 15:48:40 PDT
Created attachment 456071 [details]
Patch
Comment 8 Elliott Williams 2022-03-30 10:25:50 PDT
Created attachment 456141 [details]
Patch
Comment 9 Elliott Williams 2022-03-30 10:47:00 PDT
Comment on attachment 456141 [details]
Patch

I think I'm narrowing down the cause of EWS build failures. They are related to the hacky "(Legacy) Install Headers" build phase, which is extra tricky here because we have to invoke clang (via tapi) while running the header build rule.

By not setting SYMROOT as I'd done before in WebKit, WTF, and PAL, the inferior xcodebuild was replacing WebKitLegacy.framework with a symlink to /tmp/WebKitLegacy.dst/WebKitLegacy.framework, causing linker failures.

Now, we give the inferior xcodebuild its own SYMROOT directory, but create symlinks for all the existing build products from the superior's SYMROOT so that tapi can run successfully.

Apologies for the EWS noise. I look forward to deleting these scripts soon :)
Comment 10 Elliott Williams 2022-03-30 11:16:53 PDT
Created attachment 456153 [details]
Patch
Comment 11 Elliott Williams 2022-03-30 16:38:05 PDT
Created attachment 456185 [details]
Patch
Comment 12 Elliott Williams 2022-03-31 09:59:57 PDT
Comment on attachment 456185 [details]
Patch

ios-wk2 test failures <https://ews-build.webkit.org/#/builders/68/builds/11945> look unrelated. There were a few tests that crashed but no launch issues that could be caused by a build system change.

Alexey, I think this is ready to go!
Comment 13 Alexey Proskuryakov 2022-03-31 10:35:01 PDT
Comment on attachment 456185 [details]
Patch

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

> Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj:697
> +			filePatterns = "*/Source/WebCore/*.h";

As discussed in person, I'm confused about how this worked before. WebKitLegacy couldn't pull headers directly from Source/WebCore until semi-recently.

> Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj:706
> +				"$(HEADER_OUTPUT_DIR)/$(INPUT_FILE_NAME)",
> +				"$(DERIVED_FILE_DIR)/WebCore/$(INPUT_FILE_NAME)",

Not excited about creating two files with the same name, as always.
Comment 14 Elliott Williams 2022-03-31 11:06:04 PDT
Created attachment 456255 [details]
Fix typo, pre-approved
Comment 15 Elliott Williams 2022-03-31 11:07:08 PDT
Comment on attachment 456255 [details]
Fix typo, pre-approved

Recorded Alexey's r+, ready to land.
Comment 16 Elliott Williams 2022-03-31 11:20:27 PDT
(In reply to Alexey Proskuryakov from comment #13)
> Comment on attachment 456185 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=456185&action=review
> 
> > Source/WebKitLegacy/WebKitLegacy.xcodeproj/project.pbxproj:697
> > +			filePatterns = "*/Source/WebCore/*.h";
> 
> As discussed in person, I'm confused about how this worked before.
> WebKitLegacy couldn't pull headers directly from Source/WebCore until
> semi-recently.

Previously, the "Migrate Headers" makefile copied from WebCore's product headers, in WebCore.framework/PrivateHeaders. It used the locally-built WebCore in BUILT_PRODUCTS_DIR or SDKROOT, for engineering or production builds respectively. The logic to pick which location to get WebCore headers from was in migrate-headers.sh:

    # If we didn't build WebCore, use the production copy of the headers
    if [ ! -d "${WEBCORE_PRIVATE_HEADERS_DIR}" ]; then
        export WEBCORE_PRIVATE_HEADERS_DIR="${WEBCORE_PRIVATE_HEADERS_DIR_Production}"
    fi
    

Now, we pull migrated headers directly from other projects' source roots, because it's difficult to get Xcode to store file references to product headers, since their paths change depending on the platform we're building for. For reference, here's where we discussed doing the same thing in modern WebKit: https://bugs.webkit.org/show_bug.cgi?id=238213#c4
Comment 17 EWS 2022-03-31 14:30:05 PDT
Tools/Scripts/svn-apply failed to apply attachment 456255 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 18 Elliott Williams 2022-03-31 14:32:22 PDT
Created attachment 456282 [details]
[fast-cq] Rebase with trunk
Comment 19 EWS 2022-03-31 14:34:52 PDT
Tools/Scripts/svn-apply failed to apply attachment 456282 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 20 Ryan Haddad 2022-03-31 14:50:07 PDT
Comment on attachment 456282 [details]
[fast-cq] Rebase with trunk

Marking cq+ due to false positive related to infrastructure issue.
Comment 21 EWS 2022-03-31 14:58:11 PDT
Committed r292183 (249086@main): <https://commits.webkit.org/249086@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 456282 [details].
Comment 22 WebKit Commit Bot 2022-03-31 17:13:02 PDT
Re-opened since this is blocked by bug 238639
Comment 23 Ryan Haddad 2022-03-31 17:16:19 PDT
Reverted in https://commits.webkit.org/r292188 as this appears to have caused the following build failure: https://build.webkit.org/#/builders/29/builds/11637
Comment 24 Elliott Williams 2022-04-01 16:16:24 PDT
Created attachment 456415 [details]
Fix symlinks modifying BUILT_PRODUCTS_DIR
Comment 25 Elliott Williams 2022-04-01 16:19:20 PDT
Comment on attachment 456415 [details]
Fix symlinks modifying BUILT_PRODUCTS_DIR

This was quite the build bug. Here's my analysis:

As explained in the patch's changelog, the "(Legacy) Install Headers" script phase creates symlinks into BUILT_PRODUCTS_DIR for the inferior (child) xcodebuild:

    for p in "${BUILT_PRODUCTS_DIR}"/*; do
        ln -sf "${p}" "${INFERIOR_BUILT_PRODUCTS_DIR}/$(basename "${p}")"   # WRONG
    done
    
On a clean build, this works as intended. But if "${p}" already exists, and it points to a directory, `ln` enters the directory and creates the symlink inside it. This leads to situations where a framework bundle contains a symlink to itself:

    > ls -l WebKitBuild/Debug/WebKitLegacy.framework
    total 0
    lrwxr-xr-x  1 emw  admin   31 Apr  1 15:24 PrivateHeaders -> Versions/Current/PrivateHeaders
    lrwxr-xr-x  1 emw  admin   26 Apr  1 15:24 Resources -> Versions/Current/Resources
    drwxr-xr-x  4 emw  admin  128 Apr  1 15:24 Versions
    lrwxr-xr-x  1 emw  admin   29 Apr  1 15:24 WebKitLegacy -> Versions/Current/WebKitLegacy
    lrwxr-xr-x  1 emw  admin   72 Apr  1 15:33 WebKitLegacy.framework -> WebKitBuild/Debug/WebKitLegacy.framework  # WRONG
    lrwxr-xr-x  1 emw  admin   34 Apr  1 15:24 WebKitPluginAgent -> Versions/Current/WebKitPluginAgent
    lrwxr-xr-x  1 emw  admin   37 Apr  1 15:24 WebKitPluginHost.app -> Versions/Current/WebKitPluginHost.app

Most of the time, this is benign, because nothing tries to read the symlink. But on Mac, this symlink violates bundle structure, because the top-level bundle directory should only contain `Info.plist` and `Contents`. Bundles that are codesigned have their structure validated. In our case, `com.apple.WebKit.WebAuthn.xpc` is the unlucky bundle that signs first, failing with:

    /usr/bin/codesign --force --sign - --entitlements WebKitBuild/WebKit.build/Release/WebAuthn.build/com.apple.WebKit.WebAuthn.xpc.entitlements --timestamp=none 
    WebKitBuild/Release/com.apple.WebKit.WebAuthn.xpc: unsealed contents present in the bundle root
    
WebAuthn is part of WebKit, which builds after WebKitLegacy. Because of this, it takes at least _two builds_ to create the build-breaking symlink.

The fix is to pass a flag to tell `ln` to overwrite an existing symlink:

    for p in "${BUILT_PRODUCTS_DIR}"/*; do
        ln -sfhv "${p}" "${INFERIOR_BUILT_PRODUCTS_DIR}/$(basename "${p}")"  # RIGHT
    done

-h prevents `ln` from traversing the symlink when it's replacing it. -v makes it print the links it's creating, so that mistakes like this will be evident in build logs.
Comment 26 Alexey Proskuryakov 2022-04-01 16:29:08 PDT
Comment on attachment 456415 [details]
Fix symlinks modifying BUILT_PRODUCTS_DIR

We usually just do "ln -sfh" exactly because of this; I should have noticed the lack of the usual flag.
Comment 27 EWS 2022-04-04 10:00:16 PDT
Committed r292292 (249190@main): <https://commits.webkit.org/249190@main>

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