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 sz build_runner build command #997

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'dart:async';

import 'package:sz_repo_cli/src/common/common.dart';

class BuildRunnerBuild extends ConcurrentCommand {
BuildRunnerBuild(SharezoneRepo repo) : super(repo) {
argParser.addFlag(
'delete-conflicting-outputs',
help:
'By default, the user will be prompted to delete any files which already exist but were not known to be generated by this specific build script.',
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if promoting the options works with our CLI. Maybe we should always use the --delete-conflicting-outputs flag because I think this is the option to always use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

promoting the options works with our CLI

I don't know what do you mean exactly. Does that mean that you are unsure if we as developers would notice having that flag for the command?

I'm okay with defaulting it with true, since like you said that's the option we're always using anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

Normally, when there is a conflict, the CLI prompts three options. You can then press key 1, 2 or 3.

[INFO] Found 25 declared outputs which already exist on disk. This is likely because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository.
Delete these files?
1 - Delete
2 - Cancel build
3 - List conflicts

However, because we don't show the prints from the Dart CLI, you will not see this message and you can't press any of these options.

Therefore, I would also hard-code --delete-conflicting-outputs to true because as a Sharezone Repo CLI user can't do anything else and wouldn't make sense to set --delete-conflicting-outputs to false.

aliases: ['d'],
defaultsTo: false,
negatable: false,
);
}

@override
final String name = 'build';

@override
final String description =
'Performs a single build on the specified targets and then exits.';

@override
int get defaultMaxConcurrency => 5;

@override
Duration get defaultPackageTimeout => const Duration(minutes: 10);

@override
Stream<Package> get packagesToProcess {
return repo
.streamPackages()
.where((package) => package.hasBuildRunnerDependency);
}

@override
Future<void> runTaskForPackage(Package package) async {
await runProcessSucessfullyOrThrow(
'fvm',
[
'dart',
'run',
'build_runner',
'build',
'--delete-conflicting-outputs',
'${argResults!['delete-conflicting-outputs'] as bool}',
],
workingDirectory: package.path,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:args/command_runner.dart';

class BuildRunnerCommand extends Command {
@override
String get description =>
'Runs "dart run build_runner" for every package that contains build_runner as a dependency.';

@override
String get name => 'build_runner';
}
6 changes: 6 additions & 0 deletions tools/sz_repo_cli/lib/src/common/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Package {
bool get isPureDartPackage => type == PackageType.pureDart;
final bool hasTestDirectory;
final bool hasGoldenTestsDirectory;
final bool hasBuildRunnerDependency;

Package({
required this.location,
Expand All @@ -38,6 +39,7 @@ class Package {
required this.hasTestDirectory,
required this.hasGoldenTestsDirectory,
required this.version,
required this.hasBuildRunnerDependency,
});

factory Package.fromDirectory(Directory directory) {
Expand All @@ -60,13 +62,17 @@ class Package {
final hasTestGoldensDirectory =
Directory(p.join(directory.path, 'test_goldens')).existsSync();

final hasBuildRunnerDependency = dependencies.containsKey('build_runner') ||
devDependencies.containsKey('build_runner');

return Package(
location: directory,
name: name,
hasTestDirectory: hasTestDirectory,
hasGoldenTestsDirectory: hasTestGoldensDirectory,
type: containsFlutter ? PackageType.flutter : PackageType.pureDart,
version: version,
hasBuildRunnerDependency: hasBuildRunnerDependency,
);
}

Expand Down
5 changes: 4 additions & 1 deletion tools/sz_repo_cli/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import 'package:sz_repo_cli/src/commands/src/build_android_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_ios_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_macos_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_runner_build_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_runner_command.dart';
import 'package:sz_repo_cli/src/commands/src/build_web_command.dart';
import 'package:sz_repo_cli/src/commands/src/check_license_headers_command.dart';
import 'package:sz_repo_cli/src/commands/src/deploy_android_command.dart';
Expand Down Expand Up @@ -59,7 +61,8 @@ Future<void> main(List<String> args) async {
..addSubcommand(BuildAndroidCommand(repo))
..addSubcommand(BuildMacOsCommand(repo))
..addSubcommand(BuildWebCommand(repo))
..addSubcommand(BuildIosCommand(repo)));
..addSubcommand(BuildIosCommand(repo)))
..addCommand(BuildRunnerCommand()..addSubcommand(BuildRunnerBuild(repo)));

await commandRunner.run(args).catchError((Object e) {
final toolExit = e as ToolExit;
Expand Down
1 change: 1 addition & 0 deletions tools/sz_repo_cli/test/common/build_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void main() {
hasTestDirectory: false,
hasGoldenTestsDirectory: false,
version: version,
hasBuildRunnerDependency: false,
);
}

Expand Down