Skip to content

Commit fbbc26b

Browse files
fix: make sure new ios project has properly configured iOS options (#521)
* fix: make sure new ios project has properly configured iOS options * calculate project name and fingerprint after pod install * changeset * remove todo; update vscode extensions --------- Co-authored-by: Michał Pierzchała <[email protected]>
1 parent 03dc80e commit fbbc26b

File tree

7 files changed

+73
-23
lines changed

7 files changed

+73
-23
lines changed

.changeset/happy-parrots-return.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rock-js/platform-apple-helpers': patch
3+
'@rock-js/tools': patch
4+
---
5+
6+
fix: make sure new ios project has properly configured iOS options

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"recommendations": ["nrwl.angular-console", "esbenp.prettier-vscode"]
2+
"recommendations": ["esbenp.prettier-vscode"]
33
}

packages/platform-apple-helpers/src/lib/commands/build/createBuild.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ export const createBuild = async ({
5252
? 'simulator'
5353
: 'device'
5454
: 'simulator';
55-
const artifactName = await formatArtifactName({
56-
platform: 'ios',
57-
traits: [deviceOrSimulator, args.configuration ?? 'Debug'],
58-
root: projectRoot,
59-
fingerprintOptions,
60-
});
55+
56+
async function getArtifactName({ silent }: { silent?: boolean } = {}) {
57+
return await formatArtifactName({
58+
platform: 'ios',
59+
traits: [deviceOrSimulator, args.configuration ?? 'Debug'],
60+
root: projectRoot,
61+
fingerprintOptions,
62+
silent,
63+
});
64+
}
65+
66+
let artifactName = await getArtifactName();
67+
6168
const binaryPath = await getBinaryPath({
6269
artifactName,
6370
localFlag: args.local,
@@ -82,7 +89,7 @@ export const createBuild = async ({
8289
}
8390

8491
try {
85-
const { appPath, ...buildAppResult } = await buildApp({
92+
const { appPath, didInstallPods, ...buildAppResult } = await buildApp({
8693
projectRoot,
8794
projectConfig,
8895
platformName,
@@ -95,6 +102,12 @@ export const createBuild = async ({
95102
xcodeProject = buildAppResult.xcodeProject;
96103
sourceDir = buildAppResult.sourceDir;
97104
scheme = buildAppResult.scheme;
105+
106+
// After installing pods the fingerprint likely changes.
107+
// We update the artifact name to reflect the new fingerprint and store proper entry in the local cache.
108+
if (didInstallPods) {
109+
artifactName = await getArtifactName({ silent: true });
110+
}
98111
saveLocalBuildCache(artifactName, appPath);
99112
} catch (error) {
100113
const message = `Failed to create ${args.archive ? 'archive' : 'build'}`;

packages/platform-apple-helpers/src/lib/commands/run/createRun.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ export const createRun = async ({
5252
? 'simulator'
5353
: 'device'
5454
: 'simulator';
55-
const artifactName = await formatArtifactName({
56-
platform: 'ios',
57-
traits: [deviceOrSimulator, args.configuration ?? 'Debug'],
58-
root: projectRoot,
59-
fingerprintOptions,
60-
});
55+
56+
async function getArtifactName({ silent }: { silent?: boolean } = {}) {
57+
return await formatArtifactName({
58+
platform: 'ios',
59+
traits: [deviceOrSimulator, args.configuration ?? 'Debug'],
60+
root: projectRoot,
61+
fingerprintOptions,
62+
silent,
63+
});
64+
}
65+
66+
let artifactName = await getArtifactName();
67+
6168
const binaryPath = await getBinaryPath({
6269
artifactName,
6370
binaryPathFlag: args.binaryPath,
@@ -132,7 +139,7 @@ ${devices
132139
}
133140
cacheRecentDevice(device, platformName);
134141
if (device.type === 'simulator') {
135-
const [, { appPath, infoPlistPath }] = await Promise.all([
142+
const [, { appPath, infoPlistPath, didInstallPods }] = await Promise.all([
136143
launchSimulator(device),
137144
buildApp({
138145
args,
@@ -144,6 +151,11 @@ ${devices
144151
binaryPath,
145152
}),
146153
]);
154+
// After installing pods the fingerprint likely changes.
155+
// We update the artifact name to reflect the new fingerprint and store proper entry in the local cache.
156+
if (didInstallPods) {
157+
artifactName = await getArtifactName({ silent: true });
158+
}
147159
saveLocalBuildCache(artifactName, appPath);
148160
await runOnSimulator(device, appPath, infoPlistPath);
149161
} else if (device.type === 'device') {
@@ -194,7 +206,7 @@ ${devices
194206
}
195207
}
196208
for (const bootedDevice of bootedDevices) {
197-
const [, { appPath, infoPlistPath, bundleIdentifier }] =
209+
const [, { appPath, infoPlistPath, bundleIdentifier, didInstallPods }] =
198210
await Promise.all([
199211
launchSimulator(bootedDevice),
200212
buildApp({
@@ -207,6 +219,11 @@ ${devices
207219
binaryPath,
208220
}),
209221
]);
222+
// After installing pods the fingerprint likely changes.
223+
// We update the artifact name to reflect the new fingerprint and store proper entry in the local cache.
224+
if (didInstallPods) {
225+
artifactName = await getArtifactName({ silent: true });
226+
}
210227
saveLocalBuildCache(artifactName, appPath);
211228
if (bootedDevice.type === 'simulator') {
212229
await runOnSimulator(bootedDevice, appPath, infoPlistPath);

packages/platform-apple-helpers/src/lib/utils/buildApp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ export async function buildApp({
4949
scheme: args.scheme,
5050
xcodeProject: projectConfig.xcodeProject,
5151
sourceDir: projectConfig.sourceDir,
52+
didInstallPods: false,
5253
};
5354
}
5455

56+
let didInstallPods = false;
5557
let { xcodeProject, sourceDir } = projectConfig;
5658

5759
if (args.installPods) {
@@ -75,6 +77,7 @@ export async function buildApp({
7577
xcodeProject = newProjectConfig.xcodeProject;
7678
sourceDir = newProjectConfig.sourceDir;
7779
}
80+
didInstallPods = true;
7881
}
7982

8083
const info = await getInfo(xcodeProject, sourceDir);
@@ -123,6 +126,7 @@ export async function buildApp({
123126
xcodeProject,
124127
sourceDir,
125128
bundleIdentifier: buildSettings.bundleIdentifier,
129+
didInstallPods,
126130
};
127131
}
128132

packages/tools/src/lib/build-cache/common.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { color } from '../color.js';
44
import type { FingerprintSources } from '../fingerprint/index.js';
55
import { nativeFingerprint } from '../fingerprint/index.js';
66
import { isInteractive } from '../isInteractive.js';
7+
import logger from '../logger.js';
78
import { getCacheRootPath } from '../project.js';
89
import { spinner } from '../prompts.js';
910

@@ -104,12 +105,14 @@ export async function formatArtifactName({
104105
root,
105106
fingerprintOptions,
106107
raw,
108+
silent,
107109
}: {
108110
platform?: 'ios' | 'android';
109111
traits?: string[];
110112
root: string;
111113
fingerprintOptions: FingerprintSources;
112114
raw?: boolean;
115+
silent?: boolean;
113116
}): Promise<string> {
114117
if (!platform || !traits) {
115118
return '';
@@ -123,7 +126,7 @@ export async function formatArtifactName({
123126
return `rock-${platform}-${traits.join('-')}-${hash}`;
124127
}
125128

126-
const loader = spinner();
129+
const loader = spinner({ silent });
127130
loader.start('Calculating project fingerprint');
128131
const { hash } = await nativeFingerprint(root, {
129132
...fingerprintOptions,
@@ -132,6 +135,9 @@ export async function formatArtifactName({
132135
loader.stop(
133136
`Calculated project fingerprint: ${color.bold(color.magenta(hash))}`,
134137
);
138+
if (silent) {
139+
logger.debug(`Calculated project fingerprint: ${hash}`);
140+
}
135141
return `rock-${platform}-${traits.join('-')}-${hash}`;
136142
}
137143

packages/tools/src/lib/fingerprint/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const DEFAULT_IGNORE_PATHS = [
2222
'ios/DerivedData',
2323
'ios/Pods',
2424
'ios/tmp.xcconfig', // added by react-native-config
25+
'ios/**/*.xcworkspace',
2526
'node_modules',
2627
'android/local.properties',
2728
'android/.idea',
@@ -48,15 +49,15 @@ export type FingerprintResult = {
4849
* Calculates the fingerprint of the native parts project of the project.
4950
*/
5051
export async function nativeFingerprint(
51-
path: string,
52+
projectRoot: string,
5253
options: FingerprintOptions,
5354
): Promise<FingerprintResult> {
5455
const platform = options.platform;
5556
// Use stdout to avoid deprecation warnings
5657
const { stdout: autolinkingConfigString } = await spawn(
5758
'rock',
5859
['config', '-p', options.platform],
59-
{ cwd: path, stdio: 'pipe', preferLocal: true },
60+
{ cwd: projectRoot, stdio: 'pipe', preferLocal: true },
6061
);
6162

6263
const autolinkingSources = parseAutolinkingSources({
@@ -65,14 +66,17 @@ export async function nativeFingerprint(
6566
contentsId: 'rncoreAutolinkingConfig',
6667
});
6768

68-
const fingerprint = await createFingerprintAsync(path, {
69+
const fingerprint = await createFingerprintAsync(projectRoot, {
6970
platforms: [platform],
70-
dirExcludes: DEFAULT_IGNORE_PATHS,
7171
extraSources: [
7272
...autolinkingSources,
73-
...processExtraSources(options.extraSources, path, options.ignorePaths),
73+
...processExtraSources(
74+
options.extraSources,
75+
projectRoot,
76+
options.ignorePaths,
77+
),
7478
],
75-
ignorePaths: options.ignorePaths,
79+
ignorePaths: [...DEFAULT_IGNORE_PATHS, ...(options.ignorePaths ?? [])],
7680
});
7781

7882
// Filter out un-relevant sources as these caused hash mismatch between local and remote builds

0 commit comments

Comments
 (0)