apache / apache/cordova-node-xcode

BUG - addTargetDependency - If project doesn't contain PBXTargetDependency or PBXContainerItemProxy

未关闭
#121 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
217
派生
102
平均合并
2 天 3 小时
30 天内合并 PR
6

描述

# Description
## One Line Summary
`addTargetDependency` misses some dependency links if `PBXTargetDependency` or `PBXContainerItemProxy` are not present.

## Affected Projects
Calls made to `addTarget` or `addTargetDependency` with any `.xcodeproj` that only has one target, these do NOT have `PBXTargetDependency` or `PBXContainerItemProxy`.

## Details
### The root cause
The following if statement in the `addTargetDependency` function skips the dependencies and other steps if it is missing.
https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L860

### Possible fixes
#### Option 1 - Smallest number changes
A simple way to fix this would be to use short-circuit evaluation where these `vars` are assigned to handle `null`, `undefined`, or if no key exists when reading from `hash.project.objects`.
https://github.com/apache/cordova-node-xcode/blob/8b98cabc5978359db88dc9ff2d4c015cba40f150/lib/pbxProject.js#L834-L835
This could become the following to fix this issue:
```javascript
pbxTargetDependencySection = this.hash.project.objects[pbxTargetDependency] || {},
pbxContainerItemProxySection = this.hash.project.objects[pbxContainerItemProxy] || {};
```

I have tested this on some projects on my machine and was able to successfully run an App Extension on an iOS device to confirm the solution works.

#### Option 2 - Larger Refactor - Fix some clean up
Same fix as option 1, but clean up the hard coded strings.

1. Put these at the top of the file:
```javascript
const PBX_TARGET_DEPENDECY = "PBXTargetDependency";
const PBX_CONTAINER_ITEM_PROXY = "PBXContainerItemProxy";
```

2. Use them here and remove the old vars:
```javascript
const pbxTargetDependencySection = this.hash.project.objects[PBXTargetDependency] || {};
const pbxContainerItemProxySection = this.hash.project.objects[PBXContainerItemProxy] || {};
```

## Workaround
```javascript
// Add code anytime before calling addTarget or addTargetDependency
const projObjects = xcodeProject.hash.project.objects;
projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
```

## Related issues
PR #12 also made a note of this issue:
> 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.

They attempted to fix this in a similar way I am suggesting with commit 2e09d78efdb1d667dd513a3c97c46dc448305f5f.
This PR was not merged however, so this is still an active issue.

There is another issue #37, that references PR #12, notes that `targetDependency` is still an issue.

## Submitting a PR - Is this an active library?
It has been over a year since there has been a release or even a commit. If the maintainers could chime in I'd be happy to create one.

I have read the [CONTRIBUTING.md](https://github.com/apache/cordova-node-xcode/blob/master/CONTRIBUTING.md) guide, is there any more to it than that? I see there is a good number of tests, I'll make sure to add one to cover the code change. Lastly let me know which of the possible fixes you prefer or if you have another idea.

贡献指南

打开贡献指南

调研方向

从 lib/pbxProject.js 中的 addTargetDependency 开始,检查现有测试套件对 addTarget 或 addTargetDependency 的覆盖情况。复现不包含 PBXTargetDependency 或 PBXContainerItemProxy 的单 Target .xcodeproj 情况,然后添加回归测试。当依赖项能够被正确创建或处理,并且现有测试仍然通过时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
ios, javascript, nodejs
领域
mobile, tooling
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。