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

Introduce the snippet target type #3694

Merged
merged 1 commit into from
Sep 2, 2021

Conversation

bitjammer
Copy link
Contributor

Snippets are small, focused pieces of example code for packages. They are meant
for current and potential package clients to read and try when exploring a
package.

Snippets build with the rest of a package so they don't get stale and
can run as an executable target with hidden "demo code" to illustrate and prove
that the snippets work (this does not mean that snippets are tests!).

Summary of changes:

  • Add a .snippet product and target type
  • Add the Snippet and SnippetGroup model to PackageModel
  • When building a package in PackageBuilder, look for snippets in the
    Snippets subdirectory.
  • Add the "card stack" terminal UIs for browsing a package's snippets
    • "Top" card: The top level menu that displays products and snippet groups
    • "Snippet Group" card: The menu that shows the snippets in a group
    • "Snippet" card: Displays a snippet's presentation code and offers
      to build and run the snippet.

[One line description of your change]

Motivation:

[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]

Modifications:

[Describe the modifications you've done.]

Result:

[After your change, what will change.]

@bitjammer
Copy link
Contributor Author

Note: Color support was for convenience, happy to put that elsewhere.

Copy link
Contributor

@neonichu neonichu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @bitjammer. This looks great, just a couple of smaller points to discuss.

Sources/PackageLoading/PackageBuilder.swift Outdated Show resolved Hide resolved
Sources/PackageModel/Product.swift Show resolved Hide resolved
@@ -0,0 +1,35 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if some of the UI for snippets should be in a distinct module from Commands. I could see that this would be something we may want to expose via libSwiftPM at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking the same thing actually. Before committing to that, what do you say we keep it here for now while we refine it some more? I think it will probably change a bit in the coming months.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I think that's fine.

@neonichu
Copy link
Contributor

neonichu commented Sep 1, 2021

@swift-ci please smoke test

@neonichu
Copy link
Contributor

neonichu commented Sep 1, 2021

/home/buildnode/jenkins/workspace/swift-package-manager-Linux-smoke-test/branch-main/swiftpm/Sources/Commands/SwiftPackageTool.swift:1165:85: error: cannot find type 'SnippetGroup' in scope
21:55:18 func loadSnippetsAndSnippetGroups(from package: ResolvedPackage) throws -> [SnippetGroup] {
21:55:18 ^~~~~~~~~~~~

I think we probably have to update the CMake build in some way.

BTW, you can probably locally reproduce this by running ./Utilities/bootstrap build. When using the bootstrap script, we build an initial copy of SwiftPM using CMake and then use that to build the "real" SwiftPM using itself.

@bitjammer
Copy link
Contributor Author

Ah thank you. I didn't realize this project also had to work with cmake. Looks like Commands probably needs to link PackageModel – any concerns with that?

@bitjammer
Copy link
Contributor Author

Oh, heh. I suppose I should add the source files actually...

Snippets are small, focused pieces of example code for packages. They are meant
for current and potential package clients to read and try when exploring a
package.

Snippets build with the rest of a package so they don't get stale and
can run as an executable target with hidden "demo code" to illustrate and prove
that the snippets work (this does not mean that snippets are tests!).

Summary of changes:

- Add a `.snippet` product and target type
- Add the `Snippet` and `SnippetGroup` model to PackageModel
- When building a package in `PackageBuilder`, look for snippets in the
  `Snippets` subdirectory.
- Add the "card stack" terminal UIs for browsing a package's snippets
  - "Top" card: The top level menu that displays products and snippet groups
  - "Snippet Group" card: The menu that shows the snippets in a group
  - "Snippet" card: Displays a snippet's presentation code and offers
    to build and run the snippet.
@bitjammer
Copy link
Contributor Author

@swift-ci please smoke test

@bitjammer bitjammer merged commit a0ffd92 into swiftlang:main Sep 2, 2021
@bitjammer bitjammer deleted the acgarland/snippets branch September 2, 2021 15:28
mattt pushed a commit to mattt/swift-package-manager that referenced this pull request Sep 16, 2021
Snippets are small, focused pieces of example code for packages. They are meant
for current and potential package clients to read and try when exploring a
package.

Snippets build with the rest of a package so they don't get stale and
can run as an executable target with hidden "demo code" to illustrate and prove
that the snippets work (this does not mean that snippets are tests!).

Summary of changes:

- Add a `.snippet` product and target type
- Add the `Snippet` and `SnippetGroup` model to PackageModel
- When building a package in `PackageBuilder`, look for snippets in the
  `Snippets` subdirectory.
- Add the "card stack" terminal UIs for browsing a package's snippets
  - "Top" card: The top level menu that displays products and snippet groups
  - "Snippet Group" card: The menu that shows the snippets in a group
  - "Snippet" card: Displays a snippet's presentation code and offers
    to build and run the snippet.
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.

2 participants