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: replace copy-www-build-step script with build phase #1158

Merged
merged 4 commits into from
Oct 31, 2021

Conversation

NiklasMerz
Copy link
Member

Platforms affected

iOS and Mac (Catalyst)

Motivation and Context

We could move the build step of copying the www directory and config.xml to the Xcode "Copy files" commands to avoid issues from the manual script like changed paths or different paths between iOS and macOS.

See #699

Description

Up for discussion.

Some links: #699 (comment)

This is probably the most important reason for the script: https://issues.apache.org/jira/browse/CB-5397?focusedCommentId=13859057&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13859057

Testing

  • Run iOS simulator from CLI
  • Run iOS simulator from Xcode
  • Run Mac (designed for iPad) from Xcode
  • Enable and run Mac natively (M1) from Xcode

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@NiklasMerz NiklasMerz requested a review from dpogue October 8, 2021 19:22
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2021

Codecov Report

Merging #1158 (dc6a878) into master (92e6830) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1158   +/-   ##
=======================================
  Coverage   74.86%   74.86%           
=======================================
  Files          13       13           
  Lines        1723     1723           
=======================================
  Hits         1290     1290           
  Misses        433      433           

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 92e6830...dc6a878. Read the comment docs.

Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

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

You'll need to go through the bin/templates/project/__TEMP__.xcodeproj/project.pbxproj diff and manually re-add all the quotation marks Xcode helpfully removed 🙄
Those are needed to support projects where __PROJECT_NAME__ contains spaces.

@NiklasMerz
Copy link
Member Author

Fixed now. Good to know why they are there.

I should have checked the diff again. These Xcode files are tricky.

@NiklasMerz NiklasMerz marked this pull request as ready for review October 8, 2021 20:47
@NiklasMerz NiklasMerz requested a review from dpogue October 8, 2021 20:47
Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

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

I've been testing this locally, and it's actually copying the wrong files into Resources. It's pulling ../../config.xml when it needs to pull the __PROJECT_NAME__/config.xml file, and likewise with www.

In Xcode, these are shown in a Staging group.

@dpogue dpogue mentioned this pull request Oct 19, 2021
@NiklasMerz
Copy link
Member Author

@dpogue How did you test that? What's the best way to reproduce this?

I did quick tests and this www folder and config.xml look like the right one. I changed them to __Project_NAME/.. but then plugins won't work anymore because cordovas js files are missing.

My test:

  • Change index.html, build ios, run app on mac and ios sim -> see changes
  • Change index.html in config.xml, build ios, run mac and ios sim from Xcode -> page cannot load

To me this looks like the right files get copied into the app.

@dpogue
Copy link
Member

dpogue commented Oct 20, 2021

hmm, I was testing this as part of #1162 (which used this as a starting point) and getting "Connecting to device..." in the simulator, and log messages about the Console plugin not being found.

This should work to reproduce:

npx cordova@nightly create xcodeTestApp
cd xcodeTestApp
npx cordova@nightly platform add github:apache/cordova-ios#xcode-copy
open platforms/ios/HelloCordova.xcworkspace
# Run the app in a simulator from Xcode

@NiklasMerz
Copy link
Member Author

This works fine for me. Is there another edge case where this could break?

@dpogue
Copy link
Member

dpogue commented Oct 20, 2021

I'll try to poke at this a bit more today and see if I can figure out what was going wrong on my end

@NiklasMerz
Copy link
Member Author

I just tried the device plugin and indeed it gets stuck at deviceready with this errror:

HelloCordova[24238:422811] ERROR: Plugin 'Device' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.

I am not sure yet whats the issue.

@NiklasMerz NiklasMerz linked an issue Oct 21, 2021 that may be closed by this pull request
@@ -14,6 +14,8 @@
302D95F114D2391D003F00A1 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D95EF14D2391D003F00A1 /* MainViewController.m */; };
302D95F214D2391D003F00A1 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 302D95F014D2391D003F00A1 /* MainViewController.xib */; };
6AFF5BF91D6E424B00AB3073 /* CDVLaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6AFF5BF81D6E424B00AB3073 /* CDVLaunchScreen.storyboard */; };
857339E22710CC8900A1C74C /* config.xml in Copy config.xml */ = {isa = PBXBuildFile; fileRef = EB87FDF41871DAF40020F90C /* config.xml */; };
Copy link
Member

Choose a reason for hiding this comment

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

I believe the issue is that fileRef here should be F840E1F0165FE0F500CFE078 to refer to __PROJECT_NAME__/config.xml rather than ../../config.xml

Copy link
Member Author

Choose a reason for hiding this comment

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

This Xcode UI is hard to use... I think F840E1F0165FE0F500CFE078 is this file:

grafik

Both config.xml there don't seem to work for me.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we want the config.xml from the staging folder.

Copy link
Member Author

Choose a reason for hiding this comment

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

So probably the config copy is not origin of the plugin issue.

@NiklasMerz
Copy link
Member Author

Interesting side fact. I just tried to run the osx platform on the M1 mac with this PR apache/cordova-osx#105 and got the same error:

ERROR: Plugin 'Device' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.

@jcesarmobile
Copy link
Member

Can’t we remove the duplicated www/config.xml and have a single one, that is what prepare command copies? I always found confusing having two, the staging one and the root one.

@dpogue
Copy link
Member

dpogue commented Oct 26, 2021

Can’t we remove the duplicated www/config.xml and have a single one, that is what prepare command copies? I always found confusing having two, the staging one and the root one.

The root one is the app developer-authored one, where they configure the app name, icons, preferences, and allow list.
The staging one is the contents of the root one, with the additions from all the plugins, and is the one that needs to be bundled into the app bundle.

The root one is displayed in Xcode for convenience of the app developer if they are working in the native project, to make edits to config.xml (and www) and not have those changes overwritten when running prepare.

The staging one must be in Xcode to be handled as a resource for copying into the app bundle.

So I don't think we can get rid of either of them, despite how confusing it is to have both 😞

NiklasMerz and others added 4 commits October 28, 2021 19:06
- Combined "Copy www" & "Copy config.xml" into "Copy Staging Resources"
- Copy content from "Staging" group into Resources
@erisu erisu requested a review from dpogue October 28, 2021 11:26
@erisu
Copy link
Member

erisu commented Oct 28, 2021

@dpogue I have updated this PR to properly copy the correct content as well as simplify the build process. This PR is strictly focused on copying the app resources to the correct location.

I have combined the build phases Copy www & Copy config.xml into one build phase call Copy Staging Resources.

The contents of the "Staging" group are, www and config.xml.

The location of these resources come from:

  • <project-dir>/platforms/ios/www/
  • <project-dir>/platforms/ios/<project-name>/config.xml

And these are what cordova prepare generates.

Additionally, the combine build phase is not blindly copying an entire grouping. If users add things to that group, they would still need to update the build phase to include those items to be copied. I think from a Cordova perspective, users should not add anything to this grouping anyways.

@erisu erisu changed the title (refactor): move copy-www-build-step script to Xcode commands refactor: replace copy-www-build-step script with build phase Oct 28, 2021
Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

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

I've tested this (including with Catalyst) and it is working as expected. Also tested with cordova-plugin-device added, and was able to print out device information.

Copy link
Member Author

@NiklasMerz NiklasMerz left a comment

Choose a reason for hiding this comment

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

Thanks @erisu for completing this and your good explanation. It's working as espected for me as well with all Mac configurations and an iOS simulator.

@dpogue dpogue merged commit cc111ed into master Oct 31, 2021
@dpogue dpogue deleted the xcode-copy branch October 31, 2021 03:54
gazben pushed a commit to apicore-engineering/cordova-ios that referenced this pull request Aug 26, 2022
…#1158)

* (refactor): move copy-www-build-step script to Xcode commands

See apache#699

* select files to copy

* copy config.xml from staging

* feat: copy staging resources

- Combined "Copy www" & "Copy config.xml" into "Copy Staging Resources"
- Copy content from "Staging" group into Resources

Co-authored-by: Erisu <erisu@apache.org>
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.

Catalyst for ios platform ?
5 participants