Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build script] Remove double-quotes around variables to fix incorrect array expansion #8413

Merged
merged 3 commits into from
Feb 29, 2024
Merged

[Build script] Remove double-quotes around variables to fix incorrect array expansion #8413

merged 3 commits into from
Feb 29, 2024

Conversation

hisaac
Copy link
Contributor

@hisaac hisaac commented Nov 3, 2023

In order to use Realm within our app, we need to rebuild it with some extra settings enabled. While experimenting, I noticed what appears to be a bug in Realm's build script:

When adding more than one argument to the REALM_EXTRA_BUILD_ARGUMENTS variable, the arguments get passed to xcodebuild as a single string, rather than multiple space-separated strings.

An example:

# Running the following command:
REALM_EXTRA_BUILD_ARGUMENTS='REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEBUG_INFORMATION_FORMAT=dwarf-with-dsym' ./build.sh ios-swift

# Results in this `xcodebuild` invocation:
/Applications/Xcode-15.0.1.app/Contents/Developer/usr/bin/xcodebuild -IDECustomDerivedDataLocation=build/DerivedData -destination generic/platform=iOS -scheme Realm -configuration Release build REALM_HIDE_SYMBOLS=YES "REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEBUG_INFORMATION_FORMAT=dwarf-with-dsym"

Note the last two arguments in the xcodebuild invocation are surrounded by double-quotes, so xcodebuild interprets them as a single argument.

I've run into this exact issue before when writing my own build scripts in Bash. It has to do with how Bash does array expansion. Luckily the fix is pretty simple, just to remove double-quotes from a couple places.

Here's a diff of the xcodebuild output before and after the fix is applied:

Building with command: xcodebuild -IDECustomDerivedDataLocation=build/DerivedData -destination generic/platform=iOS -scheme Realm -configuration Release build REALM_HIDE_SYMBOLS=YES REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEBUG_INFORMATION_FORMAT=dwarf-with-dsym
Command line invocation:
-    /Applications/Xcode-15.0.1.app/Contents/Developer/usr/bin/xcodebuild -IDECustomDerivedDataLocation=build/DerivedData -destination generic/platform=iOS -scheme Realm -configuration Release build REALM_HIDE_SYMBOLS=YES "REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEBUG_INFORMATION_FORMAT=dwarf-with-dsym"
+    /Applications/Xcode-15.0.1.app/Contents/Developer/usr/bin/xcodebuild -IDECustomDerivedDataLocation=build/DerivedData -destination generic/platform=iOS -scheme Realm -configuration Release build REALM_HIDE_SYMBOLS=YES REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEBUG_INFORMATION_FORMAT=dwarf-with-dsym

User defaults from command line:
    IDECustomDerivedDataLocation = build/DerivedData
    IDEPackageSupportUseBuiltinSCM = YES

Build settings from command line:
-    REALM_BUILD_LIBRARY_FOR_DISTRIBUTION = YES DEBUG_INFORMATION_FORMAT=dwarf-with-dsym
+    DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
+    REALM_BUILD_LIBRARY_FOR_DISTRIBUTION = YES
    REALM_HIDE_SYMBOLS = YES

@cla-bot cla-bot bot added the cla: yes label Feb 24, 2024
@hisaac
Copy link
Contributor Author

hisaac commented Feb 24, 2024

Hi @dianaafanador3. Any chance this could get a review? Just adding you here because I see you approved a recent PR. Let me know if there's someone else I should mention instead. Thanks 👋

@fealebenpae fealebenpae self-requested a review February 28, 2024 17:50
@fealebenpae
Copy link
Member

Hey @hisaac,

I don't know why the original array expansion is surrounded by quotes like that, but I tested a few different invocations and it seems that the problem you spotted appears every time and that your patch makes it go away.

@fealebenpae fealebenpae merged commit a561458 into realm:master Feb 29, 2024
2 checks passed
@hisaac hisaac deleted the hisaac/fix-xcodebuild-command-array-expansion branch February 29, 2024 16:15
@hisaac
Copy link
Contributor Author

hisaac commented Feb 29, 2024

Awesome, thanks for testing it out to make sure @fealebenpae. 🙏

nirinchev added a commit that referenced this pull request Mar 7, 2024
* master:
  🔄 Synced file(s) with realm/ci-actions (#8504)
  🔄 Synced file(s) with realm/ci-actions (#8503)
  RPM-568: Add a workflow that verifies PR title (#8500)
  RCOCOA-2238: Allow defining models with only computed properties (#8484)
  [Build script] Remove double-quotes around variables to fix incorrect array expansion (#8413)
  Enable `Prepare-release` to be run manually or in a release branch for a backported fix
  Add empty CHANGELOG template after release
  Clean up files after migration to XCode Cloud
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants