build icon indicating copy to clipboard operation
build copied to clipboard

Add include_defaults for sources in build.yaml to include all default sources

Open rotorgames opened this issue 3 years ago • 6 comments
trafficstars

Every time when we would like to include custom sources to build.yaml file, we also have to add all items from defaultNonRootVisibleAssets or defaultRootPackageSources manually.

It's ok if we develop our own project but if we develop a package for public usage, we need to ask everyone who uses our package to create build.yaml file and define both their sources and all these items in the sources.

For me, it's not good approach because the list of these items can be extended in over time.

So, I suggest to add the include_defaults parameter to sources which includes all sources from defaultNonRootVisibleAssets or defaultRootPackageSources by default.

As result, we can keep our build.yaml clean and event if default sources will be changed in future we will be able easily update them in build_runner_core and provide them for all developer by new publishing.

Example:

targets:
  $default:
    sources:
      include_defaults: true
      include:
        - my_custom_sources/**

rotorgames avatar May 25 '22 13:05 rotorgames

I think instead of adding $defaults$ I would probably add a new key (that looks like a "placeholder" asset, which is a different thing). So maybe something like:

targets:
  $default:
    sources:
      include_defaults: true
      include:
        - my_custom_sources/**

Not sure on the naming of that setting though

jakemac53 avatar May 25 '22 14:05 jakemac53

@jakemac53 I guess we can implement it without huge changes in the code.

My approach with $defaults$ looks not too bad as well to be honest cuz we already have the $package$ and the $lib$, so the $defaults$ just extends the list of existed synthetic sources.

Maybe, we can vote for the best approach here?

rotorgames avatar May 25 '22 22:05 rotorgames

so the $defaults$ just extends the list of existed synthetic sources.

But $default$ is not a synthetic source, that has a specific meaning and purpose (it can be used as an actual input, for builders that are intended to run on entire packages and have no input to pin off of).

Some other solution needs to be chosen that doesn't conflate the two things.

jakemac53 avatar May 26 '22 14:05 jakemac53

@jakemac53 I changed my approach to include_defaults. Please, take a look.

rotorgames avatar May 27 '22 11:05 rotorgames

One other thing here, is the InputSet class is occasionally used for things other than sources, in particular it is also used for generate_for.

We probably want to do some validation that people aren't passing it for those types of targets. I could see either some validation on TargetBuilderConfig to check that people don't try to use it for generateFor, or possibly we can do something more general, in the InputMatcher class, where it doesn't allow an input set with includeDefaults == true but no actual defaults provided.

jakemac53 avatar May 31 '22 18:05 jakemac53

We probably want to do some validation that people aren't passing it for those types of targets. I could see either some validation on TargetBuilderConfig to check that people don't try to use it for generateFor, or possibly we can do something more general, in the InputMatcher class, where it doesn't allow an input set with includeDefaults == true but no actual defaults provided.

Or actually it occurs to me that we could support include_defaults for generate_for, but the "defaults" in that case would just be the sources globs? So that way you could easily exclude just a few sources for instance.

jakemac53 avatar Jun 03 '22 15:06 jakemac53

Have been done in https://github.com/dart-lang/build/pull/3390

rotorgames avatar Nov 08 '22 05:11 rotorgames