Skip to content

Commit

Permalink
Update the NUClear codebase to the latest version (#21)
Browse files Browse the repository at this point in the history
Updates the NUClear codebase to the latest version to help with some
compile errors and improve the stability

---------

Co-authored-by: Josephus Paye II <j.paye96@gmail.com>
  • Loading branch information
TrentHouliston and JosephusPaye authored Apr 29, 2024
1 parent 8b72040 commit d7e538a
Show file tree
Hide file tree
Showing 229 changed files with 11,809 additions and 6,913 deletions.
86 changes: 86 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# C++ files
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWrappedFunctionNames: true
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: Inner
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
50 changes: 31 additions & 19 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

# Ensure that only one instance of the workflow is run at a time for each branch/tag.
# Jobs currently running on the branch/tag will be cancelled when new commits are pushed.
# See https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency.
concurrency:
# `github.workflow` is the workflow name, `github.ref` is the current branch/tag identifier
group: ${{ format('{0}:{1}', github.workflow, github.ref) }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
build:

runs-on: ${{ matrix.os }}
continue-on-error: true

strategy:
matrix:
Expand All @@ -21,19 +29,23 @@ jobs:
node-version: [18.x, 20.x]

steps:
# Install node-gyp
- name: Install node-gyp
run: npm install -g node-gyp
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
# Run the tests up to 5 times if it fails (to avoid the error "Network error when sending
# the announce packet: Bad file descriptor" that occurs sometimes on startup)
# TODO: investigate and fix the actual issue.
- shell: bash
run: ./tests/run-with-retries.sh
- name: Checkout Code
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install node-gyp
run: npm install -g node-gyp

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build --if-present

- name: Run tests
run: npm test
26 changes: 15 additions & 11 deletions .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ jobs:
publish_to_npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: main

# Installs Node and sets up up the .npmrc file to publish to npm
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
# Run the tests up to 5 times if it fails (to avoid the error "Network error when sending
# the announce packet: Bad file descriptor" that occurs sometimes on startup)
# TODO: investigate and fix the actual issue.
- shell: bash
run: ./tests/run-with-retries.sh
- run: node .github/auto-publish-action.js
node-version: "18.x"
registry-url: "https://registry.npmjs.org"

- name: "Install Dependencies"
run: npm ci

- name: "Test Code"
run: npm test

- name: "Publish to npm"
run: node .github/auto-publish-action.js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ build/Release
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
build

# # Mac OS X clutter
.DS_Store
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.eol": "\n",
"editor.rulers": [120],
"files.associations": {
"*.ipp": "cpp"
}
}
7 changes: 4 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
'src/NetworkListener.cpp',
'src/nuclear/src/extension/network/NUClearNetwork.cpp',
'src/nuclear/src/util/platform.cpp',
'src/nuclear/src/util/serialise/xxhash.c',
'src/nuclear/src/util/network/get_interfaces.cpp'
'src/nuclear/src/util/network/get_interfaces.cpp',
'src/nuclear/src/util/network/if_number_from_address.cpp',
'src/nuclear/src/util/network/resolve.cpp',
'src/nuclear/src/util/serialise/xxhash.cpp'
],
'cflags': [],
'include_dirs': [
'<!@(node -p "require(\'node-addon-api\').include")',
"<!@(node -p \"require('napi-thread-safe-callback').include\")",
'src/nuclear/src/include'
],
"defines": [
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class NUClearNet extends EventEmitter {
}
});

// Bind our callback functions
this._net.on('packet', this._onPacket.bind(this));
this._net.on('join', this._onJoin.bind(this));
this._net.on('leave', this._onLeave.bind(this));
this._net.on('wait', this._onWait.bind(this));
// Pass our javascript callbacks to the C++ side
this._net.onPacket(this._onPacket.bind(this));
this._net.onJoin(this._onJoin.bind(this));
this._net.onLeave(this._onLeave.bind(this));
this._net.onWait(this._onWait.bind(this));
}

_onPacket(name, address, port, reliable, hash, payload) {
Expand Down
92 changes: 63 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d7e538a

Please sign in to comment.