Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Set up wpiformat
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored and PeterJohnson committed Jan 2, 2018
1 parent 4514ff8 commit 19f7a5f
Show file tree
Hide file tree
Showing 107 changed files with 1,144 additions and 908 deletions.
24 changes: 21 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
Expand All @@ -32,30 +32,45 @@ BraceWrapping:
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
Expand All @@ -64,6 +79,7 @@ NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
Expand All @@ -72,8 +88,10 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
Expand Down
26 changes: 26 additions & 0 deletions .styleguide
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cppHeaderFileInclude {
\.h$
\.inc$
}

cppSrcFileInclude {
\.cpp$
}

generatedFileExclude {
gmock/
llvm/
src/arm-linux-jni/
src/main/native/cpp/jni/
}

includeGuardRoots {
src/main/native/cpp/
src/main/native/include/
src/test/native/cpp/
}

includeOtherLibs {
^llvm/
^support/
}
6 changes: 6 additions & 0 deletions .styleguide-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST {year}. All Rights Reserved.{padding}*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
11 changes: 11 additions & 0 deletions .travis-scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

if [[ $TRAVIS_OS_NAME != 'osx' ]]; then
# Install custom requirements on Linux
sudo sh -c 'echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" > /etc/apt/sources.list.d/llvm.list'
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository ppa:wpilib/toolchain -y
sudo apt-get update -q
sudo apt-get install frc-toolchain -y

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.5 get-pip.py
python3.5 -m pip install --user wpiformat
else
brew update
brew install python3 clang-format

pip3 install --user wpiformat
fi
9 changes: 9 additions & 0 deletions .travis-scripts/wpiformat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [[ $TRAVIS_OS_NAME != 'osx' ]]; then
python3.5 -m wpiformat -y 2017 -clang 5.0
else
python3 -m wpiformat -y 2017
fi

git --no-pager diff --exit-code HEAD # Ensure formatter made no changes
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: true
language: java

matrix:
Expand All @@ -10,9 +11,12 @@ matrix:

addons:
apt:
sources:
- deadsnakes
packages:
- g++-multilib
- lib32stdc++6
- python3.5

before_install:
- .travis-scripts/install.sh
Expand All @@ -21,6 +25,7 @@ install:
- ./gradlew build -PbuildAll

script:
- .travis-scripts/wpiformat.sh
- ./gradlew build -PbuildAll

before_cache:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ When you first submit changes, Travis-CI will attempt to run `./gradlew check` o

## Licensing

By contributing to ntcore, you agree that your code will be distributed with ntcore, and licensed under the license for the ntcore project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as ntcore is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](license.txt).
By contributing to ntcore, you agree that your code will be distributed with ntcore, and licensed under the license for the ntcore project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as ntcore is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](license.txt).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ The `ntcore-java` artifact will contain a jar with no classifiers. This is the j

All of these artifacts by default are published to `~/releases/maven/development`. To switch to the release repository (`~/release/maven/release`), use the flag `-PreleaseType=OFFICIAL`.

All downstream projects are configured to use the individual classifier artifacts. The previouse `desktop` classifier does not exist anymore.
All downstream projects are configured to use the individual classifier artifacts. The previouse `desktop` classifier does not exist anymore.

When you do a publish of ntcore locally, the locally built copy will override all references to networktables dependencies from the FRC Maven server. To undo this, you must delete `~/releases/maven/<repo>/edu/wpi/first/ntcore`.
4 changes: 2 additions & 2 deletions license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*
* THIS SOFTWARE IS PROVIDED BY FIRST AND CONTRIBUTORS``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
* WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Expand Down
7 changes: 7 additions & 0 deletions manualTests/java/Client.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

import edu.wpi.first.wpilibj.networktables.*;
import edu.wpi.first.wpilibj.tables.*;

Expand Down
7 changes: 7 additions & 0 deletions manualTests/java/Server.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

import edu.wpi.first.wpilibj.networktables.*;
import edu.wpi.first.wpilibj.tables.*;

Expand Down
22 changes: 14 additions & 8 deletions manualTests/native/client.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include <chrono>
#include <climits>
#include <cstdio>
Expand All @@ -7,20 +14,19 @@

int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::AddLogger(inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::StartClient(inst, "127.0.0.1", 10000);
std::this_thread::sleep_for(std::chrono::seconds(2));

auto foo = nt::GetEntry(inst, "/foo");
auto foo_val = nt::GetEntryValue(foo);
if (foo_val && foo_val->IsDouble())
printf("Got foo: %g\n", foo_val->GetDouble());
std::printf("Got foo: %g\n", foo_val->GetDouble());

auto bar = nt::GetEntry(inst, "/bar");
nt::SetEntryValue(bar, nt::Value::MakeBoolean(false));
Expand Down
22 changes: 14 additions & 8 deletions manualTests/native/rpc_local.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include <chrono>
#include <climits>
#include <cstdio>
#include <thread>

#include "support/json.h"
#include <support/json.h>

#include "ntcore.h"

Expand All @@ -27,13 +34,12 @@ void callback1(const nt::RpcAnswer& answer) {

int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::AddLogger(inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);

nt::StartServer(inst, "rpc_local.ini", "", 10000);
auto entry = nt::GetEntry(inst, "func1");
Expand Down
29 changes: 21 additions & 8 deletions manualTests/native/rpc_speed.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include <chrono>
#include <climits>
#include <cstdio>
#include <thread>
#include <iostream>
#include <thread>

#include "support/json.h"
#include <support/json.h>

#include "ntcore.h"

Expand Down Expand Up @@ -33,7 +40,7 @@ int main() {

auto start2 = std::chrono::high_resolution_clock::now();
auto start = nt::Now();
for (int i=0; i<10000; ++i) {
for (int i = 0; i < 10000; ++i) {
unsigned int call1_uid = nt::CallRpc(entry, wpi::json::to_cbor(i));
nt::GetRpcResult(entry, call1_uid, &call1_result_str);
wpi::json call1_result;
Expand All @@ -51,11 +58,17 @@ int main() {
auto end2 = std::chrono::high_resolution_clock::now();
auto end = nt::Now();
std::cerr << "nt::Now start=" << start << " end=" << end << '\n';
std::cerr << "std::chrono start=" <<
std::chrono::duration_cast<std::chrono::nanoseconds>(start2.time_since_epoch()).count() << " end=" <<
std::chrono::duration_cast<std::chrono::nanoseconds>(end2.time_since_epoch()).count() << '\n';
std::fprintf(stderr, "time/call = %g us\n", (end-start) / 10.0 / 10000.0);
std::chrono::duration<double, std::micro> diff = end2-start2;
std::cerr << "std::chrono start="
<< std::chrono::duration_cast<std::chrono::nanoseconds>(
start2.time_since_epoch())
.count()
<< " end="
<< std::chrono::duration_cast<std::chrono::nanoseconds>(
end2.time_since_epoch())
.count()
<< '\n';
std::fprintf(stderr, "time/call = %g us\n", (end - start) / 10.0 / 10000.0);
std::chrono::duration<double, std::micro> diff = end2 - start2;
std::cerr << "time/call = " << (diff.count() / 10000.0) << " us\n";

return 0;
Expand Down
20 changes: 13 additions & 7 deletions manualTests/native/server.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2017. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

#include <chrono>
#include <climits>
#include <cstdio>
Expand All @@ -7,13 +14,12 @@

int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::AddLogger(inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::StartServer(inst, "persistent.ini", "", 10000);
std::this_thread::sleep_for(std::chrono::seconds(1));

Expand Down
4 changes: 2 additions & 2 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ model {
destinationDir = outputsFolder
duplicatesStrategy = 'exclude'

ntcoreJNITaskList.each {
ntcoreJNITaskList.each {
it.outputs.files.each {
from project.zipTree(it)
}
Expand All @@ -210,7 +210,7 @@ model {
destinationDir = outputsFolder
duplicatesStrategy = 'exclude'

ntcoreTaskList.each {
ntcoreTaskList.each {
it.outputs.files.each {
from project.zipTree(it)
}
Expand Down
Loading

0 comments on commit 19f7a5f

Please sign in to comment.