Skip to content

fix: Notify build_runner of dependency on inputSpec #187

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions openapi-generator/lib/src/openapi_generator_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
: 'dart';

return generatorV2(
args: args,
baseCommand: baseCommand,
annotatedPath: buildStep.inputId.path);
args: args, baseCommand: baseCommand, buildStep: buildStep);
}
} catch (e, st) {
late OutputMessage communication;
Expand Down Expand Up @@ -178,7 +176,8 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
FutureOr<String> generatorV2(
{required GeneratorArguments args,
required String baseCommand,
required String annotatedPath}) async {
required BuildStep buildStep}) async {
final annotatedPath = buildStep.inputId.path;
if (args.isRemote) {
logOutputMessage(
log: log,
Expand All @@ -190,6 +189,16 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
);
}
try {
// Notify build_runner of dependency on inputSpec
if (args.inputSpec is! annots.RemoteSpec &&
!path.isAbsolute(args.inputSpec.path)) {
final maybeAssetId =
AssetId(buildStep.inputId.package, args.inputSpec.path);
// Check if asset can be read. If so, build_runner will mark the asset
// as a dependency and re-run the builder when it is modified.
await buildStep.canRead(maybeAssetId);
}

if (!await hasDiff(args: args) && args.skipIfSpecIsUnchanged) {
logOutputMessage(
log: log,
Expand Down