Add LICENSE test to presubmit checks (#28369)
## Description Also update the existing dart files with missing licenses. Without the fix, we'll emit the following error message ``` License headers cannot be found at the beginning of the following files. /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/lib/src/animation/tween_sequence.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/material/raw_material_button_test.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/widgets/async_lifecycle_test.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/widgets/sliver_constraints_test.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/widgets/app_test.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/widgets/test_border.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/widgets/physical_model_test.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter/test/widgets/inherited_model.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter_tools/lib/src/base/user_messages.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter_tools/test/src/pubspec_schema.dart /usr/local/google/home/liyuqian/flutter/flutter/packages/flutter_tools/test/ios/simulators_test.dart ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ``` ## Related Issues Fixes https://github.com/flutter/flutter/issues/28368 ## Checklist Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] My PR includes tests for *all* changed/updated/fixed behaviors (See [Test Coverage]). - [x] All existing and new tests are passing. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] The analyzer (`flutter analyze --flutter-repo`) does not report any problems on my PR. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I am willing to follow-up on review comments in a timely manner. ## Breaking Change Does your PR require Flutter developers to manually update their apps to accommodate your change? - [ ] Yes, this is a breaking change (Please read [Handling breaking changes]). - [x] No, this is *not* a breaking change. <!-- Links --> [issue database]: https://github.com/flutter/flutter/issues [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Test Coverage]: https://github.com/flutter/flutter/wiki/Test-coverage-for-package%3Aflutter [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [Handling breaking changes]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
This commit is contained in:
parent
6daad8d0eb
commit
dd5559a5b8
@ -30,6 +30,7 @@ Future<void> main(List<String> args) async {
|
||||
print('The analyze.dart script must be run with --enable-asserts.');
|
||||
exit(1);
|
||||
}
|
||||
await _verifyNoMissingLicense(flutterRoot);
|
||||
await _verifyNoTestImports(flutterRoot);
|
||||
await _verifyNoTestPackageImports(flutterRoot);
|
||||
await _verifyGeneratedPluginRegistrants(flutterRoot);
|
||||
@ -472,6 +473,30 @@ Future<void> _verifyNoBadImportsInFlutterTools(String workingDirectory) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _verifyNoMissingLicense(String workingDirectory) async {
|
||||
final List<String> errors = <String>[];
|
||||
for (FileSystemEntity entity in Directory(path.join(workingDirectory, 'packages'))
|
||||
.listSync(recursive: true)
|
||||
.where((FileSystemEntity entity) => entity is File && path.extension(entity.path) == '.dart')) {
|
||||
final File file = entity;
|
||||
bool hasLicense = false;
|
||||
final List<String> lines = file.readAsLinesSync();
|
||||
if (lines.isNotEmpty)
|
||||
hasLicense = lines.first.startsWith(RegExp(r'// Copyright \d{4}'));
|
||||
if (!hasLicense)
|
||||
errors.add(file.path);
|
||||
}
|
||||
// Fail if any errors
|
||||
if (errors.isNotEmpty) {
|
||||
print('$redLine');
|
||||
final String s = errors.length == 1 ? '' : 's';
|
||||
print('${bold}License headers cannot be found at the beginning of the following file$s.$reset\n');
|
||||
print(errors.join('\n'));
|
||||
print('$redLine\n');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
final RegExp _testImportPattern = RegExp(r'''import (['"])([^'"]+_test\.dart)\1''');
|
||||
const Set<String> _exemptTestImports = <String>{
|
||||
'package:flutter_test/flutter_test.dart',
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'animation.dart';
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import 'dart:ui';
|
||||
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef Logger = void Function(String caller);
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'context.dart';
|
||||
|
||||
UserMessages get userMessages => context[UserMessages];
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 201 The Chromium Authors. All rights reserved.
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' show ProcessResult, Process;
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/flutter_manifest.dart';
|
||||
|
Loading…
x
Reference in New Issue
Block a user