Skip to content

fix: find correct apk name when --release passed #3419

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

Merged
merged 4 commits into from
Mar 8, 2018

Conversation

Plamen5kov
Copy link
Contributor

problem
The CLI can't find .apk file to install on passed --release option. Read more in this issue

solution
respect --release option when generating apk find path

@Plamen5kov Plamen5kov self-assigned this Mar 5, 2018
@Plamen5kov Plamen5kov added this to the 4.0.0 milestone Mar 5, 2018
Copy link
Contributor

@rosen-vladimirov rosen-vladimirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using $options in service will make it unusable when CLI is used as a library. In this case, this will break local release builds in Sidekick, as the $options is not populated when CLI is not used on the command line.
Instead of using $options, the getDeviceBuildOutputPath should accept the build configuration. This requires changing the deviceBuildOutputPath to become a method and to be recalculated based on the passed options. The only place where deviceBuildOutputPath is used is here - you can directly pass the buildConfig object to the method.

@Plamen5kov
Copy link
Contributor Author

@rosen-vladimirov thank's for explaining. Will fix it shortly.

@@ -431,15 +431,15 @@ export class PlatformService extends EventEmitter implements IPlatformService {
this.$fs.writeJson(buildInfoFile, buildInfo);
}

public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean> {
public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: boolean, outputPath?: string): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release param is not used in method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, thank you

const platform = device.deviceInfo.platform;
if (!(await device.applicationManager.isApplicationInstalled(projectData.projectId))) {
return true;
}

const platformData = this.$platformsData.getPlatformData(platform, projectData);
const deviceBuildInfo: IBuildInfo = await this.getDeviceBuildInfo(device, projectData);
const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator }, outputPath);
const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator, release: false }, outputPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be release: release

@@ -140,6 +140,7 @@ interface IPlatformProjectServiceBase {

interface IBuildForDevice {
buildForDevice: boolean;
release: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends IRelease

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of IBuildForDevice interface is to be used whenever buildForDevice option is required.
Instead of using the IBuildForDevice interface, I suggest creating a new one that extends both IBuildForDevice and IRelease. The other option is to rename the current one, as the current properties are not required only for IBuildForDevice implementation.

@@ -76,7 +76,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
* @param {string} @optional outputPath Directory containing build information and artifacts.
* @returns {Promise<boolean>} true indicates that the application should be installed.
*/
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean>;
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: boolean, outputPath?: string): Promise<boolean>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bad practice to use boolean parameters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a bad practice to use boolean parameters? Please elaborate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing boolean as an argument makes the call to the method unreadable.
For the current case, when you call the method, you'll write:

await this.$platformService.shouldInstall(deviceInstance, projectData, false);

You have no idea what does this false do. When you try to read the flow of the code, you cannot tell why the value false is passed. In such cases it is recommended to pass object with boolean property, for example:

shouldInstall(device: Mobile.IDevice, projectData: IProjectData, buildOptions: IRelease, outputPath?: string): Promise<boolean>;

and the call will be:

await this.$platformService.shouldInstall(deviceInstance, projectData, { release: false });

This way there's no need to read the implementation of the method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rosen-vladimirov thanks, I can see now why using a boolean parameter could be bad.

@@ -76,7 +76,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
* @param {string} @optional outputPath Directory containing build information and artifacts.
* @returns {Promise<boolean>} true indicates that the application should be installed.
*/
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean>;
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: boolean, outputPath?: string): Promise<boolean>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing boolean as an argument makes the call to the method unreadable.
For the current case, when you call the method, you'll write:

await this.$platformService.shouldInstall(deviceInstance, projectData, false);

You have no idea what does this false do. When you try to read the flow of the code, you cannot tell why the value false is passed. In such cases it is recommended to pass object with boolean property, for example:

shouldInstall(device: Mobile.IDevice, projectData: IProjectData, buildOptions: IRelease, outputPath?: string): Promise<boolean>;

and the call will be:

await this.$platformService.shouldInstall(deviceInstance, projectData, { release: false });

This way there's no need to read the implementation of the method.

@@ -255,7 +255,7 @@ interface IPlatformData {
projectRoot: string;
normalizedPlatformName: string;
appDestinationDirectoryPath: string;
deviceBuildOutputPath: string;
deviceBuildOutputPath(options: IRelease): string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should rename this property to getDeviceBuildOutputPath as it is a better name for method.

@@ -140,6 +140,7 @@ interface IPlatformProjectServiceBase {

interface IBuildForDevice {
buildForDevice: boolean;
release: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of IBuildForDevice interface is to be used whenever buildForDevice option is required.
Instead of using the IBuildForDevice interface, I suggest creating a new one that extends both IBuildForDevice and IRelease. The other option is to rename the current one, as the current properties are not required only for IBuildForDevice implementation.

@@ -431,15 +431,15 @@ export class PlatformService extends EventEmitter implements IPlatformService {
this.$fs.writeJson(buildInfoFile, buildInfo);
}

public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean> {
public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, isRelease: IRelease, outputPath?: string): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to reuse IBuildConfig interface as we pass here buildConfig https://github.com/NativeScript/nativescript-cli/pull/3419/files#diff-513fe963f5d821a1cdb167ea91d70f1cR335

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will changing the interface from IRelease to IBuildConfig achieve?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed and agreed to use IRelease interface, only isRelease name sounds like a boolean variable and suggest to rename it to release: IRelease

Copy link
Contributor

@rosen-vladimirov rosen-vladimirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After green build

@Plamen5kov Plamen5kov force-pushed the plamen5kov/fix-apk-search-dir branch from 7204eed to 40f5074 Compare March 8, 2018 08:26
@Plamen5kov Plamen5kov merged commit 69bc287 into master Mar 8, 2018
@Plamen5kov Plamen5kov deleted the plamen5kov/fix-apk-search-dir branch March 8, 2018 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants