test(build): sources of one file name, and where their objects go
SameNamedSources builds configurations whose sources share file names, on a fresh copy of its fixture outside the checkout, and runs what they link. `names` is an executable of an a/Thing.cpp and a b/Thing.cpp, the C sources a/unit.c and b/unit.c, a b/Thing.c beside the b/Thing.cpp and a Thing.cpp in a directory beside the configuration's own; its program prints what each returns, the first time and again after a header that only a/Thing.cpp includes has changed and after b/Thing.cpp and b/unit.c have. `registry` is a debug executable of an a/Self.cpp and a b/Self.cpp that register themselves when the program starts, which prints that each did so once. `things` is a static library of a/Thing.cpp, b/Thing.cpp, b/Thing.c and the two unit.c, and `things-app` a program of main.cpp and ../shared/Thing.cpp built on it, which prints what `names` does. `outside` is a static library of one C source that lies outside its configuration's directory and is listed relative to the working directory, built from a working directory with a space in its name; `llvm-ar t` lists its object. ObjectPath asks the rule for the objects of sources without building anything: in the configuration's directory and in directories of it, of one file name in two directories, a .cpp, a .c and a .cu of one name in one directory, outside the directory, and under a directory of the configuration's own that is named objects-outside and holds the whole path of the source outside. No two of them get one object. A path spelled with . and .., a relative source, and a source of a configuration whose path ends in a separator or is ./ are each given the object of the file they lead to, and a .cppm, a .h and a file without an extension are refused. CudaCompile gains a static library of its kernel.cu and a kernel.c beside it, whose archive lists kernel_source.o and kernel_cuda.o. Before the fix SameNamedSources failed at the link of `names`, with duplicate symbols, and of `things-app`, with undefined ones, and its `registry` printed that one of the two sources had registered twice and the other not at all. `outside` built before the fix as well, its object lying in the build directory then: it is there for the path the fix gives that object.
This commit is contained in:
parent
7f8089474b
commit
f9bd5333da
19 changed files with 456 additions and 4 deletions
10
tests/SameNamedSources/fixture/registry/a/Self.cpp
Normal file
10
tests/SameNamedSources/fixture/registry/a/Self.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
void Register(int source);
|
||||
|
||||
// Nothing in this file is named by another: it is in the program for what it
|
||||
// does when the program starts.
|
||||
namespace {
|
||||
const int registered = (Register(1), 0);
|
||||
}
|
||||
10
tests/SameNamedSources/fixture/registry/b/Self.cpp
Normal file
10
tests/SameNamedSources/fixture/registry/b/Self.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
void Register(int source);
|
||||
|
||||
// Nothing in this file is named by another: it is in the program for what it
|
||||
// does when the program starts.
|
||||
namespace {
|
||||
const int registered = (Register(2), 0);
|
||||
}
|
||||
19
tests/SameNamedSources/fixture/registry/main.cpp
Normal file
19
tests/SameNamedSources/fixture/registry/main.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
import std;
|
||||
|
||||
namespace {
|
||||
// How often each source has registered: [1] is a/Self.cpp's count and
|
||||
// [2] is b/Self.cpp's.
|
||||
int Registered[3];
|
||||
}
|
||||
|
||||
// Called by a/Self.cpp with 1 and by b/Self.cpp with 2, as the program starts.
|
||||
void Register(int source) { ++Registered[source]; }
|
||||
|
||||
// Prints the two counts: "1 1" when each of the two is in the program once.
|
||||
int main() {
|
||||
std::printf("%d %d", Registered[1], Registered[2]);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue