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 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
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,
);
}
}
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