@@ -579,13 +579,15 @@ static const std::vector<std::string> LD_GOLD_OPTIONS = {
579
579
" -relocatable"
580
580
};
581
581
582
- static std::vector<std::string> getLinkActionsForRootLibrary (
583
- fs::path const &workingDir, std::vector<fs::path> const &dependencies, fs::path const &output) {
582
+ static std::vector<std::string>
583
+ getLinkActionsForRootLibrary (fs::path const &workingDir,
584
+ std::vector<fs::path> const &dependencies,
585
+ fs::path const &rootOutput) {
584
586
std::vector<std::string> commandLine = LD_GOLD_OPTIONS;
585
587
commandLine.emplace_back (" --whole-archive" );
586
588
CollectionUtils::extend (
587
589
commandLine,
588
- std::vector<std::string>{ StringUtils::joinWith (dependencies, " " ), " -o" , output });
590
+ std::vector<std::string>{ StringUtils::joinWith (dependencies, " " ), " -o" , rootOutput });
589
591
utbot::LinkCommand linkAction{ commandLine, workingDir };
590
592
return { linkAction.toStringWithChangingDirectory () };
591
593
};
@@ -699,31 +701,34 @@ Linker::getLinkActionsForExecutable(fs::path const &workingDir,
699
701
return commands;
700
702
}
701
703
702
- void Linker::declareRootLibraryTarget (printer::DefaultMakefilePrinter &bitcodeLinkMakefilePrinter,
703
- const fs::path &output ,
704
- const vector< fs::path> &bitcodeDependencies ,
705
- const fs::path &prefixPath ,
706
- const utbot::RunCommand &removeAction ,
707
- vector<utbot::LinkCommand> archiveActions) {
708
- fs::path temporaryOutput = Paths::addSuffix (output, " _tmp " );
709
- utbot::RunCommand removeTemporaryAction =
710
- utbot::RunCommand::forceRemoveFile (temporaryOutput , testGen.serverBuildDir );
711
- std::vector<std::string> actions{ removeTemporaryAction .toStringWithChangingDirectory () };
704
+ fs::path
705
+ Linker::declareRootLibraryTarget (printer::DefaultMakefilePrinter &bitcodeLinkMakefilePrinter ,
706
+ const fs::path &output ,
707
+ const vector< fs::path> &bitcodeDependencies ,
708
+ const fs::path &prefixPath ,
709
+ vector<utbot::LinkCommand> archiveActions) {
710
+ fs::path rootOutput = Paths::addSuffix (output, " _root " );
711
+ utbot::RunCommand removeAction =
712
+ utbot::RunCommand::forceRemoveFile (output , testGen.serverBuildDir );
713
+ std::vector<std::string> actions{ removeAction .toStringWithChangingDirectory () };
712
714
for (auto &archiveAction : archiveActions) {
713
- archiveAction.setOutput (temporaryOutput );
715
+ archiveAction.setOutput (output );
714
716
}
715
717
CollectionUtils::extend (
716
718
actions, CollectionUtils::transform (
717
719
archiveActions, std::bind (&utbot::LinkCommand::toStringWithChangingDirectory,
718
720
std::placeholders::_1)));
719
- bitcodeLinkMakefilePrinter.declareTarget (temporaryOutput , bitcodeDependencies, actions);
721
+ bitcodeLinkMakefilePrinter.declareTarget (output , bitcodeDependencies, actions);
720
722
721
723
auto linkActions =
722
- getLinkActionsForRootLibrary (prefixPath, { temporaryOutput, STUB_BITCODE_FILES }, output);
723
- linkActions.insert (linkActions.begin (), removeAction.toStringWithChangingDirectory ());
724
- bitcodeLinkMakefilePrinter.declareTarget (output, { temporaryOutput, STUB_BITCODE_FILES },
724
+ getLinkActionsForRootLibrary (prefixPath, { output, STUB_BITCODE_FILES }, rootOutput);
725
+ utbot::RunCommand removeRootAction =
726
+ utbot::RunCommand::forceRemoveFile (rootOutput, testGen.serverBuildDir );
727
+ linkActions.insert (linkActions.begin (), removeRootAction.toStringWithChangingDirectory ());
728
+ bitcodeLinkMakefilePrinter.declareTarget (rootOutput, { output, STUB_BITCODE_FILES },
725
729
linkActions);
726
- bitcodeLinkMakefilePrinter.declareTarget (" all" , { output }, {});
730
+ bitcodeLinkMakefilePrinter.declareTarget (" all" , { rootOutput }, {});
731
+ return rootOutput;
727
732
}
728
733
729
734
@@ -769,14 +774,15 @@ Linker::addLinkTargetRecursively(const fs::path &fileToBuild,
769
774
auto output = testGen.buildDatabase ->getBitcodeFile (fileToBuild);
770
775
output = LinkerUtils::applySuffix (output, unitType, suffixForParentOfStubs);
771
776
if (Paths::isLibraryFile (fileToBuild)) {
772
- utbot::RunCommand removeAction =
773
- utbot::RunCommand::forceRemoveFile (output, testGen.serverBuildDir );
774
777
auto archiveActions = getArchiveCommands (prefixPath, dependencies, *linkUnit, output);
775
778
if (!hasParent) {
776
- declareRootLibraryTarget (bitcodeLinkMakefilePrinter, output, bitcodeDependencies,
777
- prefixPath, removeAction, archiveActions);
778
-
779
+ fs::path rootBitcode =
780
+ declareRootLibraryTarget (bitcodeLinkMakefilePrinter, output,
781
+ bitcodeDependencies, prefixPath, archiveActions);
782
+ return { rootBitcode, BuildResult::Type::NONE };
779
783
} else {
784
+ utbot::RunCommand removeAction =
785
+ utbot::RunCommand::forceRemoveFile (output, testGen.serverBuildDir );
780
786
std::vector<std::string> actions = { removeAction.toStringWithChangingDirectory () };
781
787
CollectionUtils::extend (
782
788
actions,
0 commit comments