@@ -476,11 +476,11 @@ Commands SwBuild::getCommands() const
476476
477477 for (auto &[_, tgt] : latest_targets)
478478 {
479- // copy output files
479+ // gather targets to build
480480 const auto &s = tgt->getInterfaceSettings ();
481481
482- std::function<void (const TargetSettings &)> copy_file ;
483- copy_file = [this , ©_file , &ttb](const auto &s) mutable
482+ std::function<void (const TargetSettings &)> gather_ttb ;
483+ gather_ttb = [this , &gather_ttb , &ttb](const auto &s) mutable
484484 {
485485 if (s[" header_only" ] == " true" )
486486 return ;
@@ -489,7 +489,7 @@ Commands SwBuild::getCommands() const
489489 return ;
490490
491491 std::function<void (const TargetSettings &)> process_deps;
492- process_deps = [this , ©_file , &process_deps, &ttb](const auto &s) mutable
492+ process_deps = [this , &gather_ttb , &process_deps, &ttb](const auto &s) mutable
493493 {
494494 for (auto &[k, v] : s[" dependencies" ][" link" ].getSettings ())
495495 {
@@ -506,22 +506,24 @@ Commands SwBuild::getCommands() const
506506 ttb[PackageId (k)].push_back (*j);
507507
508508 const auto &s = (*j)->getInterfaceSettings ();
509- copy_file (s);
509+ gather_ttb (s);
510510 process_deps (s);
511511 }
512512 };
513513
514514 process_deps (s);
515515 };
516516
517- copy_file (s);
517+ gather_ttb (s);
518518 }
519519 }
520520
521521 //
522522 auto cl_show_output = build_settings[" show_output" ] == " true" ;
523523 auto cl_write_output_to_file = build_settings[" write_output_to_file" ] == " true" ;
524524 path copy_dir = build_settings[" build_ide_copy_to_dir" ].isValue () ? build_settings[" build_ide_copy_to_dir" ].getValue () : " " ;
525+ // bool copy_deps_of_local_pkgs = false;
526+ bool copy_deps_of_local_pkgs = copy_dir.empty ();
525527 std::unordered_map<path, path> copy_files;
526528
527529 Commands cmds;
@@ -543,14 +545,26 @@ Commands SwBuild::getCommands() const
543545 }
544546 cmds.insert (c.begin (), c.end ());
545547
546- if (copy_dir.empty ())
548+ if (copy_dir.empty () && !copy_deps_of_local_pkgs )
547549 continue ;
548550
549551 // copy output files
550552 const auto &s = tgt->getInterfaceSettings ();
551553
554+ if (copy_deps_of_local_pkgs)
555+ {
556+ if (p.getPath ().isAbsolute ())
557+ continue ;
558+ if (s[" header_only" ] == " true" )
559+ continue ;
560+ if (!(s[" type" ] == " native_shared_library" || s[" type" ] == " native_static_library" || s[" type" ] == " native_executable" ))
561+ continue ;
562+ copy_dir = path (s[" output_file" ].getValue ()).parent_path ();
563+ }
564+
565+ PackageIdSet visited_pkgs;
552566 std::function<void (const TargetSettings &)> copy_file;
553- copy_file = [this , &cmds, ©_dir, ©_files, ©_file](const auto &s)
567+ copy_file = [this , &cmds, ©_dir, ©_files, ©_file, &visited_pkgs ](const auto &s)
554568 {
555569 if (s[" header_only" ] == " true" )
556570 return ;
@@ -575,16 +589,22 @@ Commands SwBuild::getCommands() const
575589 o /= in.filename ();
576590 if (in == o)
577591 return ;
592+ if (copy_files.find (in) != copy_files.end ())
593+ return ;
578594 copy_files[in] = o;
579595 fast_path_files.insert (o);
580596 }
581597
582598 std::function<void (const TargetSettings &)> process_deps;
583- process_deps = [this , ©_file, &process_deps](const auto &s)
599+ process_deps = [this , ©_file, &process_deps, &visited_pkgs ](const auto &s)
584600 {
585601 for (auto &[k, v] : s[" dependencies" ][" link" ].getSettings ())
586602 {
587- auto i = getTargets ().find (PackageId (k));
603+ PackageId p (k);
604+ if (visited_pkgs.find (p) != visited_pkgs.end ())
605+ continue ;
606+ visited_pkgs.insert (p);
607+ auto i = getTargets ().find (p);
588608 if (i == getTargets ().end ())
589609 throw SW_RUNTIME_ERROR (" dep not found" );
590610 auto j = i->second .findSuitable (v.getSettings ());
0 commit comments