Skip to content

Commit

Permalink
fix(Codegen): case where no platform or deployment_target is spec…
Browse files Browse the repository at this point in the history
…ified (#42867)

Summary:
This PR fixes a specific case pointed out by dmytrorykun, where there might be no platform or `deployment_target` specified at all and in that case we assume that this library supports every platform (same as Cocoapods).

## Changelog:

[IOS] [FIXED] - Don't add compiler conditionals when no platforms are specified

Pull Request resolved: #42867

Test Plan:
Test running codegen when library doesn't specify a `platform`:

```
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
  s.name            = 'OSSLibraryExample'
  s.version         = package['version']
  s.summary         = package['description']
  s.description     = package['description']
  s.homepage        = package['homepage']
  s.license         = package['license']
  s.author          = 'Meta Platforms, Inc. and its affiliates'
  s.source          = { :git => package['repository'], :tag => '#{s.version}' }

  s.source_files = 'ios/**/*.{h,m,mm,cpp}'

  install_modules_dependencies(s)
end
```

Check generated `RCTThirdPartyFabricComponentsProvider`

Reviewed By: cortinico

Differential Revision: D53405625

Pulled By: dmytrorykun

fbshipit-source-id: 0f6917c56b84f0fa29807f516acdbd8d15aa5b46
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Feb 5, 2024
1 parent d66d651 commit 1ce7bfd
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ function generateSupportedApplePlatformsMacro(
return fileTemplate;
}

// According to Podspec Syntax Reference, when `platform` or `deployment_target` is not specified, it defaults to all platforms.
// https://guides.cocoapods.org/syntax/podspec.html#platform
const everyPlatformIsUnsupported = Object.keys(supportedPlatformsMap).every(
platform => supportedPlatformsMap[platform] === false,
);

if (everyPlatformIsUnsupported) {
return fileTemplate;
}

const compilerMacroString = Object.keys(supportedPlatformsMap)
.reduce((acc: string[], platform) => {
if (!supportedPlatformsMap[platform]) {
Expand Down

0 comments on commit 1ce7bfd

Please sign in to comment.