Skip to content

Commit f3e1c47

Browse files
committed
Separate headers from source files
The short answer for why we need to do this is so we can consistently do `#include "nix/..."`. Without this change, there are ways to still make that work, but they are hacky, and they have downsides such as making it harder to make sure headers from the wrong Nix library (e..g. `libnixexpr` headers in `libnixutil`) aren't being used. The C API alraedy used `nix_api_*`, so its headers are *not* put in subdirectories accordingly. Progress on #7876 We resisted doing this for a while because it would be annoying to not have the header source file pairs close by / easy to change file path/name from one to the other. But I am ameliorating that with symlinks in the next commit.
1 parent 326548b commit f3e1c47

664 files changed

Lines changed: 2978 additions & 2917 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/manual/source/development/testing.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
3131
> ├── libexpr
3232
> │ ├── meson.build
3333
> │ ├── value/context.hh
34-
> │ ├── value/context.cc
34+
> │ ├── include/nix/value/context.cc
3535
> │ …
3636
> │
3737
> ├── tests
@@ -46,8 +46,12 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
4646
> │ │
4747
> │ ├── libexpr-test-support
4848
> │ │ ├── meson.build
49+
> │ │ ├── include/nix
50+
> │ │ │ ├── meson.build
51+
> │ │ │ └── tests
52+
> │ │ │ ├── value/context.hh
53+
> │ │ │ …
4954
> │ │ └── tests
50-
> │ │ ├── value/context.hh
5155
> │ │ ├── value/context.cc
5256
> │ │ …
5357
> │ │
@@ -59,15 +63,15 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
5963
> ```
6064
6165
The tests for each Nix library (`libnixexpr`, `libnixstore`, etc..) live inside a directory `src/${library_name_without-nix}-test`.
62-
Given an interface (header) and implementation pair in the original library, say, `src/libexpr/value/context.{hh,cc}`, we write tests for it in `src/libexpr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/libexpr-test-support/tests/value/context.{hh,cc}`.
66+
Given an interface (header) and implementation pair in the original library, say, `src/libexpr/include/nix/value/context.hh` and `src/libexpr/value/context.cc`, we write tests for it in `src/libexpr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/libexpr-test-support/include/nix/tests/value/context.hh` and `src/libexpr-test-support/tests/value/context.cc`.
6367
6468
Data for unit tests is stored in a `data` subdir of the directory for each unit test executable.
6569
For example, `libnixstore` code is in `src/libstore`, and its test data is in `src/libstore-tests/data`.
6670
The path to the `src/${library_name_without-nix}-test/data` directory is passed to the unit test executable with the environment variable `_NIX_TEST_UNIT_DATA`.
6771
Note that each executable only gets the data for its tests.
6872
6973
The unit test libraries are in `src/${library_name_without-nix}-test-support`.
70-
All headers are in a `tests` subdirectory so they are included with `#include "tests/"`.
74+
All headers are in a `tests` subdirectory so they are included with `#include "nix/tests/"`.
7175
7276
The use of all these separate directories for the unit tests might seem inconvenient, as for example the tests are not "right next to" the part of the code they are testing.
7377
But organizing the tests this way has one big benefit:

maintainers/flake-module.nix

Lines changed: 169 additions & 169 deletions
Large diffs are not rendered by default.

nix-meson-build-support/export/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import('pkgconfig').generate(
1616
filebase : meson.project_name(),
1717
name : 'Nix',
1818
description : 'Nix Package Manager',
19-
subdirs : ['nix'],
2019
extra_cflags : ['-std=c++2a'],
2120
requires : requires_public,
2221
requires_private : requires_private,

src/build-remote/build-remote.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
#include <sys/time.h>
1010
#endif
1111

12-
#include "machines.hh"
13-
#include "shared.hh"
14-
#include "plugin.hh"
15-
#include "pathlocks.hh"
16-
#include "globals.hh"
17-
#include "serialise.hh"
18-
#include "build-result.hh"
19-
#include "store-api.hh"
20-
#include "strings.hh"
21-
#include "derivations.hh"
22-
#include "local-store.hh"
23-
#include "legacy.hh"
24-
#include "experimental-features.hh"
12+
#include "nix/machines.hh"
13+
#include "nix/shared.hh"
14+
#include "nix/plugin.hh"
15+
#include "nix/pathlocks.hh"
16+
#include "nix/globals.hh"
17+
#include "nix/serialise.hh"
18+
#include "nix/build-result.hh"
19+
#include "nix/store-api.hh"
20+
#include "nix/strings.hh"
21+
#include "nix/derivations.hh"
22+
#include "nix/local-store.hh"
23+
#include "nix/legacy.hh"
24+
#include "nix/experimental-features.hh"
2525

2626
using namespace nix;
2727
using std::cin;

src/libcmd/built-path.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include "built-path.hh"
2-
#include "derivations.hh"
3-
#include "store-api.hh"
4-
#include "comparator.hh"
1+
#include "nix/built-path.hh"
2+
#include "nix/derivations.hh"
3+
#include "nix/store-api.hh"
4+
#include "nix/comparator.hh"
55

66
#include <nlohmann/json.hpp>
77

src/libcmd/command-installable-value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "command-installable-value.hh"
1+
#include "nix/command-installable-value.hh"
22

33
namespace nix {
44

src/libcmd/command.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#include <algorithm>
22
#include <nlohmann/json.hpp>
33

4-
#include "command.hh"
5-
#include "markdown.hh"
6-
#include "store-api.hh"
7-
#include "local-fs-store.hh"
8-
#include "derivations.hh"
9-
#include "nixexpr.hh"
10-
#include "profiles.hh"
11-
#include "repl.hh"
12-
#include "strings.hh"
13-
#include "environment-variables.hh"
4+
#include "nix/command.hh"
5+
#include "nix/markdown.hh"
6+
#include "nix/store-api.hh"
7+
#include "nix/local-fs-store.hh"
8+
#include "nix/derivations.hh"
9+
#include "nix/nixexpr.hh"
10+
#include "nix/profiles.hh"
11+
#include "nix/repl.hh"
12+
#include "nix/strings.hh"
13+
#include "nix/environment-variables.hh"
1414

1515
namespace nix {
1616

src/libcmd/common-eval-args.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#include "fetch-settings.hh"
2-
#include "eval-settings.hh"
3-
#include "common-eval-args.hh"
4-
#include "shared.hh"
5-
#include "config-global.hh"
6-
#include "filetransfer.hh"
7-
#include "eval.hh"
8-
#include "fetchers.hh"
9-
#include "registry.hh"
10-
#include "flake/flakeref.hh"
11-
#include "flake/settings.hh"
12-
#include "store-api.hh"
13-
#include "command.hh"
14-
#include "tarball.hh"
15-
#include "fetch-to-store.hh"
16-
#include "compatibility-settings.hh"
17-
#include "eval-settings.hh"
1+
#include "nix/fetch-settings.hh"
2+
#include "nix/eval-settings.hh"
3+
#include "nix/common-eval-args.hh"
4+
#include "nix/shared.hh"
5+
#include "nix/config-global.hh"
6+
#include "nix/filetransfer.hh"
7+
#include "nix/eval.hh"
8+
#include "nix/fetchers.hh"
9+
#include "nix/registry.hh"
10+
#include "nix/flake/flakeref.hh"
11+
#include "nix/flake/settings.hh"
12+
#include "nix/store-api.hh"
13+
#include "nix/command.hh"
14+
#include "nix/tarball.hh"
15+
#include "nix/fetch-to-store.hh"
16+
#include "nix/compatibility-settings.hh"
17+
#include "nix/eval-settings.hh"
1818

1919
namespace nix {
2020

src/libcmd/editor-for.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "editor-for.hh"
2-
#include "environment-variables.hh"
3-
#include "source-path.hh"
1+
#include "nix/editor-for.hh"
2+
#include "nix/environment-variables.hh"
3+
#include "nix/source-path.hh"
44

55
namespace nix {
66

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22
///@file
33

4-
#include "derived-path.hh"
5-
#include "realisation.hh"
4+
#include "nix/derived-path.hh"
5+
#include "nix/realisation.hh"
66

77
namespace nix {
88

0 commit comments

Comments
 (0)