55#include " flutter/impeller/compiler/switches.h"
66
77#include < filesystem>
8+ #include < map>
89
910#include " flutter/fml/file.h"
1011
1112namespace impeller {
1213namespace compiler {
1314
15+ static const std::map<std::string, Compiler::TargetPlatform> kKnownPlatforms = {
16+ {" macos" , Compiler::TargetPlatform::kMacOS },
17+ {" ios" , Compiler::TargetPlatform::kIPhoneOS },
18+ };
19+
1420void Switches::PrintHelp (std::ostream& stream) {
1521 stream << std::endl << " Valid Argument are:" << std::endl;
22+ stream << " One of [" ;
23+ for (const auto & platform : kKnownPlatforms ) {
24+ stream << " --" << platform.first ;
25+ }
26+ stream << " ]" << std::endl;
1627 stream << " --input=<glsl_file>" << std::endl;
1728 stream << " --metal=<metal_output_file>" << std::endl;
1829 stream << " --spirv=<spirv_output_file>" << std::endl;
@@ -28,8 +39,27 @@ Switches::Switches() = default;
2839
2940Switches::~Switches () = default ;
3041
42+ static Compiler::TargetPlatform TargetPlatformFromCommandLine (
43+ const fml::CommandLine& command_line) {
44+ auto target = Compiler::TargetPlatform::kUnknown ;
45+ for (const auto & platform : kKnownPlatforms ) {
46+ if (command_line.HasOption (platform.first )) {
47+ // If the platform has already been determined, the caller may have
48+ // specified multiple platforms. This is an error and only one must be
49+ // selected.
50+ if (target != Compiler::TargetPlatform::kUnknown ) {
51+ return Compiler::TargetPlatform::kUnknown ;
52+ }
53+ target = platform.second ;
54+ // Keep going to detect duplicates.
55+ }
56+ }
57+ return target;
58+ }
59+
3160Switches::Switches (const fml::CommandLine& command_line)
32- : working_directory(std::make_shared<fml::UniqueFD>(
61+ : target_platform(TargetPlatformFromCommandLine(command_line)),
62+ working_directory (std::make_shared<fml::UniqueFD>(
3363 fml::OpenDirectory (std::filesystem::current_path().native().c_str(),
3464 false, // create if necessary,
3565 fml::FilePermission::kRead))),
@@ -67,6 +97,11 @@ Switches::Switches(const fml::CommandLine& command_line)
6797
6898bool Switches::AreValid (std::ostream& explain) const {
6999 bool valid = true ;
100+ if (target_platform == Compiler::TargetPlatform::kUnknown ) {
101+ explain << " The target platform (only one) was not specified." << std::endl;
102+ valid = false ;
103+ }
104+
70105 if (!working_directory || !working_directory->is_valid ()) {
71106 explain << " Could not figure out working directory." << std::endl;
72107 valid = false ;
0 commit comments