@@ -51,6 +51,7 @@ constexpr char kAssetsKey[] = "assets";
5151// "args" are how the component specifies arguments to the runner.
5252constexpr char kArgsKey [] = " args" ;
5353constexpr char kOldGenHeapSizeKey [] = " old_gen_heap_size" ;
54+ constexpr char kExposeDirsKey [] = " expose_dirs" ;
5455
5556constexpr char kTmpPath [] = " /tmp" ;
5657constexpr char kServiceRootPath [] = " /svc" ;
@@ -88,6 +89,18 @@ void ParseArgs(std::vector<std::string>& args, ProgramMetadata* metadata) {
8889 << old_gen_heap_size_option;
8990 }
9091 }
92+
93+ std::string expose_dirs_option;
94+ if (parsed_args.GetOptionValue (kExposeDirsKey , &expose_dirs_option)) {
95+ // Parse the comma delimited string
96+ std::vector<std::string> expose_dirs;
97+ std::stringstream s (expose_dirs_option);
98+ while (s.good ()) {
99+ std::string dir;
100+ getline (s, dir, ' ,' ); // get first string delimited by comma
101+ metadata->expose_dirs .push_back (dir);
102+ }
103+ }
91104}
92105
93106} // namespace
@@ -258,32 +271,41 @@ ComponentV2::ComponentV2(
258271 fuchsia::io::OPEN_RIGHT_WRITABLE,
259272 cloned_directory_ptr_.NewRequest ());
260273
261- cloned_directory_ptr_.events ().OnOpen =
262- [this ](zx_status_t status, std::unique_ptr<fuchsia::io::NodeInfo> info) {
263- cloned_directory_ptr_.Unbind ();
264- if (status != ZX_OK) {
265- FML_LOG (ERROR)
266- << " could not bind out directory for flutter component("
267- << debug_label_ << " ): " << zx_status_get_string (status);
268- return ;
269- }
270- const char * other_dirs[] = {" debug" , " ctrl" , " diagnostics" };
271- // add other directories as RemoteDirs.
272- for (auto & dir_str : other_dirs) {
273- fuchsia::io::DirectoryHandle dir;
274- auto request = dir.NewRequest ().TakeChannel ();
275- auto status = fdio_service_connect_at (directory_ptr_.channel ().get (),
276- dir_str, request.release ());
277- if (status == ZX_OK) {
278- outgoing_dir_->AddEntry (
279- dir_str, std::make_unique<vfs::RemoteDir>(dir.TakeChannel ()));
280- } else {
281- FML_LOG (ERROR) << " could not add out directory entry(" << dir_str
282- << " ) for flutter component(" << debug_label_
283- << " ): " << zx_status_get_string (status);
284- }
285- }
286- };
274+ // Collect our standard set of directories along with directories that are
275+ // included in the cml file to expose.
276+ std::vector<std::string> other_dirs = {" debug" , " ctrl" , " diagnostics" };
277+ for (auto dir : metadata.expose_dirs ) {
278+ other_dirs.push_back (dir);
279+ }
280+
281+ cloned_directory_ptr_.events ()
282+ .OnOpen = [this , other_dirs](
283+ zx_status_t status,
284+ std::unique_ptr<fuchsia::io::NodeInfo> info) {
285+ cloned_directory_ptr_.Unbind ();
286+ if (status != ZX_OK) {
287+ FML_LOG (ERROR) << " could not bind out directory for flutter component("
288+ << debug_label_ << " ): " << zx_status_get_string (status);
289+ return ;
290+ }
291+
292+ // add other directories as RemoteDirs.
293+ for (auto & dir_str : other_dirs) {
294+ fuchsia::io::DirectoryHandle dir;
295+ auto request = dir.NewRequest ().TakeChannel ();
296+ auto status = fdio_service_connect_at (directory_ptr_.channel ().get (),
297+ dir_str.c_str (), request.release ());
298+ if (status == ZX_OK) {
299+ outgoing_dir_->AddEntry (
300+ dir_str.c_str (),
301+ std::make_unique<vfs::RemoteDir>(dir.TakeChannel ()));
302+ } else {
303+ FML_LOG (ERROR) << " could not add out directory entry(" << dir_str
304+ << " ) for flutter component(" << debug_label_
305+ << " ): " << zx_status_get_string (status);
306+ }
307+ }
308+ };
287309
288310 cloned_directory_ptr_.set_error_handler (
289311 [this ](zx_status_t status) { cloned_directory_ptr_.Unbind (); });
0 commit comments