Skip to content

Commit

Permalink
Add sz build_runner build command (#997)
Browse files Browse the repository at this point in the history
Needed for #963

Usage:

```
$ sz build_runner
Missing subcommand for "pub global run sz_repo_cli build_runner".

Usage: pub global run sz_repo_cli build_runner <subcommand> [arguments]
-h, --help    Print this usage information.

Available subcommands:
  build   Performs a single build on the specified targets and then exits.

Run "pub global run sz_repo_cli help" to see global options.
```

```
$ sz build_runner build
holidays ⚙ Running
abgabe_http_api ⚙ Running
sharezone ⚙ Running
abgabe_http_api ✅
holidays ✅
sharezone ✅
Task was successfully executed for all packages!
```
  • Loading branch information
nilsreichardt authored Sep 18, 2023
1 parent a2f2631 commit 9c6a3c4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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);

@override
final String name = 'build';

@override
final String description =
'Performs a single build on the specified targets and then exits. Uses the "--delete-conflicting-outputs" flag';

@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',
// We use the "--delete-conflicting-outputs" flag, because we want to
// delete the conflicting outputs.
//
// Normally, the Dart CLI shows three options when there is a conflict:
// delete (1), cancel build (2) or list conflicts (3). But since we
// don't show the output of the `dart run build_runner` command, the
// user has no way to choose between these options.
//
// Therefore, we hard code it to delete the conflicting outputs.
'--delete-conflicting-outputs',
],
workingDirectory: package.path,
);
}
}
18 changes: 18 additions & 0 deletions tools/sz_repo_cli/lib/src/commands/src/build_runner_command.dart
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

0 comments on commit 9c6a3c4

Please sign in to comment.