Skip to content

Commit 777d377

Browse files
Albert221flutter-zl
authored andcommitted
Look for project root for FeatureFlags manifest (flutter#180689)
Fixes flutter#176294. The `FeatureFlags` service is now instantiated with the manifest parsed not from `<current working directory>/pubspec.yaml`, but from `findProjectRoot(cwd)` (falling back to old behavior). ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **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 [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 7e57b68 commit 777d377

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎packages/flutter_tools/lib/src/context_runner.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ Future<T> runInContext<T>(FutureOr<T> Function() runner, {Map<Type, Generator>?
224224
globalConfig: globals.config,
225225
platform: globals.platform,
226226
projectManifest: FlutterManifest.createFromPath(
227-
globals.fs.path.join(globals.fs.currentDirectory.path, 'pubspec.yaml'),
227+
globals.fs.path.join(
228+
findProjectRoot(globals.fs) ?? globals.fs.currentDirectory.path,
229+
'pubspec.yaml',
230+
),
228231
fileSystem: globals.fs,
229232
logger: globals.logger,
230233
),

‎packages/flutter_tools/test/general.shard/features_test.dart‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,55 @@ void main() {
125125
},
126126
);
127127

128+
FileSystem createFsWithPubspecInParentDir() {
129+
final FileSystem fs = MemoryFileSystem.test();
130+
// Create pubspec.yaml in the root directory
131+
fs.currentDirectory.childFile('pubspec.yaml').writeAsStringSync('''
132+
flutter:
133+
config:
134+
enable-foo: true
135+
enable-bar: false
136+
''');
137+
// Create a subdirectory and set it as the current directory
138+
final Directory subdir = fs.currentDirectory.childDirectory('lib').childDirectory('src');
139+
subdir.createSync(recursive: true);
140+
fs.currentDirectory = subdir;
141+
return fs;
142+
}
143+
144+
testUsingContext(
145+
'FeatureFlags finds pubspec.yaml in parent directory when CWD is a subdirectory',
146+
() {
147+
// This test verifies that findProjectRoot is used to locate pubspec.yaml
148+
// even when the current directory is a subdirectory of the project.
149+
final FeatureFlags featureFlagsFromContext = featureFlags;
150+
151+
expect(
152+
featureFlagsFromContext.isEnabled(
153+
const Feature(
154+
name: 'foo',
155+
configSetting: 'enable-foo',
156+
master: FeatureChannelSetting(available: true),
157+
),
158+
),
159+
isTrue,
160+
reason: 'enable-foo: true should be found in pubspec.yaml in parent directory',
161+
);
162+
163+
expect(
164+
featureFlagsFromContext.isEnabled(
165+
const Feature.fullyEnabled(name: 'bar', configSetting: 'enable-bar'),
166+
),
167+
isFalse,
168+
reason: 'enable-bar: false should be found in pubspec.yaml in parent directory',
169+
);
170+
},
171+
overrides: <Type, Generator>{
172+
ProcessManager: FakeProcessManager.empty,
173+
FileSystem: createFsWithPubspecInParentDir,
174+
},
175+
);
176+
128177
testUsingContext('Test feature flags match feature flags', () {
129178
final FeatureFlags testFeatureFlags = TestFeatureFlags();
130179

0 commit comments

Comments
 (0)