-
Notifications
You must be signed in to change notification settings - Fork 905
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
fix(macCatalyst): construct correct path for executable #2510
Open
mikehardy
wants to merge
1
commit into
main
Choose a base branch
from
maccatalyst-cli-14
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/cli-platform-apple/src/commands/runCommand/__tests__/getBuildPath.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import {getTempDirectory} from '../../../../../../jest/helpers'; | ||
import {BuildSettings} from '../getBuildSettings'; | ||
import {getBuildPath} from '../getBuildPath'; | ||
|
||
const targetBuildDirName = 'foo'; | ||
const targetBuildDirNameWithMaccatalyst = `${targetBuildDirName}-maccatalyst`; | ||
const executableFolderPath = path.join('foo.app', 'Contents', 'MacOS', 'foo'); | ||
|
||
test('correctly determines macCatalyst build artifact path new style', async () => { | ||
// setup: | ||
const tmpBuildPath = getTempDirectory('maccatalyst-test-dir'); | ||
fs.mkdirSync(path.join(tmpBuildPath, targetBuildDirNameWithMaccatalyst), { | ||
recursive: true, | ||
}); | ||
|
||
// - create buildSettings object that represents this to CLI | ||
const buildSettings: BuildSettings = { | ||
TARGET_BUILD_DIR: path.join( | ||
tmpBuildPath, | ||
targetBuildDirNameWithMaccatalyst, | ||
), | ||
EXECUTABLE_FOLDER_PATH: executableFolderPath, | ||
FULL_PRODUCT_NAME: 'unused-in-this-test', | ||
INFOPLIST_PATH: 'unused-in-this-test', | ||
}; | ||
|
||
// test: | ||
// - send our buildSettings in and see what build path comes out | ||
const buildPath = await getBuildPath(buildSettings, 'ios', true); | ||
|
||
// assert: | ||
expect(buildPath).toBe( | ||
path.join( | ||
tmpBuildPath, | ||
targetBuildDirNameWithMaccatalyst, | ||
executableFolderPath, | ||
), | ||
); | ||
}); | ||
|
||
test('correctly determines macCatalyst build artifact path old style', async () => { | ||
// setup: | ||
const tmpBuildPath = getTempDirectory('maccatalyst-test-dir'); | ||
fs.mkdirSync(path.join(tmpBuildPath, targetBuildDirNameWithMaccatalyst), { | ||
recursive: true, | ||
}); | ||
|
||
// - create buildSettings object that represents this to CLI | ||
// FIXME get the build settings as side effect from project definition, | ||
// because it's the translation of project settings to path that fails | ||
const buildSettings: BuildSettings = { | ||
TARGET_BUILD_DIR: path.join(tmpBuildPath, targetBuildDirName), | ||
EXECUTABLE_FOLDER_PATH: executableFolderPath, | ||
FULL_PRODUCT_NAME: 'unused-in-this-test', | ||
INFOPLIST_PATH: 'unused-in-this-test', | ||
}; | ||
|
||
// test: | ||
// - send our buildSettings in and see what build path comes out | ||
const buildPath = await getBuildPath(buildSettings, 'ios', true); | ||
|
||
// assert: | ||
expect(buildPath).toBe( | ||
path.join( | ||
tmpBuildPath, | ||
targetBuildDirNameWithMaccatalyst, | ||
executableFolderPath, | ||
), | ||
); | ||
}); | ||
|
||
test('correctly determines iOS build artifact path', async () => { | ||
// setup: | ||
const tmpBuildPath = getTempDirectory('ios-test-dir'); | ||
fs.mkdirSync(path.join(tmpBuildPath, targetBuildDirName), { | ||
recursive: true, | ||
}); | ||
|
||
// - create buildSettings object that represents this to CLI | ||
const buildSettings: BuildSettings = { | ||
TARGET_BUILD_DIR: path.join(tmpBuildPath, targetBuildDirName), | ||
EXECUTABLE_FOLDER_PATH: executableFolderPath, | ||
FULL_PRODUCT_NAME: 'unused-in-this-test', | ||
INFOPLIST_PATH: 'unused-in-this-test', | ||
}; | ||
|
||
// test: | ||
// - send our buildSettings in and see what build path comes out | ||
const buildPath = await getBuildPath(buildSettings); | ||
|
||
// assert: | ||
expect(buildPath).toBe( | ||
path.join(tmpBuildPath, targetBuildDirName, executableFolderPath), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be
if-else if
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it certainly could be, but...it seemed to me the three cases were all mutually exclusive so simple
if
overrides/clobbers were semantically identical ?case 1 - we're the default platform == ios && isCatalyst == false: default case join targetBuildDir + executableFolderPath
case 2 - we're the rare platform == ios && isCatalyst == true: clobber with result of maybe adding
-maccatalyst
to targetBuildDir -- note that catalyst is an ios platform subset, it will not go in to the platform == macos conditional as truecase 3 - we're the platform == macos: clobber join of targetBuildDir + fullProductName
Each of the three cases is unambiguously identifiable and unique so I thought a simple set of ifs + clobbers worked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a tiny change in response to this, for future developers so less explanation + thought is required I hope
1- I altered the isCatalyst conditional to explicitly contain a
platform === 'ios'
clause as that is the assumption, so now it is more clear that the catalyst block will not ever collide with the macos block2- I updated the comments to reflect the same, and the idea that the default case and the two override blocks are exclusive of one another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they were equivalent. But with
All three conditions are always evaluated. With
cond2 is evaluated if and only if cond1 is false. cond3 is evaluated if and only if both cond1 and cond2 are false.
So, the if-elseif approach is slightly more efficient, and makes it clear that the conditions are mutually exclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi lots of discussion and we are in agreement with each other :-) - the question is that with the mixed signal I am hearing of "if/elseif/elseif is slightly better" vs "but I have approved the if/if/if version" - do you want me to convert it and re-push or not?
I don't want to swirl endlessly on this - it's a relatively small fix after all, but I'll do what you like (because, it's an easy conversion from if/if/if/ to if/elseif/elsif too).
So just let me know but I won't change+repush unless you ask, so we don't have another approval cycle unless desired
Cheers man