Skip to content

Commit

Permalink
libutil/windows: only define headers/code if we are actually on windows
Browse files Browse the repository at this point in the history
all those includes otherwise break linters.
  • Loading branch information
Mic92 committed Dec 17, 2024
1 parent b9bbdbe commit eda331e
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/libexpr/lexer-helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

// inluding the generated headers twice leads to errors
#ifndef BISON_HEADER
#include "lexer-tab.hh"
#include "parser-tab.hh"
# include "lexer-tab.hh"
# include "parser-tab.hh"
#endif

namespace nix::lexer::internal {
Expand Down
11 changes: 7 additions & 4 deletions src/libstore/windows/pathlocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include "pathlocks.hh"
#include "signals.hh"
#include "util.hh"
#include <errhandlingapi.h>
#include <fileapi.h>
#include <windows.h>
#include "windows-error.hh"

#ifdef WIN32
# include <errhandlingapi.h>
# include <fileapi.h>
# include <windows.h>
# include "windows-error.hh"

namespace nix {

Expand Down Expand Up @@ -154,3 +156,4 @@ FdLock::FdLock(Descriptor desc, LockType lockType, bool wait, std::string_view w
}

}
#endif
4 changes: 3 additions & 1 deletion src/libutil/windows/environment-variables.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "environment-variables.hh"

#include "processenv.h"
#ifdef WIN32
# include "processenv.h"

namespace nix {

Expand Down Expand Up @@ -43,3 +44,4 @@ int setEnvOs(const OsString & name, const OsString & value)
}

}
#endif
2 changes: 2 additions & 0 deletions src/libutil/windows/file-descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "windows-error.hh"
#include "file-path.hh"

#ifdef WIN32
#include <fileapi.h>
#include <error.h>
#include <namedpipeapi.h>
Expand Down Expand Up @@ -152,3 +153,4 @@ Path windows::handleToPath(HANDLE handle) {
#endif

}
#endif
2 changes: 2 additions & 0 deletions src/libutil/windows/file-system.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "file-system.hh"

#ifdef WIN32
namespace nix {

Descriptor openDirectory(const std::filesystem::path & path)
Expand All @@ -15,3 +16,4 @@ Descriptor openDirectory(const std::filesystem::path & path)
}

}
#endif
12 changes: 7 additions & 5 deletions src/libutil/windows/muxable-pipe.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <ioapiset.h>
#include "windows-error.hh"
#ifdef WIN32
# include <ioapiset.h>
# include "windows-error.hh"

#include "logging.hh"
#include "util.hh"
#include "muxable-pipe.hh"
# include "logging.hh"
# include "util.hh"
# include "muxable-pipe.hh"

namespace nix {

Expand Down Expand Up @@ -68,3 +69,4 @@ void MuxablePipePollState::iterate(
}

}
#endif
4 changes: 4 additions & 0 deletions src/libutil/windows/os-string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "file-path-impl.hh"
#include "util.hh"

#ifdef WIN32

namespace nix {

std::string os_string_to_string(PathViewNG::string_view path)
Expand All @@ -22,3 +24,5 @@ std::filesystem::path::string_type string_to_os_string(std::string_view s)
}

}

#endif
4 changes: 4 additions & 0 deletions src/libutil/windows/processes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <sys/types.h>
#include <unistd.h>

#ifdef WIN32

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

Expand Down Expand Up @@ -386,3 +388,5 @@ int execvpe(const wchar_t * file0, const wchar_t * const argv[], const wchar_t *
}

}

#endif
2 changes: 2 additions & 0 deletions src/libutil/windows/users.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "file-system.hh"
#include "windows-error.hh"

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

Expand Down Expand Up @@ -50,3 +51,4 @@ bool isRootUser() {
}

}
#endif
4 changes: 4 additions & 0 deletions src/libutil/windows/windows-async-pipe.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "windows-async-pipe.hh"
#include "windows-error.hh"

#ifdef WIN32

namespace nix::windows {

void AsyncPipe::createAsyncPipe(HANDLE iocp)
Expand Down Expand Up @@ -47,3 +49,5 @@ void AsyncPipe::close()
}

}

#endif
2 changes: 2 additions & 0 deletions src/libutil/windows/windows-async-pipe.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
///@file

#include "file-descriptor.hh"
#ifdef WIN32

namespace nix::windows {

Expand All @@ -25,3 +26,4 @@ public:
};

}
#endif
2 changes: 2 additions & 0 deletions src/libutil/windows/windows-error.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "windows-error.hh"

#ifdef WIN32
#include <error.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Expand Down Expand Up @@ -29,3 +30,4 @@ std::string WinError::renderError(DWORD lastError)
}

}
#endif
2 changes: 2 additions & 0 deletions src/libutil/windows/windows-error.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
///@file

#ifdef WIN32
#include <errhandlingapi.h>

#include "error.hh"
Expand Down Expand Up @@ -49,3 +50,4 @@ private:
};

}
#endif

0 comments on commit eda331e

Please sign in to comment.