Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kqueue backend #149

Merged
merged 6 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
cache: yarn
node-version: ${{matrix.node}}
- run: yarn --frozen-lockfile --ignore-scripts
- run: npm install node-gyp -g
- run: yarn prebuild --arch ${{ matrix.arch }} -t ${{ matrix.node }}.0.0
env:
PREBUILD_LIBC: ${{ matrix.libc }}
Expand All @@ -72,10 +73,35 @@ jobs:
name: prebuilds
path: prebuilds

build-freebsd:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Build FreeBSD
uses: vmactions/freebsd-vm@v0
with:
usesh: true
prepare: |
pkg install -y -f curl node libnghttp2 npm yarn
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ yarn --version ~~~~"
yarn --version
run: |
yarn --frozen-lockfile --ignore-scripts
npm install node-gyp -g
yarn prebuild --arch x64 -t 16.0.0
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: prebuilds
path: prebuilds

release:
runs-on: ubuntu-latest
needs:
- build
- build-freebsd
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,20 @@ jobs:
watchman -v
- run: yarn --frozen-lockfile
- run: yarn test
test-freebsd:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Test in FreeBSD
uses: vmactions/freebsd-vm@v0
with:
usesh: true
prepare: |
pkg install -y -f curl node libnghttp2 npm yarn
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ yarn --version ~~~~"
yarn --version
run: |
yarn --frozen-lockfile
yarn test
20 changes: 18 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
"src/watchman/WatchmanBackend.cc",
"src/shared/BruteForceBackend.cc",
"src/unix/fts.cc",
"src/macos/FSEventsBackend.cc"
"src/macos/FSEventsBackend.cc",
"src/kqueue/KqueueBackend.cc"
],
"link_settings": {
"libraries": ["CoreServices.framework"]
},
"defines": [
"WATCHMAN",
"BRUTE_FORCE",
"FS_EVENTS"
"FS_EVENTS",
"KQUEUE"
],
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
Expand Down Expand Up @@ -65,6 +67,20 @@
"ExceptionHandling": 1, # /EHsc
}
}
}],
['OS=="freebsd"', {
"sources": [
"src/watchman/BSER.cc",
"src/watchman/WatchmanBackend.cc",
"src/shared/BruteForceBackend.cc",
"src/unix/fts.cc",
"src/kqueue/KqueueBackend.cc"
],
"defines": [
"WATCHMAN",
"BRUTE_FORCE",
"KQUEUE"
]
}]
]
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/build-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const triples = [
platform: 'android',
arch: 'arm64'
},
{
platform: 'freebsd',
arch: 'x64'
}
];

let optionalDependencies = {};
Expand Down
8 changes: 8 additions & 0 deletions src/Backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#ifdef INOTIFY
#include "linux/InotifyBackend.hh"
#endif
#ifdef KQUEUE
#include "kqueue/KqueueBackend.hh"
#endif
#include "shared/BruteForceBackend.hh"

#include "Backend.hh"
Expand Down Expand Up @@ -41,6 +44,11 @@ std::shared_ptr<Backend> getBackend(std::string backend) {
return std::make_shared<InotifyBackend>();
}
#endif
#ifdef KQUEUE
if (backend == "kqueue" || backend == "default") {
return std::make_shared<KqueueBackend>();
}
#endif
if (backend == "brute-force" || backend == "default") {
return std::make_shared<BruteForceBackend>();
}
Expand Down
11 changes: 4 additions & 7 deletions src/Event.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ public:
void remove(std::string path) {
std::lock_guard<std::mutex> l(mMutex);
Event *event = internalUpdate(path);
if (event->isCreated) {
// Ignore event when rapidly created and removed
mEvents.erase(path);
} else {
event->isDeleted = true;
}
event->isDeleted = true;
}

size_t size() {
Expand All @@ -63,7 +58,9 @@ public:
std::lock_guard<std::mutex> l(mMutex);
std::vector<Event> eventsCloneVector;
for(auto it = mEvents.begin(); it != mEvents.end(); ++it) {
eventsCloneVector.push_back(it->second);
if (!(it->second.isCreated && it->second.isDeleted)) {
eventsCloneVector.push_back(it->second);
}
}
return eventsCloneVector;
}
Expand Down
Loading