Meta: Add a script check the presence of "#pragma once" in header files

.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
This commit is contained in:
Emanuele Torre 2020-05-28 20:40:53 +02:00 committed by Andreas Kling
parent 8e151ff33e
commit 937d0be762
Notes: sideshowbarker 2024-07-19 06:00:11 +09:00
61 changed files with 150 additions and 42 deletions

View file

@ -33,7 +33,7 @@ before_install:
script:
- export SERENITY_ROOT=$(pwd)
- Meta/lint-shell-scripts.sh
- Meta/check-license-headers.sh
- Meta/check-style.sh
- cd Toolchain
- TRY_USE_LOCAL_TOOLCHAIN=y ./BuildIt.sh
- cd "$SERENITY_ROOT"

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/Forward.h>
namespace AK {

View file

@ -23,6 +23,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibGUI/Widget.h>

View file

@ -23,6 +23,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "BrowserConsoleClient.h"

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibGUI/Widget.h>
#include <LibWeb/Forward.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/String.h>
#include <sys/stat.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/Function.h>
#include <LibGUI/Frame.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/CircularQueue.h>
#include <LibGUI/Frame.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibGUI/Widget.h>
#include <LibGfx/Point.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/Vector.h>
#include <LibGUI/ListView.h>
#include <LibGUI/Model.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/Function.h>
#include <AK/String.h>
#include <AK/Types.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include "Debugger.h"
#include <AK/NonnullOwnPtr.h>
#include <LibGUI/Model.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibGUI/Frame.h>
class Profile;

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include "CardStack.h"
#include <LibGUI/Painter.h>
#include <LibGUI/Widget.h>

View file

@ -34,17 +34,18 @@
// More information about the ATA spec for PATA can be found here:
// ftp://ftp.seagate.com/acrobat/reference/111-1c.pdf
//
#pragma once
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <Kernel/IO.h>
#include <Kernel/Lock.h>
#include <Kernel/PCI/Access.h>
#include <Kernel/PCI/Device.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/WaitQueue.h>
#include <Kernel/IO.h>
#include <Kernel/PhysicalAddress.h>
namespace Kernel {

View file

@ -27,7 +27,7 @@
//
// A Disk Device Connected to a PATA Channel
//
//
#pragma once
#include <Kernel/Devices/BlockDevice.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <Kernel/Devices/CharacterDevice.h>
namespace Kernel {

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
/*
* If linux/types.h is already been included, assume it has defined
* everything we need. (cross fingers) Other header files may have

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <Kernel/PCI/Access.h>
namespace Kernel {

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/Types.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <Kernel/KResult.h>
#include <Kernel/Process.h>
#include <Kernel/Syscall.h>

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <sys/cdefs.h>

View file

@ -24,3 +24,4 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

View file

@ -24,4 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <string.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <sys/socket.h>
struct rtentry {

View file

@ -23,3 +23,5 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/Types.h>
struct [[gnu::packed]] PtraceRegisters

View file

@ -24,3 +24,4 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

View file

@ -24,4 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <mman.h>

View file

@ -24,3 +24,4 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace Core {
class ArgsParser;

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/Optional.h>
#include <AK/String.h>

View file

@ -1,3 +1,5 @@
#pragma once
/* puff.h
Copyright (C) 2002-2013 Mark Adler, all rights reserved
version 2.3, 21 Jan 2013

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/LogStream.h>
#include <AK/String.h>
@ -45,7 +46,7 @@ public:
{
}
UnsignedBigInteger() {}
UnsignedBigInteger() { }
static UnsignedBigInteger create_invalid();

View file

@ -25,12 +25,14 @@
*/
#pragma once
#include "DwarfTypes.h"
#include <AK/HashMap.h>
#include <AK/Optional.h>
#include <AK/Types.h>
namespace Dwarf {
class DwarfInfo;
class AbbreviationsMap {

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include "AbbreviationsMap.h"
#include <AK/Types.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include "CompilationUnit.h"
#include "DwarfTypes.h"
#include <AK/BufferStream.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include "CompilationUnit.h"
#include "DwarfTypes.h"
#include <AK/BufferStream.h>

View file

@ -23,7 +23,9 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/Types.h>
namespace Dwarf {

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include "AK/ByteBuffer.h"
#include "AK/Types.h"
@ -32,6 +33,7 @@ class PtraceRegisters;
namespace Dwarf {
namespace Expression {
enum class Type {
None,
UnsignedIntetger,
@ -52,5 +54,5 @@ enum class Operations : u8 {
Value evaluate(const ByteBuffer&, const PtraceRegisters&);
};
};
}
}

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/BufferStream.h>
#include <AK/Vector.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/LexicalPath.h>
#include <AK/Optional.h>
#include <LibCore/StandardPaths.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace GUI {
class AbstractButton;

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibGUI/Widget.h>
namespace GUI {

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace Gemini {
class Document;

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/Forward.h>
#include <LibGfx/Point.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace HTTP {
class HttpRequest;

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/HashTable.h>
#include <AK/String.h>
#include <LibJS/Forward.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibCore/DateTime.h>
#include <LibJS/Runtime/Object.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibJS/Runtime/Cell.h>
#include <LibJS/Runtime/Value.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <stdlib.h>
namespace Line {

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/Forward.h>
#include <AK/String.h>
#include <LibLine/SuggestionManager.h>

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/Forward.h>
#include <AK/String.h>
#include <AK/Utf32View.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/LayoutBox.h>

View file

@ -23,6 +23,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/URL.h>

View file

@ -1,30 +0,0 @@
#!/bin/bash
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "$script_path/.." || exit 1
# We simply check if the file starts with:
# /*
# * Copyright
PATTERN=$'^/\*\n \* Copyright'
ERRORS=()
while IFS= read -r f; do
if [[ ! $(cat "$f") =~ $PATTERN ]]; then
ERRORS+=("$f")
fi
done < <(git ls-files -- \
'*.cpp' \
'*.h' \
':!:Tests' \
':!:Base' \
':!:Kernel/FileSystem/ext2_fs.h' \
':!:Libraries/LibC/getopt.cpp' \
':!:Libraries/LibCore/puff.h' \
':!:Libraries/LibELF/exec_elf.h' \
)
if (( ${#ERRORS[@]} )); then
echo "Files missing license headers: ${ERRORS[*]}"
exit 1
fi

56
Meta/check-style.sh Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "$script_path/.." || exit 1
# We simply check if the file starts with:
# /*
# * Copyright
LICENSE_HEADER_PATTERN=$'^/\*\n \* Copyright'
MISSING_LICENSE_HEADER_ERRORS=()
# We check that "#pragma once" is present
PRAGMA_ONCE_PATTERN='#pragma once'
MISSING_PRAGMA_ONCE_ERRORS=()
# We make sure that there's a blank line before and after pragma once
GOOD_PRAGMA_ONCE_PATTERN=$'(^|\\S\n\n)#pragma once(\n\n\\S.|$)'
BAD_PRAGMA_ONCE_ERRORS=()
while IFS= read -r f; do
file_content="$(< "$f")"
if [[ ! "$file_content" =~ $LICENSE_HEADER_PATTERN ]]; then
MISSING_LICENSE_HEADER_ERRORS+=("$f")
fi
if [[ "$f" =~ \.h$ ]]; then
if [[ ! "$file_content" =~ $PRAGMA_ONCE_PATTERN ]]; then
MISSING_PRAGMA_ONCE_ERRORS+=("$f")
elif [[ ! "$file_content" =~ $GOOD_PRAGMA_ONCE_PATTERN ]]; then
BAD_PRAGMA_ONCE_ERRORS+=("$f")
fi
fi
done < <(git ls-files -- \
'*.cpp' \
'*.h' \
':!:Tests' \
':!:Base' \
':!:Kernel/FileSystem/ext2_fs.h' \
':!:Libraries/LibC/getopt.cpp' \
':!:Libraries/LibCore/puff.h' \
':!:Libraries/LibELF/exec_elf.h' \
)
exit_status=0
if (( ${#MISSING_LICENSE_HEADER_ERRORS[@]} )); then
echo "Files missing license headers: ${MISSING_LICENSE_HEADER_ERRORS[*]}"
exit_status=1
fi
if (( ${#MISSING_PRAGMA_ONCE_ERRORS[@]} )); then
echo "Header files missing \"#pragma once\": ${MISSING_PRAGMA_ONCE_ERRORS[*]}"
exit_status=1
fi
if (( ${#BAD_PRAGMA_ONCE_ERRORS[@]} )); then
echo "\"#pragma once\" should have a blank line before and after in these files: ${BAD_PRAGMA_ONCE_ERRORS[*]}"
exit_status=1
fi
exit "$exit_status"

View file

@ -24,14 +24,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "DNSAnswer.h"
#include "DNSQuestion.h"
#include <AK/Optional.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <AK/Optional.h>
class DNSResponse {
public:
@ -69,7 +68,7 @@ public:
Code code() const { return (Code)m_code; }
private:
DNSResponse() {}
DNSResponse() { }
u16 m_id { 0 };
u8 m_code { 0 };

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/Vector.h>
#include <LibGUI/Dialog.h>

View file

@ -24,6 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "WindowList.h"
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>