Skip to content

Commit a46a9ac

Browse files
committed
Better circular dependency handling on windows. Improve tests. Put produced executables into binary folder.
1 parent 1029676 commit a46a9ac

File tree

9 files changed

+70
-119
lines changed

9 files changed

+70
-119
lines changed

src/client/client.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,17 @@ void override_package_perform()
862862
}
863863
}
864864

865+
SUBCOMMAND_DECL(mirror)
866+
{
867+
enum storage_file_type
868+
{
869+
SourceArchive,
870+
SpecificationFirstFile,
871+
About,
872+
BuildArchive, // binary archive?
873+
};
874+
}
875+
865876
SUBCOMMAND_DECL(ide)
866877
{
867878
//useFileMonitor = false;

src/client/commands.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SUBCOMMAND(ide, "Used to invoke sw application to do IDE tasks: generate project
2626
SUBCOMMAND(create, "Create different projects.") COMMA
2727
SUBCOMMAND(install, "Add package to lock.") COMMA
2828
SUBCOMMAND(list, "List packages in database.") COMMA
29+
SUBCOMMAND(mirror, "Manage software mirrors.") COMMA
2930
SUBCOMMAND(pack, "Used to prepare distribution packages.") COMMA
3031
SUBCOMMAND(remote, "Manage remotes.") COMMA
3132
SUBCOMMAND(remove, "Remove package.") COMMA

src/driver/compiler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,9 @@ CompilerBaseProgram::CompilerBaseProgram(const CompilerBaseProgram &rhs)
10111011

10121012
std::shared_ptr<builder::Command> CompilerBaseProgram::getCommand() const
10131013
{
1014-
if (!cmd || !prepared)
1014+
if (!cmd)
1015+
throw SW_RUNTIME_ERROR("Command is not created");
1016+
if (!prepared)
10151017
throw SW_RUNTIME_ERROR("Command is not prepared");
10161018
return cmd;
10171019
}

src/driver/options_cl.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,17 @@ types:
471471
vslib:
472472
name: VisualStudioLibrarianOptions
473473

474+
flags:
475+
def:
476+
name: CreateImportLibrary
477+
type: bool
478+
flag: DEF
479+
480+
name:
481+
name: DllName
482+
type: String
483+
flag: "Name:"
484+
474485
# https://docs.microsoft.com/en-us/cpp/build/reference/linker-options
475486
vslink:
476487
name: VisualStudioLinkerOptions

src/driver/target/native.cpp

Lines changed: 38 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,14 @@ void NativeExecutedTarget::setOutputFile()
221221
if (Scope == TargetScope::Build)
222222
{
223223
if (getSelectedTool() == Librarian.get())
224-
getSelectedTool()->setOutputFile(getOutputFileName2());
224+
getSelectedTool()->setOutputFile(getOutputFileName2("lib"));
225225
else
226226
{
227-
getSelectedTool()->setOutputFile(getOutputFileName(getOutputBaseDir()));
228-
getSelectedTool()->setImportLibrary(getOutputFileName2());
227+
if (getType() == TargetType::NativeExecutable)
228+
getSelectedTool()->setOutputFile(getOutputFileName2("bin"));
229+
else
230+
getSelectedTool()->setOutputFile(getOutputFileName(getOutputBaseDir()));
231+
getSelectedTool()->setImportLibrary(getOutputFileName2("lib"));
229232
}
230233
}
231234
else
@@ -263,7 +266,7 @@ path NativeExecutedTarget::getOutputFileName(const path &root) const
263266
return p;
264267
}
265268

266-
path NativeExecutedTarget::getOutputFileName2() const
269+
path NativeExecutedTarget::getOutputFileName2(const path &subdir) const
267270
{
268271
if (SW_IS_LOCAL_BINARY_DIR)
269272
{
@@ -274,7 +277,7 @@ path NativeExecutedTarget::getOutputFileName2() const
274277
if (IsConfig)
275278
return getOutputFileName("");
276279
else
277-
return BinaryDir.parent_path() / "lib" / getOutputFileName();
280+
return BinaryDir.parent_path() / subdir / getOutputFileName();
278281
}
279282
}
280283

@@ -907,40 +910,8 @@ Commands NativeExecutedTarget::getCommands1() const
907910
// link deps
908911
if (getSelectedTool() != Librarian.get())
909912
{
910-
for (auto &l : gatherDependenciesTargets())
911-
{
912-
if (auto c2 = ((NativeExecutedTarget*)l)->getCommand())
913-
c->dependencies.insert(c2);
914-
}
915-
916-
// check circular, resolve if possible
917-
for (auto &d : CircularDependencies)
918-
{
919-
auto dt = ((NativeExecutedTarget*)d->target);
920-
auto non_circ_cmd = dt->getSelectedTool()->getCommand(*this);
921-
922-
// one command must be executed after the second to free implib files from any compiler locks
923-
// we choose it based on ptr address
924-
//if (c < non_circ_cmd)
925-
c->dependencies.erase(non_circ_cmd);
926-
927-
if (dt->CircularLinker)
928-
{
929-
auto cd = dt->CircularLinker->getCommand(*this);
930-
c->dependencies.insert(cd);
931-
}
932-
//cmds.insert(cd);
933-
}
934-
935-
if (CircularLinker)
936-
{
937-
// execute this command after unresolved (circular) cmd
938-
c->dependencies.insert(CircularLinker->getCommand(*this));
939-
940-
// we reset generator of implib from usual build command (c = getCommand()) to circular linker generator to overcome
941-
// automatic circular dependency generation in command.cpp
942-
//File(getImportLibrary()).getFileRecord().generator = CircularLinker->getCommand();
943-
}
913+
if (circular_dependency)
914+
cmds.insert(Librarian->getCommand(*this));
944915
}
945916

946917
cmds.insert(c);
@@ -1997,6 +1968,8 @@ bool NativeExecutedTarget::prepare()
19971968
case 6:
19981969
// link libraries
19991970
{
1971+
auto L = Linker->as<VisualStudioLinker>();
1972+
20001973
// add link libraries from deps
20011974
if (!HeaderOnly.value() && getSelectedTool() != Librarian.get())
20021975
{
@@ -2011,30 +1984,19 @@ bool NativeExecutedTarget::prepare()
20111984

20121985
auto dt = ((NativeExecutedTarget*)d->target);
20131986

2014-
for (auto &d2 : dt->Dependencies)
1987+
// circular deps detection
1988+
if (L)
20151989
{
2016-
if (d2->target != this)
2017-
continue;
2018-
if (d2->IncludeDirectoriesOnly)
2019-
continue;
2020-
2021-
CircularDependencies.insert(d.get());
2022-
}
2023-
2024-
if (!CircularDependencies.empty())
2025-
{
2026-
CircularLinker = std::static_pointer_cast<NativeLinker>(getSelectedTool()->clone());
2027-
2028-
// set to temp paths
2029-
auto o = IsConfig;
2030-
IsConfig = true;
2031-
CircularLinker->setOutputFile(getOutputFileName(getOutputBaseDir()));
2032-
CircularLinker->setImportLibrary(getOutputFileName2());
2033-
IsConfig = o;
2034-
2035-
if (auto c = CircularLinker->as<VisualStudioLinker>())
1990+
for (auto &d2 : dt->Dependencies)
20361991
{
2037-
c->Force = vs::ForceType::Unresolved;
1992+
if (d2->target != this)
1993+
continue;
1994+
if (d2->IncludeDirectoriesOnly)
1995+
continue;
1996+
1997+
circular_dependency = true;
1998+
L->ImportLibrary.clear();
1999+
break;
20382000
}
20392001
}
20402002

@@ -2077,30 +2039,26 @@ bool NativeExecutedTarget::prepare()
20772039
auto obj = gatherObjectFilesWithoutLibraries();
20782040
auto O1 = gatherLinkLibraries();
20792041

2080-
if (CircularLinker)
2042+
if (!HeaderOnly.value() && getSelectedTool() != Librarian.get())
20812043
{
2082-
// O1 -= Li
2083-
for (auto &d : CircularDependencies)
2084-
O1.erase(std::remove(O1.begin(), O1.end(), ((NativeTarget*)d->target)->getImportLibrary()), O1.end());
2085-
2086-
// CL1 = O1
2087-
CircularLinker->setInputLibraryDependencies(O1);
2044+
for (auto &f : ::sw::gatherSourceFiles<RcToolSourceFile>(*this))
2045+
obj.insert(f->output.file);
2046+
}
20882047

2089-
// O1 += CLi
2090-
for (auto &d : CircularDependencies)
2048+
if (circular_dependency)
2049+
{
2050+
Librarian->setObjectFiles(obj);
2051+
Librarian->setOutputFile(getOutputFileName2("lib"));
2052+
if (auto L = Librarian->as<VisualStudioLibrarian>())
20912053
{
2092-
if (d->target && ((NativeExecutedTarget*)d->target)->CircularLinker)
2093-
O1.push_back(((NativeExecutedTarget*)d->target)->CircularLinker->getImportLibrary());
2054+
L->CreateImportLibrary = true;
2055+
L->DllName = Linker->getOutputFile().filename().u8string();
20942056
}
20952057

2096-
// prepare command here to prevent races
2097-
CircularLinker->getCommand(*this);
2098-
}
2099-
2100-
if (!HeaderOnly.value() && getSelectedTool() != Librarian.get())
2101-
{
2102-
for (auto &f : ::sw::gatherSourceFiles<RcToolSourceFile>(*this))
2103-
obj.insert(f->output.file);
2058+
auto exp = Librarian->getImportLibrary();
2059+
exp = exp.parent_path() / (exp.stem().u8string() + ".exp");
2060+
Librarian->createCommand()->addOutput(exp);
2061+
obj.insert(exp);
21042062
}
21052063

21062064
getSelectedTool()->setObjectFiles(obj);

src/driver/target/native.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,8 @@ struct SW_DRIVER_CPP_API NativeExecutedTarget : NativeTarget,
161161
#undef STD_MACRO
162162

163163
protected:
164-
using once_mutex_t = std::recursive_mutex;
165-
166-
once_mutex_t once;
167164
mutable NativeLinker *SelectedTool = nullptr;
168-
UniqueVector<Dependency*> CircularDependencies;
169-
std::shared_ptr<NativeLinker> CircularLinker;
165+
bool circular_dependency = false;
170166

171167
Files gatherObjectFiles() const;
172168
Files gatherObjectFilesWithoutLibraries() const;
@@ -185,7 +181,7 @@ struct SW_DRIVER_CPP_API NativeExecutedTarget : NativeTarget,
185181

186182
using Target::getOutputFileName;
187183
path getOutputFileName(const path &root) const;
188-
path getOutputFileName2() const;
184+
path getOutputFileName2(const path &subdir) const;
189185
Commands getGeneratedCommands() const;
190186
void resolvePostponedSourceFiles();
191187
void gatherStaticLinkLibraries(LinkLibrariesType &ll, Files &added, std::unordered_set<NativeExecutedTarget*> &targets, bool system);
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
#include <iostream>
2-
3-
MY_A_API void a()
4-
{
5-
std::cout << "Hello, A World!\n";
6-
}
71
MY_B_API void b();
8-
9-
int main()
2+
MY_A_API void a()
103
{
11-
a();
124
b();
13-
return 0;
145
}
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
#include <iostream>
2-
3-
MY_B_API void b()
4-
{
5-
std::cout << "Hello, B World!\n";
6-
}
71
MY_A_API void a();
8-
9-
int main()
2+
MY_B_API void b()
103
{
114
a();
12-
b();
13-
return 0;
145
}
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
#include <iostream>
2-
3-
MY_B_API int b(int a)
4-
{
5-
return a * 2;
6-
}
71
MY_A_API int a(int);
8-
9-
int main()
2+
MY_B_API int b(int aa)
103
{
11-
auto r = b(5);
12-
r = a(r);
13-
std::cout << r;
14-
return 0;
4+
return a(aa) * 2;
155
}

0 commit comments

Comments
 (0)