5
5
#include " flutter/impeller/compiler/switches.h"
6
6
7
7
#include < filesystem>
8
+ #include < map>
8
9
9
10
#include " flutter/fml/file.h"
10
11
11
12
namespace impeller {
12
13
namespace compiler {
13
14
15
+ static const std::map<std::string, Compiler::TargetPlatform> kKnownPlatforms = {
16
+ {" macos" , Compiler::TargetPlatform::kMacOS },
17
+ {" ios" , Compiler::TargetPlatform::kIPhoneOS },
18
+ };
19
+
14
20
void Switches::PrintHelp (std::ostream& stream) {
15
21
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;
16
27
stream << " --input=<glsl_file>" << std::endl;
17
28
stream << " --metal=<metal_output_file>" << std::endl;
18
29
stream << " --spirv=<spirv_output_file>" << std::endl;
@@ -28,8 +39,27 @@ Switches::Switches() = default;
28
39
29
40
Switches::~Switches () = default ;
30
41
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
+
31
60
Switches::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>(
33
63
fml::OpenDirectory (std::filesystem::current_path().native().c_str(),
34
64
false, // create if necessary,
35
65
fml::FilePermission::kRead))),
@@ -67,6 +97,11 @@ Switches::Switches(const fml::CommandLine& command_line)
67
97
68
98
bool Switches::AreValid (std::ostream& explain) const {
69
99
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
+
70
105
if (!working_directory || !working_directory->is_valid ()) {
71
106
explain << " Could not figure out working directory." << std::endl;
72
107
valid = false ;
0 commit comments