Repository navigation
Commit b8df948
Encode line breaks in SwiftPM scheme pre-action scriptText (#58826)
Summary:
The SwiftPM setup adds a "Sync SPM Autolinking" pre-action to the app's Xcode scheme. The pre-action never ran its sync step.
The script is many lines long. `escapeXmlAttribute` wrote it into the `scriptText` XML attribute with raw line breaks. An XML parser replaces each raw line break in an attribute value with a space (XML 1.0 §3.3.3). So Xcode read the script as one line. The second line of the script is a `#` comment, so everything after `set -euo pipefail` became part of that comment.
This PR makes two changes in `packages/react-native/scripts/spm/generate-spm-xcodeproj.js`:
- `escapeXmlAttribute` now also encodes `\r`, `\n` and `\t` as `&https://github.com/react/react-native/issues/13;`, `&https://github.com/react/react-native/issues/10;` and `&https://github.com/react/react-native/issues/9;`. Xcode itself writes the script this way.
- `deinit` deletes a scheme that RN created only when the scheme is still unchanged. This check now ignores the value of the script. Without this change, a scheme that an older version wrote with raw line breaks would no longer match, and `deinit` would leave it on disk. The XML decoder had no callers left after this change, so this PR removes it.
Existing projects get the fixed script when the user runs `npx react-native spm update` once. The build-time `sync` does not rewrite the scheme.
## Changelog:
[IOS] [FIXED] - SwiftPM: keep line breaks in the scheme pre-action script so that the "Sync SPM Autolinking" pre-action runs. Run `npx react-native spm update` once to rewrite an existing scheme.
Pull Request resolved: #58826
Test Plan:
New tests:
- `generate-spm-xcodeproj-test.js`: parses the generated scheme with `xmldom/xmldom` and checks that the script keeps its line breaks and tabs. A second test checks that a refresh of an older scheme with raw line breaks writes `&https://github.com/react/react-native/issues/10;`.
- `remove-spm-injection-test.js`: checks that `deinit` still deletes an RN-created scheme whose script has raw line breaks.
```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__/generate-spm-xcodeproj-test.js packages/react-native/scripts/spm/__tests__/remove-spm-injection-test.js
```
- Before the fix: 2 failed, 124 passed (the two `generate-spm-xcodeproj` tests).
- With only the encoding change: the new `deinit` test and 4 existing `deinit` tests failed.
- With both changes: 2 suites passed, 126 tests passed.
ESLint and Prettier pass on the changed files. `flow check-contents` reports no errors for `generate-spm-xcodeproj.js`.
I did not build an app in Xcode for this PR. An Expo app had the problem: when the line breaks in its scheme were changed to `&https://github.com/react/react-native/issues/10;` by hand, the pre-action ran.
Reviewed By: christophpurrer
Differential Revision: D123382914
Pulled By: cipolleschi
fbshipit-source-id: 0c51cb7c6fe7a66567602d813a13381f6bf3704f1 parent 99d327c commit b8df948
3 files changed
Lines changed: 65 additions & 24 deletions
File tree
- packages/react-native/scripts/spm
- __tests__
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
140 | 175 | | |
141 | 176 | | |
142 | 177 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
502 | 517 | | |
503 | 518 | | |
504 | 519 | | |
| |||
Lines changed: 15 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
862 | 862 | | |
863 | 863 | | |
864 | 864 | | |
865 | | - | |
866 | | - | |
867 | | - | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
868 | 870 | | |
869 | 871 | | |
870 | 872 | | |
871 | 873 | | |
872 | 874 | | |
873 | 875 | | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | | - | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
887 | 880 | | |
888 | 881 | | |
889 | 882 | | |
| |||
2525 | 2518 | | |
2526 | 2519 | | |
2527 | 2520 | | |
2528 | | - | |
2529 | | - | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
2530 | 2524 | | |
2531 | 2525 | | |
2532 | 2526 | | |
| |||
2540 | 2534 | | |
2541 | 2535 | | |
2542 | 2536 | | |
2543 | | - | |
2544 | | - | |
2545 | | - | |
| 2537 | + | |
2546 | 2538 | | |
2547 | 2539 | | |
2548 | 2540 | | |
| |||
2564 | 2556 | | |
2565 | 2557 | | |
2566 | 2558 | | |
2567 | | - | |
2568 | 2559 | | |
2569 | | - | |
2570 | | - | |
| 2560 | + | |
| 2561 | + | |
2571 | 2562 | | |
2572 | 2563 | | |
2573 | 2564 | | |
| |||
0 commit comments