Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
buildSyncAutolinkingScript,
flavorForBuildConfiguration,
frameworkConditionalSettings,
generateReactNativeXcconfig,
generateXcscheme,
readScriptPhasesManifest,
} = require('../generate-spm-xcodeproj');
Expand Down Expand Up @@ -358,6 +359,99 @@ describe('configuration-driven framework settings', () => {
});
});

describe('generateReactNativeXcconfig', () => {
const DEVICE_ONLY = {...FRAMEWORK, slices: [FRAMEWORK.slices[0]]};

it('writes every setting the app target needs, extending inherited lists', () => {
expect(
generateReactNativeXcconfig(
['Debug', 'Release'],
'../node_modules/react-native',
[DEVICE_ONLY],
),
).toBe(
`// Generated by React Native on every \`spm add\` and \`spm update\`.
// Do not edit: changes are overwritten.

CLANG_CXX_LANGUAGE_STANDARD = c++20
REACT_NATIVE_PATH = $(SRCROOT)/../node_modules/react-native

HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/build/generated/autolinking/headers"
OTHER_LDFLAGS = $(inherited) -ObjC "$(RN_SPM_REACT_BINARY)"
FRAMEWORK_SEARCH_PATHS = $(inherited) "$(RN_SPM_REACT_SEARCH_PATH)"
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/Frameworks

RN_SPM_FLAVOR = release
RN_SPM_FLAVOR[config=Debug] = debug
SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug] = $(inherited) DEBUG
RN_SPM_FLAVOR[config=Release] = release

RN_SPM_REACT_FRAMEWORK[sdk=iphoneos*] = $(SRCROOT)/build/xcframeworks/$(RN_SPM_FLAVOR)/React.xcframework/ios-arm64/React.framework
RN_SPM_REACT_BINARY[sdk=iphoneos*] = $(SRCROOT)/build/xcframeworks/$(RN_SPM_FLAVOR)/React.xcframework/ios-arm64/React.framework/React
RN_SPM_REACT_SEARCH_PATH[sdk=iphoneos*] = $(SRCROOT)/build/xcframeworks/$(RN_SPM_FLAVOR)/React.xcframework/ios-arm64
`,
);
});

it('anchors REACT_NATIVE_PATH on SRCROOT itself when react-native sits there', () => {
expect(generateReactNativeXcconfig(['Debug'], '', [FRAMEWORK])).toContain(
'\nREACT_NATIVE_PATH = $(SRCROOT)\n',
);
});

it("conditions the flavor on the project's own configuration names", () => {
const xcconfig = generateReactNativeXcconfig(
['Development', 'Staging'],
'../node_modules/react-native',
[FRAMEWORK],
);
expect(xcconfig).toContain('RN_SPM_FLAVOR[config=Development] = debug\n');
expect(xcconfig).toContain(
'SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Development] = $(inherited) DEBUG\n',
);
expect(xcconfig).toContain('RN_SPM_FLAVOR[config=Staging] = release\n');
expect(xcconfig).not.toContain(
'SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Staging]',
);
expect(xcconfig).not.toMatch(/\[config=(Debug|Release)\]/);
});

// A configuration duplicated in Xcode keeps the base reference but has no
// line of its own until the next sync, and an unset flavor would resolve
// every framework path to nothing.
it('falls back to the release flavor for a configuration it does not list', () => {
const lines = generateReactNativeXcconfig(
['Debug', 'Release'],
'../node_modules/react-native',
[FRAMEWORK],
).split('\n');
const fallback = lines.indexOf('RN_SPM_FLAVOR = release');
expect(fallback).toBeGreaterThan(-1);
expect(fallback).toBeLessThan(
lines.findIndex(line => line.startsWith('RN_SPM_FLAVOR[config=')),
);
expect(
lines.some(line =>
line.startsWith('SWIFT_ACTIVE_COMPILATION_CONDITIONS ='),
),
).toBe(false);
});

it('writes no plist quoting around conditional keys or path values', () => {
const xcconfig = generateReactNativeXcconfig(
['Debug'],
'../node_modules/react-native',
[FRAMEWORK],
);
expect(xcconfig).toContain(
'\nRN_SPM_REACT_BINARY[sdk=iphonesimulator*] = $(SRCROOT)/',
);
expect(xcconfig).toContain('\nRN_SPM_REACT_SEARCH_PATH[sdk=macosx*] = ');
expect(xcconfig).not.toMatch(/^"/m);
expect(xcconfig).not.toContain('= "$(SRCROOT)/build/xcframeworks');
});
});

describe('embed framework phase script', () => {
const script = buildEmbedFrameworksScript([FRAMEWORK]);

Expand Down
Loading
Loading