Skip to content

Commit e30750c

Browse files
committed
Look for project root for FeatureFlags manifest
Fixes flutter#176294.
1 parent 93cba59 commit e30750c

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)