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

[2/n] Handle module names shadowed by nominal types #172

Merged

Conversation

andrewchang-bird
Copy link
Contributor

@andrewchang-bird andrewchang-bird commented Sep 25, 2020

⚠️ Stack 2 of n ⚠️

Types can shadow the module name they're declared in, which breaks the existing type qualification system. Until Swift gains a fully qualified module name syntax, there aren't many good options without splitting the output to directly mirror the source file structure (which would preserve file import namespacing and remove the need for qualification).

https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482

This change strips module qualification from type references if a tracked type is found to shadow the module name. Note that untracked symbols like global functions, structs, and enums that shadow the module name aren't handled yet.

Custom build systems such as Buck or Bazel need a way to generate mocks
without an `.xcodeproj` file. This adds support for passing a JSON
project description containing all of the required module and dependency
graph information usually parsed from an Xcode project. The description
format is roughly compatible with the output from
`$ swift package describe --type JSON`, although adding the `dependency`
field needs to be upstreamed.

```json
{
  "targets": [
    {
      "name": "MyLibrary",
      "type": "library",
      "path": "/path/to/my-library",
      "dependencies": [],
      "sources": [
        "SourceFileA.swift",
        "SourceFileB.swift"
      ]
    },
    {
      "name": "MyOtherLibrary",
      "type": "library",
      "path": "/path/to/my-other-library",
      "dependencies": [
        "MyLibrary"
      ],
      "sources": [
        "SourceFileA.swift",
        "SourceFileB.swift"
      ]
    },
    {
      "name": "MyLibraryTests",
      "type": "test",
      "path": "/path/to/my-library-tests",
      "dependencies": [
        "MyLibrary"
      ],
      "sources": [
        "SourceFileA.swift",
        "SourceFileB.swift"
      ]
    }
  ]
}
```

The `--project` generator option now accepts arbitrary files. Iff a file
with an `xcodeproj` extension is provided then it is read as an Xcode
project. Cache metadata is stored in the same enclosing directory as the
project description file under the `.mockingbird` subdirectory.

Since builds are run outside of an Xcode testing context, it's necessary
to optionally provide a host test target with the `--testbundle` option
to enable thunk pruning support.

```bash
mockingbird generate \
  --target MyLibrary \
  --testbundle MyLibraryTests \
  --project /path/to/project-desc.json
```
Types can shadow the module name they're declared in, which breaks the
existing type qualification system. Until Swift gains a fully qualified
module name syntax, there aren't many good options without splitting the
output to directly mirror the source file structure (which would
preserve file import namespacing and remove the need for qualification).

https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482

This change strips module qualification from type references if a
tracked type is found to shadow the module name. Note that untracked
symbols like global functions, structs, and enums that shadow the module
name aren't handled yet.
@andrewchang-bird andrewchang-bird added this to the Release 0.16 milestone Sep 25, 2020
@andrewchang-bird andrewchang-bird changed the title Handle module names shadowed by nominal types [2/n] Handle module names shadowed by nominal types Sep 25, 2020
@andrewchang-bird andrewchang-bird merged commit 775426c into typealiased:master Sep 30, 2020
@andrewchang-bird andrewchang-bird deleted the module-name-shadowing branch September 30, 2020 17:38
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.

None yet

2 participants