Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate headers from source files #12764

Merged
merged 3 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ pull_request_rules:
labels:
- automatic backport
- merge-queue

- name: backport patches to 2.28
conditions:
- label=backport 2.28-maintenance
actions:
backport:
branches:
- "2.28-maintenance"
labels:
- automatic backport
- merge-queue
12 changes: 8 additions & 4 deletions doc/manual/source/development/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
> ├── libexpr
> │ ├── meson.build
> │ ├── value/context.hh
> │ ├── value/context.cc
> │ ├── include/nix/value/context.cc
> │ …
> │
> ├── tests
Expand All @@ -46,8 +46,12 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
> │ │
> │ ├── libexpr-test-support
> │ │ ├── meson.build
> │ │ ├── include/nix
> │ │ │ ├── meson.build
> │ │ │ └── tests
> │ │ │ ├── value/context.hh
> │ │ │ …
> │ │ └── tests
> │ │ ├── value/context.hh
> │ │ ├── value/context.cc
> │ │ …
> │ │
Expand All @@ -59,15 +63,15 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
> ```

The tests for each Nix library (`libnixexpr`, `libnixstore`, etc..) live inside a directory `src/${library_name_without-nix}-test`.
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}`.
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`.

Data for unit tests is stored in a `data` subdir of the directory for each unit test executable.
For example, `libnixstore` code is in `src/libstore`, and its test data is in `src/libstore-tests/data`.
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`.
Note that each executable only gets the data for its tests.

The unit test libraries are in `src/${library_name_without-nix}-test-support`.
All headers are in a `tests` subdirectory so they are included with `#include "tests/"`.
All headers are in a `tests` subdirectory so they are included with `#include "nix/tests/"`.

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.
But organizing the tests this way has one big benefit:
Expand Down
338 changes: 169 additions & 169 deletions maintainers/flake-module.nix

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion nix-meson-build-support/export/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import('pkgconfig').generate(
filebase : meson.project_name(),
name : 'Nix',
description : 'Nix Package Manager',
subdirs : ['nix'],
extra_cflags : ['-std=c++2a'],
requires : requires_public,
requires_private : requires_private,
Expand Down
26 changes: 13 additions & 13 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
#include <sys/time.h>
#endif

#include "machines.hh"
#include "shared.hh"
#include "plugin.hh"
#include "pathlocks.hh"
#include "globals.hh"
#include "serialise.hh"
#include "build-result.hh"
#include "store-api.hh"
#include "strings.hh"
#include "derivations.hh"
#include "local-store.hh"
#include "legacy.hh"
#include "experimental-features.hh"
#include "nix/machines.hh"
#include "nix/shared.hh"
#include "nix/plugin.hh"
#include "nix/pathlocks.hh"
#include "nix/globals.hh"
#include "nix/serialise.hh"
#include "nix/build-result.hh"
#include "nix/store-api.hh"
#include "nix/strings.hh"
#include "nix/derivations.hh"
#include "nix/local-store.hh"
#include "nix/legacy.hh"
#include "nix/experimental-features.hh"

using namespace nix;
using std::cin;
Expand Down
8 changes: 4 additions & 4 deletions src/libcmd/built-path.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "built-path.hh"
#include "derivations.hh"
#include "store-api.hh"
#include "comparator.hh"
#include "nix/built-path.hh"
#include "nix/derivations.hh"
#include "nix/store-api.hh"
#include "nix/comparator.hh"

#include <nlohmann/json.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/command-installable-value.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "command-installable-value.hh"
#include "nix/command-installable-value.hh"

namespace nix {

Expand Down
20 changes: 10 additions & 10 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include <algorithm>
#include <nlohmann/json.hpp>

#include "command.hh"
#include "markdown.hh"
#include "store-api.hh"
#include "local-fs-store.hh"
#include "derivations.hh"
#include "nixexpr.hh"
#include "profiles.hh"
#include "repl.hh"
#include "strings.hh"
#include "environment-variables.hh"
#include "nix/command.hh"
#include "nix/markdown.hh"
#include "nix/store-api.hh"
#include "nix/local-fs-store.hh"
#include "nix/derivations.hh"
#include "nix/nixexpr.hh"
#include "nix/profiles.hh"
#include "nix/repl.hh"
#include "nix/strings.hh"
#include "nix/environment-variables.hh"

namespace nix {

Expand Down
34 changes: 17 additions & 17 deletions src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "fetch-settings.hh"
#include "eval-settings.hh"
#include "common-eval-args.hh"
#include "shared.hh"
#include "config-global.hh"
#include "filetransfer.hh"
#include "eval.hh"
#include "fetchers.hh"
#include "registry.hh"
#include "flake/flakeref.hh"
#include "flake/settings.hh"
#include "store-api.hh"
#include "command.hh"
#include "tarball.hh"
#include "fetch-to-store.hh"
#include "compatibility-settings.hh"
#include "eval-settings.hh"
#include "nix/fetch-settings.hh"
#include "nix/eval-settings.hh"
#include "nix/common-eval-args.hh"
#include "nix/shared.hh"
#include "nix/config-global.hh"
#include "nix/filetransfer.hh"
#include "nix/eval.hh"
#include "nix/fetchers.hh"
#include "nix/registry.hh"
#include "nix/flake/flakeref.hh"
#include "nix/flake/settings.hh"
#include "nix/store-api.hh"
#include "nix/command.hh"
#include "nix/tarball.hh"
#include "nix/fetch-to-store.hh"
#include "nix/compatibility-settings.hh"
#include "nix/eval-settings.hh"

namespace nix {

Expand Down
6 changes: 3 additions & 3 deletions src/libcmd/editor-for.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "editor-for.hh"
#include "environment-variables.hh"
#include "source-path.hh"
#include "nix/editor-for.hh"
#include "nix/environment-variables.hh"
#include "nix/source-path.hh"

namespace nix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
///@file

#include "derived-path.hh"
#include "realisation.hh"
#include "nix/derived-path.hh"
#include "nix/realisation.hh"

namespace nix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
///@file

#include "installable-value.hh"
#include "command.hh"
#include "nix/installable-value.hh"
#include "nix/command.hh"

namespace nix {

Expand Down
10 changes: 5 additions & 5 deletions src/libcmd/command.hh → src/libcmd/include/nix/command.hh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once
///@file

#include "installable-value.hh"
#include "args.hh"
#include "common-eval-args.hh"
#include "path.hh"
#include "flake/lockfile.hh"
#include "nix/installable-value.hh"
#include "nix/args.hh"
#include "nix/common-eval-args.hh"
#include "nix/path.hh"
#include "nix/flake/lockfile.hh"

#include <optional>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
///@file

#include "args.hh"
#include "canon-path.hh"
#include "common-args.hh"
#include "search-path.hh"
#include "nix/args.hh"
#include "nix/canon-path.hh"
#include "nix/common-args.hh"
#include "nix/search-path.hh"

#include <filesystem>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "config.hh"
#include "nix/config.hh"

namespace nix {
struct CompatibilitySettings : public Config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
///@file

#include "types.hh"
#include "source-path.hh"
#include "nix/types.hh"
#include "nix/source-path.hh"

namespace nix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#pragma once
///@file

#include "globals.hh"
#include "installable-value.hh"
#include "outputs-spec.hh"
#include "command.hh"
#include "attr-path.hh"
#include "common-eval-args.hh"
#include "derivations.hh"
#include "eval-inline.hh"
#include "eval.hh"
#include "get-drvs.hh"
#include "store-api.hh"
#include "shared.hh"
#include "eval-cache.hh"
#include "url.hh"
#include "registry.hh"
#include "build-result.hh"
#include "nix/globals.hh"
#include "nix/installable-value.hh"
#include "nix/outputs-spec.hh"
#include "nix/command.hh"
#include "nix/attr-path.hh"
#include "nix/common-eval-args.hh"
#include "nix/derivations.hh"
#include "nix/eval-inline.hh"
#include "nix/eval.hh"
#include "nix/get-drvs.hh"
#include "nix/store-api.hh"
#include "nix/shared.hh"
#include "nix/eval-cache.hh"
#include "nix/url.hh"
#include "nix/registry.hh"
#include "nix/build-result.hh"

#include <regex>
#include <queue>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
///@file

#include "installables.hh"
#include "nix/installables.hh"

namespace nix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
///@file

#include "common-eval-args.hh"
#include "installable-value.hh"
#include "nix/common-eval-args.hh"
#include "nix/installable-value.hh"

namespace nix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
///@file

#include "installables.hh"
#include "flake/flake.hh"
#include "nix/installables.hh"
#include "nix/flake/flake.hh"

namespace nix {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once
///@file

#include "path.hh"
#include "outputs-spec.hh"
#include "derived-path.hh"
#include "built-path.hh"
#include "store-api.hh"
#include "build-result.hh"
#include "nix/path.hh"
#include "nix/outputs-spec.hh"
#include "nix/derived-path.hh"
#include "nix/built-path.hh"
#include "nix/store-api.hh"
#include "nix/build-result.hh"

#include <optional>

Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions src/libcmd/include/nix/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Public headers directory

include_dirs = [include_directories('..')]

headers = files(
'built-path.hh',
'command-installable-value.hh',
'command.hh',
'common-eval-args.hh',
'compatibility-settings.hh',
'editor-for.hh',
'installable-attr-path.hh',
'installable-derived-path.hh',
'installable-flake.hh',
'installable-value.hh',
'installables.hh',
'legacy.hh',
'markdown.hh',
'misc-store-flags.hh',
'network-proxy.hh',
'repl-interacter.hh',
'repl.hh',
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "args.hh"
#include "content-address.hh"
#include "nix/args.hh"
#include "nix/content-address.hh"

namespace nix::flag {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
///@file

#include "types.hh"
#include "nix/types.hh"

namespace nix {

Expand Down
Loading
Loading