Unverified Commit 17ec3b1d authored by Elias Yishak's avatar Elias Yishak Committed by GitHub

[flutter_tools] Introducing arg option for specifying the output directory for web (#113076)

parent 61deaef5
......@@ -37,6 +37,7 @@ class BuildAarCommand extends BuildSubCommand {
addTreeShakeIconsFlag();
usesFlavorOption();
usesBuildNumberOption();
usesOutputDir();
usesPubOption();
addSplitDebugInfoOption();
addDartObfuscationOption();
......@@ -47,16 +48,11 @@ class BuildAarCommand extends BuildSubCommand {
addEnableExperimentation(hide: !verboseHelp);
addAndroidSpecificBuildOptions(hide: !verboseHelp);
argParser
..addMultiOption(
.addMultiOption(
'target-platform',
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'],
help: 'The target platform for which the project is compiled.',
)
..addOption(
'output-dir',
help: 'The absolute path to the directory where the repository is generated. '
'By default, this is "<current-directory>android/build".',
);
}
......@@ -142,7 +138,7 @@ class BuildAarCommand extends BuildSubCommand {
project: _getProject(),
target: targetFile.path,
androidBuildInfo: androidBuildInfo,
outputDirectoryPath: stringArgDeprecated('output-dir'),
outputDirectoryPath: stringArg('output'),
buildNumber: buildNumber,
);
return FlutterCommandResult.success();
......
......@@ -19,6 +19,7 @@ class BuildWebCommand extends BuildSubCommand {
}) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(enabledByDefault: false);
usesTargetOption();
usesOutputDir();
usesPubOption();
usesBuildNumberOption();
usesBuildNameOption();
......@@ -113,6 +114,11 @@ class BuildWebCommand extends BuildSubCommand {
r'Please add `<base href="$FLUTTER_BASE_HREF">` to web/index.html'
);
}
// Currently supporting options [output-dir] and [output] as
// valid approaches for setting output directory of build artifacts
final String? outputDirectoryPath = stringArg('output');
displayNullSafetyMode(buildInfo);
await buildWeb(
flutterProject,
......@@ -124,6 +130,7 @@ class BuildWebCommand extends BuildSubCommand {
boolArgDeprecated('native-null-assertions'),
baseHref,
stringArgDeprecated('dart2js-optimization'),
outputDirectoryPath: outputDirectoryPath,
);
return FlutterCommandResult.success();
}
......
......@@ -392,6 +392,19 @@ abstract class FlutterCommand extends Command<void> {
_usesPortOption = true;
}
/// Add option values for output directory of artifacts
void usesOutputDir() {
// TODO(eliasyishak): this feature has been added to [BuildWebCommand] and
// [BuildAarCommand]
argParser.addOption('output',
abbr: 'o',
aliases: <String>['output-dir'],
help:
'The absolute path to the directory where the repository is generated. '
'By default, this is <current-directory>/build/<target-platform>.\n'
'Currently supported for subcommands: aar, web.');
}
void addDevToolsOptions({required bool verboseHelp}) {
argParser.addFlag(
kEnableDevTools,
......
......@@ -28,10 +28,13 @@ Future<void> buildWeb(
bool nativeNullAssertions,
String? baseHref,
String? dart2jsOptimization,
{String? outputDirectoryPath}
) async {
final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
final Directory outputDirectory = globals.fs.directory(getWebBuildDirectory());
final Directory outputDirectory = outputDirectoryPath == null
? globals.fs.directory(getWebBuildDirectory())
: globals.fs.directory(outputDirectoryPath);
outputDirectory.createSync(recursive: true);
// The migrators to apply to a Web project.
......
......@@ -84,7 +84,7 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Builds a web bundle - end to end', () async {
testUsingContext('Setup for a web build with default output directory', () async {
final BuildCommand buildCommand = BuildCommand();
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
......@@ -116,6 +116,48 @@ void main() {
}),
});
testUsingContext('Setup for a web build with a user specified output directory',
() async {
final BuildCommand buildCommand = BuildCommand();
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
const String newBuildDir = 'new_dir';
final Directory buildDir = fileSystem.directory(fileSystem.path.join(newBuildDir));
expect(buildDir.existsSync(), false);
await runner.run(<String>[
'build',
'web',
'--no-pub',
'--output=$newBuildDir'
]);
expect(buildDir.existsSync(), true);
}, overrides: <Type, Generator>{
Platform: () => fakePlatform,
FileSystem: () => fileSystem,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => FakeProcessManager.any(),
BuildSystem: () => TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
expect(environment.defines, <String, String>{
'TargetFile': 'lib/main.dart',
'HasWebPlugins': 'true',
'cspMode': 'false',
'SourceMaps': 'false',
'NativeNullAssertions': 'true',
'ServiceWorkerStrategy': 'offline-first',
'BuildMode': 'release',
'DartDefines': 'RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==',
'DartObfuscation': 'false',
'TrackWidgetCreation': 'false',
'TreeShakeIcons': 'false',
});
}),
});
testUsingContext('hidden if feature flag is not enabled', () async {
expect(BuildWebCommand(verboseHelp: false).hidden, true);
}, overrides: <Type, Generator>{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment