bazelbuild / bazelbuild/rules_apple
Incorrect module name in the compiled managed object model file (`.mom`)
- Dominant language
- Starlark
- Stars
- 593
- Forks
- 334
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 9
Description
Hi,
I have the following setup
```
ios_unit_test (FooTests) -> swift_library (FooTestsLib) -> swift_library (FooLib) -> apple_resource_bundle (FooBundle)
```
`FooBundle` wraps a Core Data model `Foo.xcdatamodel`.
A) Given module name is not explicitly set in `Foo.xcdatamodel`
(Xcode view of `Foo.xcdatamodel`)
```
... representedClassName=".DBFoo" ...
```
(raw view of `Foo.xcdatamodel/contents`)
when i build unit tests, the module name in the generated `.xctest/Foo.bundle/Foo.momd/Foo.mom` file is incorrect `FooTests__internal____test_bundle` (`plutil -p Foo.mom`), therefore the Core Data model fails to load from unit tests.
(Xcode view of `.xcdatamodel` reversed from `.mom` using https://github.com/atomicbird/momdec)
B) If i explicitly set module name in `Foo.xcdatamodel`
```
... representedClassName="Foo.DBFoo" ...
```
when i build unit tests, the module name in the generated `.xctest/Foo.bundle/Foo.momd/Foo.mom` file is correct `Foo`, and the Core Data model successfully loads from unit tests.
- - - -
I have created a minimal repro example: https://github.com/vakhidbetrakhmadov/rules_apple/tree/core-data-repro-2/examples/repro
A) Run `bazelisk build //examples/repro:FooTests` and examine `.mom` file in the generated `.xctest` bundle.
B) Run `git apply examples/repro/module_name.patch && bazelisk build //examples/repro:FooTests` and examine `.mom` file in the generated `.xctest` bundle.
Contributor guide
Research direction
Start with the minimal reproduction under examples/repro and run bazelisk build //examples/repro:FooTests. Inspect Foo.mom in the generated .xctest/Foo.bundle/Foo.momd directory, then apply examples/repro/module_name.patch and repeat the build. Done means the generated module name is correct without explicitly setting it in Foo.xcdatamodel and the Core Data model loads from unit tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- build-system, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100