Skip to content
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

refactor: unify target resolution for devices & emulators #1101

Merged
merged 2 commits into from
Apr 9, 2021

Conversation

raphinesse
Copy link
Contributor

@raphinesse raphinesse commented Oct 19, 2020

Motivation and Context

This change simplifies and deduplicates the code that, given a user-supplied target specification, finds a target to install and run an app on.

This refactoring was triggered by my ongoing work to stop copying cordova/lib to the platform folder.

Description

  • replaced device.list and emulator.list_started with target.list
  • merged the virtually identical methods {device, emulator}.resolveTarget with the part of the target resolution that was implemented in the run module to form the new method target.resolve.
  • the result of the target resolution remains unchanged, log and error messages are a bit different now.

Testing

Updated unit tests pass.

@codecov-io
Copy link

codecov-io commented Oct 19, 2020

Codecov Report

Merging #1101 (0e8da4f) into master (b245337) will decrease coverage by 0.59%.
The diff coverage is 94.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1101      +/-   ##
==========================================
- Coverage   71.19%   70.59%   -0.60%     
==========================================
  Files          21       20       -1     
  Lines        1739     1714      -25     
==========================================
- Hits         1238     1210      -28     
- Misses        501      504       +3     
Impacted Files Coverage Δ
bin/templates/cordova/lib/emulator.js 98.77% <ø> (-0.08%) ⬇️
bin/templates/cordova/lib/target.js 94.44% <92.30%> (-2.33%) ⬇️
bin/templates/cordova/lib/run.js 97.56% <100.00%> (-2.44%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b245337...0e8da4f. Read the comment docs.

raphinesse added a commit to raphinesse/cordova-android that referenced this pull request Oct 19, 2020
raphinesse added a commit to raphinesse/cordova-android that referenced this pull request Oct 22, 2020
@raphinesse raphinesse marked this pull request as ready for review November 17, 2020 09:07
@raphinesse raphinesse marked this pull request as draft November 17, 2020 13:53
@raphinesse
Copy link
Contributor Author

Converted to draft until the PRs that this one depends on are merged (commits marked as [DEP]).

@raphinesse raphinesse force-pushed the unified-target branch 4 times, most recently from 0c62cd6 to 5a816d0 Compare November 21, 2020 09:46
@raphinesse raphinesse changed the title refactor: unify target resolution & installation code for devices & emulators refactor: unify target resolution for devices & emulators Nov 21, 2020
@raphinesse raphinesse marked this pull request as ready for review November 21, 2020 11:14
@erisu
Copy link
Member

erisu commented Apr 9, 2021

@raphinesse From a quick run test, I see a subtle difference.

I haven't covered all cases but here is one example:

When running the command cordova run android --target:

The Main Branch Ending Printout:

Using Android SDK: /Users/cordova/Library/Android/sdk
No target specified and no devices found, deploying to emulator
Failed to execute shell command "getprop,sys.boot_completed" on device: Error: Command failed with exit code 1: adb -s  shell getprop sys.boot_completed
adb: device 'undefined' not found

This PR's Ending Printout:

Using Android SDK: /Users/cordova/Library/Android/sdk
Deploying to emulator emulator-5554
Using apk: /Users/cordova/.test/someRandomProject2/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Package name: com.erisu.someRandomProject2
INSTALL SUCCESS
LAUNCH SUCCESS

As seen, the warning message No target specified and no devices found, deploying to emulator is missing from this PR.

I suspect a refactor shouldn't lose warning messages. I think improvements in visuals, such as spacing, on the other hand, are acceptable.

A bonus from your PR is that it launches the emulator when the target is not provided. The main branch fails to launch even though the warning said it would launch.

Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

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

After testing and communicating over the changes, it was decided to be acceptable and safe for a minor release.

Everything still performs the same except for the warning message printout, which is not necessary and also fixed an issue.

@erisu erisu merged commit c04ea9b into apache:master Apr 9, 2021
@raphinesse raphinesse deleted the unified-target branch June 24, 2021 11:53
wedgberto pushed a commit to wedgberto/cordova-android that referenced this pull request May 17, 2022
* refactor: unify target resolution for devices & emulators
* fix: use unified target methods in platform-centric bins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants