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

Fix issues with pbxFile extension and addTargetDependency sections #12

Closed
wants to merge 8 commits into from

Conversation

kspearrin
Copy link
Contributor

@kspearrin kspearrin commented Sep 5, 2018

This PR fixes a few issues I discovered while using this library to add an app extension to a pbxproject.

  1. new pbxFile('AppExtension', { explicitFileType: '"wrapper.app-extension"'}) gets indirectly called when using proj.addTarget('AppExtension', 'app_extension'). This results in an incorrect extension being added to the basename when trying to determine the extension from defaultExtension (detectType sets it to the literal string "unknown" which fails falsey checks). The result would end up being AppExtension.undefined instead of the correct AppExtension.appex. Also corrected a missing unquoted() call in the defaultExtension() function which also led to the same failure.

  2. addTargetDependency() is indirectly called as well from proj.addTarget('AppExtension', 'app_extension'). In my project, PBXTargetDependency and PBXContainerItemProxy sections did not yet exist which results in the necessary dependencies not being set up properly for building the extension with the main app. Create these sections if they do not exist.

  3. In the various functions that build out buildSettings, it checks for the PRODUCT_NAME to be the same as the project's product name. This never matches if you are using these functions on the app extension, since it has a different PRODUCT_NAME. Allow a product name to be passed as an option to these functions.

  4. Added showEnvVarsInLog option to pbxShellScriptBuildPhaseObj. Passing this a false will set showEnvVarsInLog = 0.

All tests (and the newly added) pass.

@janpio
Copy link
Member

janpio commented Sep 5, 2018

Offtopic:

This PR fixes two issues I discovered while using this library to add an app extension to a pbxproject

Public repository somewhere? I remember some people asking about something like that...

@kspearrin
Copy link
Contributor Author

@janpio We are looking into moving to NativeScript (from Xamarin) with our app here: https://github.com/bitwarden/mobile/tree/ns2 . Though most of what is going on right now is just discovery so not all work is committed.

@janpio
Copy link
Member

janpio commented Sep 5, 2018

Ah ok, let me know if this works out with cordova-node-xcode and that code is online.

@brodycj
Copy link

brodycj commented Dec 9, 2018

What is the status of this proposal?

@brodycj brodycj mentioned this pull request Dec 9, 2018
11 tasks
Copy link
Contributor

@n1ru4l n1ru4l left a comment

Choose a reason for hiding this comment

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

I added some comments, the overall functionality seems fine, but please us strict equal checks instead of the abstract equal checks

test/pbxFile.js Outdated
@@ -278,5 +278,13 @@ exports['settings'] = {

test.deepEqual({COMPILER_FLAGS:'"-std=c++11 -fno-objc-arc"'}, sourceFile.settings);
test.done();
},

'should have extension if {explicitFileType:"blah"} specified': function (test) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the test name here does not match the actual content of the test

lib/pbxProject.js Outdated Show resolved Hide resolved
lib/pbxProject.js Outdated Show resolved Hide resolved
lib/pbxProject.js Outdated Show resolved Hide resolved
lib/pbxProject.js Outdated Show resolved Hide resolved
test/pbxFile.js Outdated Show resolved Hide resolved
@brodycj
Copy link

brodycj commented Dec 9, 2018

Thanks @n1ru4l for reviewing. It looks like we do want at least some of the proposed changes but I still don't really understand everything that is changed here.

n1ru4l and others added 2 commits December 10, 2018 10:03
Co-Authored-By: kspearrin <kspearrin@users.noreply.github.com>
@kspearrin
Copy link
Contributor Author

kspearrin commented Dec 10, 2018

@n1ru4l Suggested changes applied.

Copy link

@brodycj brodycj left a comment

Choose a reason for hiding this comment

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

  • Several changes in lib/pbxFile.js are not covered by testing. Reverting these proposed changes would not cause any test failures
  • None of the changes in lib/pbxProject.js are covered by testing. Reverting all of the proposed changes in this file would not cause any test failures.

I would favor merging the first few changes in lib/pbxFile.js, which seem to be properly tested, and dealing with the other changes in one or more separate PRs.

Also +1 for changing != to !== but I would favor making this kind of fix, throughout this project, in its own PR.

return extension;
}
}
}

function defaultEncoding(fileRef) {
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
fileRef.lastKnownFileType : fileRef.explicitFileType,
Copy link

Choose a reason for hiding this comment

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

This change is not covered by testing.

@@ -119,7 +121,8 @@ function defaultEncoding(fileRef) {

function detectGroup(fileRef, opt) {
var extension = path.extname(fileRef.basename).substring(1),
filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
fileRef.lastKnownFileType : fileRef.explicitFileType,
Copy link

Choose a reason for hiding this comment

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

This change is not covered by testing.

@@ -139,7 +142,8 @@ function detectGroup(fileRef, opt) {

function detectSourcetree(fileRef) {

var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
fileRef.lastKnownFileType : fileRef.explicitFileType,
Copy link

Choose a reason for hiding this comment

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

This change is not covered by testing.

@@ -158,7 +162,8 @@ function detectSourcetree(fileRef) {
}

function defaultPath(fileRef, filePath) {
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
fileRef.lastKnownFileType : fileRef.explicitFileType,
Copy link

Choose a reason for hiding this comment

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

This change is not covered by testing.

@brodycj
Copy link

brodycj commented Dec 10, 2018

I would like to add one more tip that you should always make a new branch when proposing changes to keep your master branch clean and give us a more sensical commit message in case of a merge commit.

Thanks @kspearrin for your efforts.

brodycj pushed a commit to brodycj/cordova-node-xcode that referenced this pull request Dec 11, 2018
where pbxFile extension was being set to 'undefined'

and add new test case to verify the bug fix

NOTE: These changes were originally part of
apache#12 (cordova-node-xcode PR apache#12),
extracted here by @brodybits (Christopher J. Brody).

Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
Co-authored-by: Christopher J. Brody <brodybits@litehelpers.net>
brodycj pushed a commit that referenced this pull request Dec 11, 2018
where pbxFile extension was being set to 'undefined'

and add new test case to verify the bug fix

with a quick test fix by @brodybits (Christopher J. Brody)
for the sake of consistency with the other test cases

NOTE: These changes were originally part of
#12 (cordova-node-xcode PR #12),
extracted here by @brodybits.

Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
Co-authored-by: Christopher J. Brody <brodybits@litehelpers.net>
@brodycj
Copy link

brodycj commented Dec 12, 2018

The changes to fix the pbxFiile extension issue were merged in PR #37, with due credit given to @kspearrin. I am closing this one, raised #37 to track the other issues that should be fixed. We really cannot make the other proposed fixes without test coverage, otherwise we risk things breaking at some random time in the future.

The strict equality checks will be done when we introduce the eslint updates (#36).

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