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

[1/n] Add support for reading JSON project descriptions #171

Merged

Conversation

andrewchang-bird
Copy link
Contributor

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

⚠️ Stack 1 of n ⚠️

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.

{
  "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.

mockingbird generate \
  --target MyLibrary \
  --testbundle MyLibraryTests \
  --project /path/to/project-desc.json

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
```
@andrewchang-bird andrewchang-bird added this to the Release 0.16 milestone Sep 25, 2020
@andrewchang-bird andrewchang-bird changed the title Add support for reading JSON project descriptions [1/n] Add support for reading JSON project descriptions Sep 25, 2020
@andrewchang-bird andrewchang-bird merged commit eef1217 into typealiased:master Sep 30, 2020
@andrewchang-bird andrewchang-bird deleted the json-project-description branch September 30, 2020 17:37
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