Skip to content

artifacts class refactoring in the flutter_tool #80875

@jonahwilliams

Description

@jonahwilliams

When trying to migrate artifacts.dart to null safety (context #79866) I discovered that the API is currently in a pretty bad state. Based on the type of Artifact, the caller is required to provide zero or more of the build mode, target platform, and environment enums. This has made the null safety migration awkward, since all arguments must be nullable and its up to the callsite to unit test to ensure correctness.

I think we should fix this, though not to the point of completely rewriting the library.

Given that each value of the Artifacts enum has different requirements, we should split the single enum into various different enums based on what they require to be looked up, and then create specialized lookup methods.

For example, the dartSdkPath does not require a build mode or target platform, this could be part of a "HostPlatform" artifacts:

enum HostPlatformArtifact {
  dartSdkPath,
  flutterWebSdkPath,
  iproxy,
  ...
}

String getHostPlatformArtifact(HostPlatformArtifact artifact) { ... }

Similarly, the gen_snapshot binaries always require a target platform and build mode:

enum TargetPlatformArtifact {
  genSnapshot,
  ...
}

String getTargetPlatformArtifact(HostPlatformArtifact artifact, BuildMode mode, TargetPlatform platform) { ... }

Finally there are some artifacts that require a build mode but not a host platform, since that platform is somewhat implied:

enum DontKnowWhatToCalllYouArtifacts {
  linuxDesktopWrapper,
  windowsDesktopWrapper,
}

This would us to make all of the required arguments appropriately non-nullable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: tech-debtTechnical debt, code quality, testing, etc.team-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions