dart-lang / build

A build system for Dart written in Dart
https://pub.dev/packages/build
BSD 3-Clause "New" or "Revised" License
777 stars 205 forks source link

Add configuration set aliases #1544

Open natebosch opened 6 years ago

natebosch commented 6 years ago

Allow builder to define a simple alias which represents multiple options. This would be an enhancement over release/dev option defaults.

Use case: To truly debug in prod mode we would need to set options on multiple builders. The Dart source cleanup would need to stop filtering out Dart files, and the dart2js archive extractor would need to stop filtering out the source map. Our instructions today recommend running without --release and enabling dart2js becaus it's a smaller amount to --define, but it also means you're not getting release mode options for any other builder. We could allow both of these builders to agree on what the option alias debug or keep_source_maps should mean and provide the right configuration for that intention.

Configuration would look something like:

builders:
  some_builder_name:
    ...
    defaults:
      release_options:
        compiler: dart2js
        dart2js_use_source_maps: false
    option_aliases:
      debug:
        help: "Keep source maps"
        options:
          dart2js_use_source_maps: true

Usage looks like:

pub run build_runner build --release --define debug

Behind the scenes we'd merge in the options in the following order:

  1. Existing options as we're using them today:
    • builder defaults
    • builder defaults by mode
    • user options
    • user options by mode
  2. Global options from build.yaml
  3. Option aliases
  4. "legacy" style --define options
jakemac53 commented 6 years ago

Should we also enable using these aliases when statically configuring a builder somehow?

natebosch commented 6 years ago

Should we also enable using these aliases when statically configuring a builder somehow?

I don't see why not as long as we can make a decision about syntax and merge order.

targets:
  $default:
    builders:
      some_package:
        option_sets:
          - debug
        options:
          foo: bar
        release_options:
          foo: baz
  1. builder defaults
  2. builder defaults by mode
  3. Option sets from build.yaml
  4. user options
  5. user options by mode
  6. Global option sets.
  7. Global options from build.yaml
  8. Option aliases from command line
  9. "legacy" style --define options
jakemac53 commented 6 years ago

What if you want to only apply an option set in a specific mode though? Do we support debug_option_sets etc? lol