Skip to content

Commit 0feeeab

Browse files
authored
Move examples/api to packages/flutter/examples/api and fix CI errors (flutter#190481)
This PR moves API examples from `<root>/examples/api` to `<root>/packages/flutter/examples/api`. This change is required because the standard dartdoc directive `{@example}` requires API examples to reside within the package directory. For more details, see issue flutter#189629 (item 1 under "What's needed"). ### Summary of changes Moved all API example files to `packages/flutter/examples/api`. Updated related scripts and CI configurations to reflect the new directory structure. - Most changes involve simple path updates from `examples/api` to `packages/flutter/examples/api`. - Some adjustments were more complex because the examples, which previously resided in a single `<root>/examples` directory, are now split across two separate locations. Existing paths in `"See code in "` directives are retained. These paths are now treated as relative to the package root rather than the repository root. For example, the following API doc comment remains valid despite the file move: ```dart /// Class definition. /// /// {@tool sample} /// An example. /// /// ** See code in examples/api/lib/widgets/foo/foo.0.dart ** /// {@end-tool} ``` Three API doc tests are now marked as `reduced-test-set` because they're now facing additional analysis for being under `packages/flutter`. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent dba040a commit 0feeeab

1,239 files changed

Lines changed: 761 additions & 647 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/labeler.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'd: api docs':
5151
- changed-files:
5252
- any-glob-to-any-file:
53-
- examples/api/**/*
53+
- packages/flutter/examples/api/**/*
5454

5555
'd: docs/':
5656
- changed-files:
@@ -61,6 +61,7 @@
6161
- changed-files:
6262
- any-glob-to-any-file:
6363
- examples/**/*
64+
- packages/flutter/examples/**/*
6465

6566
'e: embedder':
6667
- changed-files:
@@ -138,7 +139,6 @@ framework:
138139
- packages/flutter_localizations/**/*
139140
- packages/flutter_test/**/*
140141
- packages/integration_test/**/*
141-
- examples/api/**/*
142142
- docs/about/**/*
143143
- docs/contributing/**/*
144144
- docs/libraries/**/*

‎.github/workflows/freeze.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ jobs:
3232
token: ${{ github.token }}
3333
filters: |
3434
frozen:
35+
- 'packages/flutter/examples/api/lib/material/**'
36+
- 'packages/flutter/examples/api/lib/cupertino/**'
37+
- 'packages/flutter/examples/api/test/material/**'
38+
- 'packages/flutter/examples/api/test/cupertino/**'
3539
- 'packages/flutter/lib/src/material/**'
3640
- 'packages/flutter/lib/src/cupertino/**'
3741
- 'packages/flutter/test/material/**'
3842
- 'packages/flutter/test/cupertino/**'
39-
- 'examples/api/lib/material/**'
40-
- 'examples/api/lib/cupertino/**'
41-
- 'examples/api/test/material/**'
42-
- 'examples/api/test/cupertino/**'
4343
- 'packages/flutter/lib/fix_data/fix_cupertino.yaml'
4444
- 'packages/flutter/lib/fix_data/fix_material/**'
4545
- 'packages/flutter/test_fixes/material/**'

‎dev/bots/analyze.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ List<Validation> _getValidations({
225225
),
226226
Validation('no-sync-star-async-star', 'No sync*/async*', () async {
227227
await verifyNoSyncAsyncStar(flutterPackages);
228-
await verifyNoSyncAsyncStar(flutterExamples, minimumMatches: 200);
228+
await verifyNoSyncAsyncStar(flutterExamples, minimumMatches: 80);
229229
}),
230230
Validation(
231231
'no-runtime-type',

‎dev/bots/analyze_snippet_code.dart‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
// In general, please prefer using full linked examples in API docs.
99
//
10-
// For documentation on creating sample code, see ../../examples/api/README.md
11-
// See also our style guide's discussion on documentation and sample code:
10+
// For documentation on creating sample code, see
11+
// ../../packages/flutter/examples/api/README.md See also our style guide's
12+
// discussion on documentation and sample code:
1213
// https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
1314
//
1415
// This tool is used to analyze smaller snippets of code in the API docs.
@@ -1008,13 +1009,13 @@ class _SnippetChecker {
10081009

10091010
_copyPubspec(
10101011
path.join(_contentDirectory.path, _pubspecName),
1011-
path.join(_flutterRoot, 'examples', 'api', _pubspecName),
1012+
path.join(_flutterRoot, 'packages', 'flutter', 'examples', 'api', _pubspecName),
10121013
);
10131014
final targetAnalysisOptions = File(path.join(_contentDirectory.path, 'analysis_options.yaml'));
10141015
if (!targetAnalysisOptions.existsSync()) {
1015-
// Use the same analysis_options.yaml configuration that's used for examples/api.
1016+
// Use the same analysis_options.yaml configuration that's used for packages/flutter/examples/api.
10161017
final sourceAnalysisOptions = File(
1017-
path.join(_flutterRoot, 'examples', 'api', 'analysis_options.yaml'),
1018+
path.join(_flutterRoot, 'packages', 'flutter', 'examples', 'api', 'analysis_options.yaml'),
10181019
);
10191020
if (!sourceAnalysisOptions.existsSync()) {
10201021
throw 'Cannot find analysis_options.yaml at ${sourceAnalysisOptions.path}, which is also used to analyze code snippets.';
@@ -1028,7 +1029,7 @@ class _SnippetChecker {
10281029
void _copyPubspec(String targetPath, String sourcePath) {
10291030
final targetPubSpec = File(targetPath);
10301031
if (!targetPubSpec.existsSync()) {
1031-
// Copying pubspec.yaml from examples/api into temp directory.
1032+
// Copying pubspec.yaml from packages/flutter/examples/api into temp directory.
10321033
final sourcePubSpec = File(sourcePath);
10331034
if (!sourcePubSpec.existsSync()) {
10341035
throw 'Cannot find pubspec.yaml at ${sourcePubSpec.path}, which is also used to analyze code snippets.';

‎dev/bots/check_code_samples.dart‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import 'utils.dart';
1616

1717
final String _scriptLocation = path.fromUri(Platform.script);
1818
final String _flutterRoot = path.dirname(path.dirname(path.dirname(_scriptLocation)));
19-
final String _exampleDirectoryPath = path.join(_flutterRoot, 'examples', 'api');
19+
final String _exampleDirectoryPath = path.join(
20+
_flutterRoot,
21+
'packages',
22+
'flutter',
23+
'examples',
24+
'api',
25+
);
2026
final String _packageDirectoryPath = path.join(_flutterRoot, 'packages');
2127
final String _dartUIDirectoryPath = path.join(
2228
_flutterRoot,
@@ -128,6 +134,10 @@ class SampleChecker {
128134
final Directory flutterRoot;
129135
final FileSystem filesystem;
130136

137+
// The `exampleBase` is where the paths in "See code in" are relative to.
138+
// Defaults to <flutter_root>/packages/flutter.
139+
Directory get exampleBase => examples.parent.parent;
140+
131141
bool checkCodeSamples() {
132142
filesystem.currentDirectory = flutterRoot;
133143

@@ -258,7 +268,7 @@ class SampleChecker {
258268
List<String> checkForMissingLinks(List<File> exampleFilenames, Set<String> searchStrings) {
259269
final missingFilenames = <String>[];
260270
for (final example in exampleFilenames) {
261-
final String relativePath = getRelativePath(example);
271+
final String relativePath = getRelativePath(example, exampleBase);
262272
if (!searchStrings.contains(relativePath)) {
263273
missingFilenames.add(relativePath);
264274
}

0 commit comments

Comments
 (0)