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

Add extraProjects and derivedProjects (formerly known as buildExtras and projectExtras) #2717

Merged
merged 1 commit into from
Aug 27, 2016

Conversation

eed3si9n
Copy link
Member

@eed3si9n eed3si9n commented Aug 27, 2016

Fixes #2532

This adds support to generate synthetic subprojects from an auto plugin.

In addition, a method called projectOrigin is added to distinguish Organic, BuildExtra, ProjectExtra, and GenericRoot.

To generate subprojects, override buildExtras
method as follows:

import sbt._
import Keys._

object BuildExtrasPlugin extends AutoPlugin {
  override def buildExtras: Seq[Project] =
    List("foo", "bar", "baz") map generateProject

  def generateProject(id: String): Project =
    Project(id, file(id)).
      settings(
        name := id
      )
}

Subprojects may also be derived from an existing subproject
by overriding projectExtras.

import sbt._
import Keys._

object ProjectExtrasPlugin extends AutoPlugin {
  // Enable this plugin by default
  override def requires: Plugins = sbt.plugins.CorePlugin
  override def trigger = allRequirements

  override def projectExtras(proj: ProjectDefinition[_]): Seq[Project] =
    // Make sure to exclude project extras to avoid recursive generation
    if (proj.projectOrigin != ProjectOrigin.ProjectExtra) {
      val id = proj.id + "1"
      Seq(
        Project(id, file(id)).
          enablePlugins(DatabasePlugin)
      )
    }
    else Nil
}

/review @dwijnand, @Duhemm

@eed3si9n eed3si9n changed the title Add buildExtras and projectExtras. Fixes #2532 Add buildExtras and projectExtras Aug 27, 2016
@eed3si9n eed3si9n added this to the 0.13.13 milestone Aug 27, 2016
@dwijnand
Copy link
Member

Wow knocking them out the park this week, awesome.

I'm only concerned with the name buildExtras: for builds where all the projecrs are programmatically generated it sounds a bit weird. So I was thinking perhaps just "projects" (like we have projectSettings, not extraProjectSettings).

projectExtras I'm not sure of either, but I don't have any better suggestions.

@eed3si9n
Copy link
Member Author

So I was thinking perhaps just "projects" (like we have projectSettings, not extraProjectSettings).

  • If I call it projects that would imply both the organic one and synthetic ones.
  • If I call it syntethicProjects or extras that would imply both the build-level and project-level.

buildExtras I think has a nice symmetry with buildSettings and easy to grasp what it would do.

@dwijnand
Copy link
Member

dwijnand commented Aug 27, 2016

I see the organic/synthetic project argument. But what's a project-level project?

@eed3si9n
Copy link
Member Author

def projectExtras(proj: ProjectDefinition[_]): Seq[Project].
project-level extras allow you to generate a synthetic subproject from an existing stuff.

@dwijnand
Copy link
Member

I see. Cool.

On Sat, 27 Aug 2016, 12:36 eugene yokota, notifications@github.com wrote:

def projectExtras(proj: ProjectDefinition[_]): Seq[Project].
project-level extras allow you to generate a synthetic subproject from an
existing stuff.


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#2717 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAVCIvR7_JMVyMReQvQjAm1MrowZ1r6uks5qkBMrgaJpZM4JuqPL
.


/** Definitively set the [[ProjectOrigin]] for this project. */
private[sbt] def setProjectOrigin(origin: ProjectOrigin): Project = {
// TODO: for 0.14.0, use copy when it has the additional `autoPlugins` parameter
Copy link
Member

Choose a reason for hiding this comment

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

Is this TODO right?

Copy link
Member Author

@eed3si9n eed3si9n Aug 27, 2016

Choose a reason for hiding this comment

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

It should be additional projectOrigin parameter, I guess.

@dwijnand
Copy link
Member

I'm really happy to see progress, thank you.

Reviewed, some minor tweaks, but generally LGTM.

This adds support to generate synthetic subprojects from an auto plugin.

In addition, a method called `projectOrigin` is added to distinguish
Organic, BuildExtra, ProjectExtra, and GenericRoot.
@eed3si9n
Copy link
Member Author

Pushed a commit per reviews.

@eed3si9n eed3si9n merged commit d0ce0ce into sbt:0.13 Aug 27, 2016
@eed3si9n eed3si9n deleted the wip/plugin branch August 27, 2016 19:03
@mslinn
Copy link

mslinn commented Aug 27, 2016

Docs addressing motivation (why does this feature exist, what problems does it solve) would be helpful.

@clhodapp
Copy link

I agree 100% with @dwijnand's first comment. The feature itself here is absolutely terrific. That said, calling these "extras" feels really under-descriptive to me. There are innumerable "extra" things that could be generated by a plugin, so, as a user, why would I assume that the "extras" would be projects? Also, @dwijnand indicates, this naming would feel kind of weird if you were in a setting where most projects were generated (maybe someone defines a plugin in the future for opinionated builds described by a JSON dependencies file, for instance). Why not just call them generatedProjects and generatedSubprojects?

@clhodapp
Copy link

Or derivedProjects for the second one might be more accurate

@eed3si9n
Copy link
Member Author

There are innumerable "extra" things that could be generated by a plugin, so, as a user, why would I assume that the "extras" would be projects?

A typical build user would not see the method name when they consume a plugin. This is mostly for advanced plugin authors.

I want the names that can be used as noun phrase like projectSettings and buildSettings that would distinguish the build- and project-level clearly. generatedProjects + derivedProjects are not bad, but they are more subtle because you can claim that both are "generated" and/or "derived" off of something like JSON. Can we come up with something that's unambiguous?

@ahjohannessen
Copy link
Contributor

Why not just subProjects ?

@clhodapp
Copy link

clhodapp commented Sep 7, 2016

How about independentProjects and derivedProjects?

One thing I'll note now that I've thought about it is that sbt's model doesn't even really include the notion of "subprojects" unless you count aggregation (which I don't think is in play here). There are just "projects". So isn't it a bit confusing to say that these generated projects are "subprojects"?

@mslinn
Copy link

mslinn commented Sep 7, 2016

I do not believe it is accurate to say SBT does not support the concept of subprojects. See dependsOn in the multi-project build page.

@eed3si9n
Copy link
Member Author

eed3si9n commented Sep 7, 2016

ok. How about:

def extraProjects: Seq[Project]
def derivedProjects(proj: ProjectDefinition[_]): Seq[Project]

?

@clhodapp
Copy link

clhodapp commented Sep 7, 2016

That combo is better than any one so far. From my point of view, the bikeshedding can stop with them ;). Thanks again for this great feature.

@clhodapp
Copy link

clhodapp commented Sep 7, 2016

@mslinn That usage of "subproject" means "subproject of the build" not "subproject of another project" and is roughly synonymous with just "project".

@mslinn
Copy link

mslinn commented Sep 7, 2016

@clhodapp if this is going to be an ongoing source of confusion, the docs should introduce a term like "build subproject" or "subbuild" - I don't care if the b's are elided or not.

eed3si9n added a commit to eed3si9n/sbt that referenced this pull request Sep 15, 2016
@eed3si9n
Copy link
Member Author

Sent PR for the rename (#2738)

@eed3si9n eed3si9n changed the title Add buildExtras and projectExtras Add extraProjects and derivedProjects (formerly known as buildExtras and projectExtras) Sep 16, 2016
This was referenced Sep 27, 2016
dwijnand pushed a commit to dwijnand/sbt that referenced this pull request Sep 28, 2016
This adds support to generate synthetic subprojects from an auto plugin.

In addition, a method called `projectOrigin` is added to distinguish
Organic, BuildExtra, ProjectExtra, and GenericRoot.

Forward-port of sbt#2717 and sbt#2738
dwijnand pushed a commit to dwijnand/sbt that referenced this pull request Sep 29, 2016
This adds support to generate synthetic subprojects from an auto plugin.

In addition, a method called `projectOrigin` is added to distinguish
Organic, BuildExtra, ProjectExtra, and GenericRoot.

Forward-port of sbt#2717 and sbt#2738
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

5 participants