Skip to content

Commit

Permalink
Support trace log (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Feb 3, 2024
1 parent 186be10 commit ea9ab88
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 167 deletions.
12 changes: 8 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ CheckOptions:
value: ^[cij]$

# https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html

# CamelCase represents types and enum constants.
- key: readability-identifier-naming.AbstractClassCase
value: CamelCase
- key: readability-identifier-naming.ClassCase
Expand All @@ -64,23 +66,25 @@ CheckOptions:
- key: readability-identifier-naming.EnumConstantCase
value: CamelCase

# camelBack represents data.
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.MethodCase
value: camelBack
- key: readability-identifier-naming.VariableCase
value: camelBack
- key: readability-identifier-naming.LocalConstantCase
value: camelBack
- key: readability-identifier-naming.LocalVariableCase
value: camelBack
- key: readability-identifier-naming.MemberCase
value: camelBack
- key: readability-identifier-naming.NamespaceCase
value: camelBack

# UPPER_CASE represents something shared across the entire program.
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.StaticVariableCase
value: UPPER_CASE
- key: readability-identifier-naming.ConstexprVariableCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalVariableCase
Expand Down
15 changes: 15 additions & 0 deletions .github/actions/setup-macos-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Setup macOS dependencies"
description: "Setup macOS dependencies"

runs:
using: "composite"
steps:
- name: "Setup dependencies"
run: |
brew install \
curl \
fmt \
libgit2 \
nlohmann-json \
tbb
shell: "bash"
16 changes: 16 additions & 0 deletions .github/actions/setup-ubuntu-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Setup Ubuntu dependencies"
description: "Setup Ubuntu dependencies"

runs:
using: "composite"
steps:
- name: "Setup dependencies"
run: |
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev \
libfmt-dev \
libgit2-dev \
nlohmann-json3-dev \
libtbb-dev
shell: "bash"
10 changes: 2 additions & 8 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ jobs:
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev \
libgit2-dev \
nlohmann-json3-dev \
libtbb-dev
- name: Setup dependencies
uses: ./.github/actions/setup-ubuntu-deps

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev \
libgit2-dev \
nlohmann-json3-dev \
libtbb-dev
- name: Setup dependencies
uses: ./.github/actions/setup-ubuntu-deps

- name: Build Poac
run: make RELEASE=1
Expand All @@ -46,14 +40,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev \
libgit2-dev \
nlohmann-json3-dev \
libtbb-dev
- name: Setup dependencies
uses: ./.github/actions/setup-ubuntu-deps

- name: Build Poac
run: make RELEASE=1
Expand All @@ -75,14 +63,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev \
libgit2-dev \
nlohmann-json3-dev \
libtbb-dev
- name: Setup dependencies
uses: ./.github/actions/setup-ubuntu-deps

- name: Build Poac
run: make RELEASE=1
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ jobs:
chmod +x ./llvm.sh
sudo ./llvm.sh ${{ matrix.compiler.ver }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev \
libgit2-dev \
nlohmann-json3-dev \
libtbb-dev
- name: Setup dependencies
uses: ./.github/actions/setup-ubuntu-deps

- name: Print versions
run: make versions
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
brew install \
curl \
libgit2 \
nlohmann-json \
tbb
- name: Setup dependencies
uses: ./.github/actions/setup-macos-deps

- name: Print versions
run: make versions
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ INCLUDES := -isystem $(O)/DEPS/toml11 \
$(shell pkg-config --cflags 'libgit2 >= 1.1.0, libgit2 < 2.0.0') \
$(shell pkg-config --cflags 'libcurl >= 7.79.1, libcurl < 9.0.0') \
$(shell pkg-config --cflags 'nlohmann_json >= 3.10.5, nlohmann_json < 4.0.0') \
$(shell pkg-config --cflags 'tbb >= 2021.5.0, tbb < 2022.0.0')
$(shell pkg-config --cflags 'tbb >= 2021.5.0, tbb < 2022.0.0') \
$(shell pkg-config --cflags 'fmt >= 8.1.1, fmt < 11.0.0')
LIBS := $(shell pkg-config --libs 'libgit2 >= 1.1.0, libgit2 < 2.0.0') \
$(shell pkg-config --libs 'libcurl >= 7.79.1, libcurl < 9.0.0') \
$(shell pkg-config --libs 'tbb >= 2021.5.0, tbb < 2022.0.0')
$(shell pkg-config --libs 'tbb >= 2021.5.0, tbb < 2022.0.0') \
$(shell pkg-config --libs 'fmt >= 8.1.1, fmt < 11.0.0')

SRCS := $(shell find src -name '*.cc')
OBJS := $(patsubst src/%,$(O)/%,$(SRCS:.cc=.o))
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ If your environment is not included in the released packages, you have to build

#### Libraries

* fmt: `>=8.1.1 && <11`
* `libfmt-dev` on APT
* `fmt` on Homebrew
* libgit2: `>=1.1.0 && <2`
* `libgit2-dev` on APT
* `libgit2` on Homebrew
Expand Down
1 change: 1 addition & 0 deletions poac.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version = "0.9.3"

[dependencies]
"ToruNiina/toml11" = {git = "https://github.com/ToruNiina/toml11.git", tag = "v3.8.0"}
fmt = {version = ">=8.1.1 && <11", system = true}
libcurl = {version = ">=7.79.1 && <9", system = true}
libgit2 = {version = "1.1.0", system = true}
nlohmann_json = {version = "3.10.5", system = true}
Expand Down
62 changes: 31 additions & 31 deletions src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ execCmd(const StringRef cmd) noexcept {

static std::pair<String, int>
getCmdOutputImpl(const StringRef cmd) {
constexpr usize BUFFER_SIZE = 128;
std::array<char, BUFFER_SIZE> buffer{};
constexpr usize bufferSize = 128;
std::array<char, bufferSize> buffer{};
String output;

FILE* pipe = popen(cmd.data(), "r");
Expand Down Expand Up @@ -189,16 +189,16 @@ testLevDistance() {

void
testLevDistance2() {
constexpr StringRef STR1 = "\nMäry häd ä little lämb\n\nLittle lämb\n";
constexpr StringRef STR2 = "\nMary häd ä little lämb\n\nLittle lämb\n";
constexpr StringRef STR3 = "Mary häd ä little lämb\n\nLittle lämb\n";
constexpr StringRef str1 = "\nMäry häd ä little lämb\n\nLittle lämb\n";
constexpr StringRef str2 = "\nMary häd ä little lämb\n\nLittle lämb\n";
constexpr StringRef str3 = "Mary häd ä little lämb\n\nLittle lämb\n";

assertEq(levDistance(STR1, STR2), 2UL);
assertEq(levDistance(STR2, STR1), 2UL);
assertEq(levDistance(STR1, STR3), 3UL);
assertEq(levDistance(STR3, STR1), 3UL);
assertEq(levDistance(STR2, STR3), 1UL);
assertEq(levDistance(STR3, STR2), 1UL);
assertEq(levDistance(str1, str2), 2UL);
assertEq(levDistance(str2, str1), 2UL);
assertEq(levDistance(str1, str3), 3UL);
assertEq(levDistance(str3, str1), 3UL);
assertEq(levDistance(str2, str3), 1UL);
assertEq(levDistance(str3, str2), 1UL);

assertEq(levDistance("b", "bc"), 1UL);
assertEq(levDistance("ab", "abc"), 1UL);
Expand All @@ -218,36 +218,36 @@ testLevDistance2() {

void
testFindSimilarStr() {
constexpr Arr<StringRef, 8> CANDIDATES{
constexpr Arr<StringRef, 8> candidates{
"if", "ifdef", "ifndef", "elif", "else", "endif", "elifdef", "elifndef"
};

assertEq(findSimilarStr("id", CANDIDATES), "if"sv);
assertEq(findSimilarStr("ifd", CANDIDATES), "if"sv);
assertEq(findSimilarStr("ifde", CANDIDATES), "ifdef"sv);
assertEq(findSimilarStr("elf", CANDIDATES), "elif"sv);
assertEq(findSimilarStr("elsif", CANDIDATES), "elif"sv);
assertEq(findSimilarStr("elseif", CANDIDATES), "elif"sv);
assertEq(findSimilarStr("elfidef", CANDIDATES), "elifdef"sv);
assertEq(findSimilarStr("elfindef", CANDIDATES), "elifdef"sv);
assertEq(findSimilarStr("elfinndef", CANDIDATES), "elifndef"sv);
assertEq(findSimilarStr("els", CANDIDATES), "else"sv);
assertEq(findSimilarStr("endi", CANDIDATES), "endif"sv);

assertEq(findSimilarStr("i", CANDIDATES), None);
assertEq(findSimilarStr("special_compiler_directive", CANDIDATES), None);
assertEq(findSimilarStr("id", candidates), "if"sv);
assertEq(findSimilarStr("ifd", candidates), "if"sv);
assertEq(findSimilarStr("ifde", candidates), "ifdef"sv);
assertEq(findSimilarStr("elf", candidates), "elif"sv);
assertEq(findSimilarStr("elsif", candidates), "elif"sv);
assertEq(findSimilarStr("elseif", candidates), "elif"sv);
assertEq(findSimilarStr("elfidef", candidates), "elifdef"sv);
assertEq(findSimilarStr("elfindef", candidates), "elifdef"sv);
assertEq(findSimilarStr("elfinndef", candidates), "elifndef"sv);
assertEq(findSimilarStr("els", candidates), "else"sv);
assertEq(findSimilarStr("endi", candidates), "endif"sv);

assertEq(findSimilarStr("i", candidates), None);
assertEq(findSimilarStr("special_compiler_directive", candidates), None);

pass();
}

void
testFindSimilarStr2() {
constexpr Arr<StringRef, 2> CANDIDATES{ "aaab", "aaabc" };
assertEq(findSimilarStr("aaaa", CANDIDATES), "aaab"sv);
assertEq(findSimilarStr("1111111111", CANDIDATES), None);
constexpr Arr<StringRef, 2> candidates{ "aaab", "aaabc" };
assertEq(findSimilarStr("aaaa", candidates), "aaab"sv);
assertEq(findSimilarStr("1111111111", candidates), None);

constexpr Arr<StringRef, 1> CANDIDATES2{ "AAAA" };
assertEq(findSimilarStr("aaaa", CANDIDATES2), "AAAA"sv);
constexpr Arr<StringRef, 1> candidateS2{ "AAAA" };
assertEq(findSimilarStr("aaaa", candidateS2), "AAAA"sv);

pass();
}
Expand Down
15 changes: 7 additions & 8 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ struct BuildConfig {

static void
emitDep(std::ostream& os, usize& offset, const StringRef dep) {
constexpr usize MAX_LINE_LEN = 80;
if (offset + dep.size() + 2 > MAX_LINE_LEN) { // 2 for space and \.
constexpr usize maxLineLen = 80;
if (offset + dep.size() + 2 > maxLineLen) { // 2 for space and \.
// \ for line continuation. \ is the 80th character.
os << std::setw(static_cast<int>(MAX_LINE_LEN + 3 - offset)) << " \\\n ";
os << std::setw(static_cast<int>(maxLineLen + 3 - offset)) << " \\\n ";
offset = 2;
}
os << ' ' << dep;
Expand Down Expand Up @@ -232,15 +232,14 @@ BuildConfig::emitVariable(std::ostream& os, const String& varName) const {
const String left = oss.str();
os << left << ' ';

constexpr usize MAX_LINE_LEN = 80; // TODO: share across sources?
constexpr usize maxLineLen = 80; // TODO: share across sources?
usize offset = left.size() + 1; // space
String value;
for (const char c : variables.at(varName).value) {
if (c == ' ') {
// Emit value
if (offset + value.size() + 2 > MAX_LINE_LEN) { // 2 for space and '\'
os << std::setw(static_cast<int>(MAX_LINE_LEN + 3 - offset))
<< "\\\n ";
if (offset + value.size() + 2 > maxLineLen) { // 2 for space and '\'
os << std::setw(static_cast<int>(maxLineLen + 3 - offset)) << "\\\n ";
offset = 2;
}
os << value << ' ';
Expand Down Expand Up @@ -302,7 +301,7 @@ BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const {
continue;
}
if (cmd.find("-c") == String::npos) {
// Ignore linking commands.
// Ignore link commands.
continue;
}
isCompileTarget = true;
Expand Down
12 changes: 6 additions & 6 deletions src/Cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Opt::print(const usize maxShortSize, usize maxOffset) const noexcept {

if (shouldColor()) {
// Color escape sequences are not visible but affect std::setw.
constexpr usize COLOR_ESCAPE_SEQ_LEN = 31;
maxOffset += COLOR_ESCAPE_SEQ_LEN;
constexpr usize colorEscapeSeqLen = 31;
maxOffset += colorEscapeSeqLen;
}
setOffset(maxOffset);
std::cout << option << desc;
Expand Down Expand Up @@ -147,8 +147,8 @@ Arg::print(usize maxOffset) const noexcept {
const String left = getLeft();
if (shouldColor()) {
// Color escape sequences are not visible but affect std::setw.
constexpr usize COLOR_ESCAPE_SEQ_LEN = 9;
maxOffset += COLOR_ESCAPE_SEQ_LEN;
constexpr usize colorEscapeSeqLen = 9;
maxOffset += colorEscapeSeqLen;
}
setOffset(maxOffset);
std::cout << left;
Expand Down Expand Up @@ -271,8 +271,8 @@ Subcmd::print(usize maxOffset) const noexcept {

if (shouldColor()) {
// Color escape sequences are not visible but affect std::setw.
constexpr usize COLOR_ESCAPE_SEQ_LEN = 22;
maxOffset += COLOR_ESCAPE_SEQ_LEN;
constexpr usize colorEscapeSeqLen = 22;
maxOffset += colorEscapeSeqLen;
}
setOffset(maxOffset);
std::cout << cmdStr << desc << '\n';
Expand Down
2 changes: 2 additions & 0 deletions src/Cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
return getCmd().printHelp(HELP_ARGS); \
} else if (arg == "-v" || arg == "--verbose") { \
logger::setLevel(logger::Level::Debug); \
} else if (arg == "-vv") { \
logger::setLevel(logger::Level::Trace); \
} else if (arg == "-q" || arg == "--quiet") { \
logger::setLevel(logger::Level::Off); \
} else if (arg == "--color") { \
Expand Down
Loading

0 comments on commit ea9ab88

Please sign in to comment.