Skip to content

Commit 60c4e81

Browse files
ygoumazomichel
andauthored
Simplify tmp directory computation for extern controllers (#6002)
* reorganize and comment system.c * Simplify tmp dir computation * comments * Update system.c * fix cpp check error * fix cppcheck ubuntu * clang format 11 * Fixed cppcheck * print clang format info * Force version 11 * pip uninstall * remove initial version * fix * Fixed clang format * fix macOS * Update tests_sources.yml * Update tests_sources.yml * install cf macOS * fix c-f * install llvm instead * install c-f 14 on macOS * fix cf install * Update latest script and cleanup * Update changelog-r2023.md --------- Co-authored-by: Olivier Michel <[email protected]>
1 parent 97bdea0 commit 60c4e81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+526
-223
lines changed

.github/workflows/tests_sources.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ jobs:
3434
strategy:
3535
fail-fast: false
3636
matrix:
37-
os: [ubuntu-20.04, macos-11, windows-2019]
37+
os: [ubuntu-22.04, macos-11, windows-2019]
3838
python: [3.9]
3939
include:
40-
- os: ubuntu-20.04
41-
DEPENDENCIES_INSTALLATION: "sudo apt -y install clang-format-10 cppcheck"
40+
- os: ubuntu-22.04
41+
DEPENDENCIES_INSTALLATION: "sudo apt -y install cppcheck"
4242
- os: macos-11
43-
DEPENDENCIES_INSTALLATION: "brew tap-new --no-git $USER/local-cppcheck; brew extract --version=2.10 cppcheck $USER/local-cppcheck; brew install [email protected]; brew install clang-format@11; ln /usr/local/bin/clang-format-11 /usr/local/bin/clang-format"
43+
DEPENDENCIES_INSTALLATION: "brew tap-new --no-git $USER/local-cppcheck; brew extract --version=2.10 cppcheck $USER/local-cppcheck; brew install [email protected]; brew tap-new --no-git $USER/local-clang-format; brew extract --version=14.0.0 clang-format $USER/local-clang-format; brew install [email protected]"
4444
- os: windows-2019
45-
DEPENDENCIES_INSTALLATION: "choco install -y cppcheck --version=2.10 || true; choco uninstall -y llvm; choco install -y llvm --version=13.0.1; export PATH=$PATH:\"/c/Program Files/Cppcheck:/c/Program Files/LLVM/bin\""
45+
DEPENDENCIES_INSTALLATION: "choco install -y cppcheck --version=2.10 || true; choco uninstall -y llvm; choco install -y llvm --version=14.0.0; export PATH=$PATH:\"/c/Program Files/Cppcheck:/c/Program Files/LLVM/bin\""
4646
runs-on: ${{ matrix.os }}
4747
if: needs.job-skipper.outputs.should_skip != 'true'
4848
steps:
4949
- name: OS check
50-
if: (matrix.os == 'ubuntu-20.04' && matrix.python == '3.9') || github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
50+
if: (matrix.os == 'ubuntu-22.04' && matrix.python == '3.9') || github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
5151
run: |
5252
echo "::set-output name=job_needed::true"
5353
id: os_check

.github/workflows/tests_sources_with_latest_cppcheck.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ jobs:
3030
strategy:
3131
fail-fast: false
3232
matrix:
33-
os: [ubuntu-20.04, macos-11, windows-2019]
33+
os: [ubuntu-22.04, macos-11, windows-2019]
3434
python: [3.9]
3535
include:
36-
- os: ubuntu-20.04
37-
DEPENDENCIES_INSTALLATION: "sudo apt -y install clang-format-10 cppcheck"
36+
- os: ubuntu-22.04
37+
DEPENDENCIES_INSTALLATION: "sudo apt -y install cppcheck"
3838
- os: macos-11
39-
DEPENDENCIES_INSTALLATION: "brew install clang-format@11 cppcheck; ln /usr/local/bin/clang-format-11 /usr/local/bin/clang-format"
39+
DEPENDENCIES_INSTALLATION: "brew install cppcheck; brew tap-new --no-git $USER/local-clang-format; brew extract --version=14.0.0 clang-format $USER/local-clang-format; brew install [email protected]"
4040
- os: windows-2019
41-
DEPENDENCIES_INSTALLATION: "choco install -y cppcheck || true; choco uninstall -y llvm; choco install -y llvm --version=13.0.1; export PATH=$PATH:\"/c/Program Files/Cppcheck:/c/Program Files/LLVM/bin\""
41+
DEPENDENCIES_INSTALLATION: "choco install -y cppcheck || true; choco uninstall -y llvm; choco install -y llvm --version=14.0.0; export PATH=$PATH:\"/c/Program Files/Cppcheck:/c/Program Files/LLVM/bin\""
4242
runs-on: ${{ matrix.os }}
4343
if: needs.job-skipper.outputs.should_skip != 'true'
4444
steps:
4545
- name: OS check
46-
if: (matrix.os == 'ubuntu-20.04' && matrix.python == '3.9') || github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
46+
if: (matrix.os == 'ubuntu-22.04' && matrix.python == '3.9') || github.event_name == 'schedule' || github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'test sources')
4747
run: |
4848
echo "::set-output name=job_needed::true"
4949
id: os_check

docs/reference/changelog-r2023.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Released on ??
4949
- Fixed bug causing Webots to hang when requesting multiple poses while pose-tracking multiple nodes ([#5952](https://github.com/cyberbotics/webots/pull/5952)).
5050
- Fixed physics state updates of [Solid](solid.md) nodes added to a descendant [`Joint.endPoint`](joint.md) during simulation ([#5961](https://github.com/cyberbotics/webots/pull/5961)).
5151
- Fixed unwanted altitude change when reaching a target waypoint in `mavic2pro_patrol.c` ([#5981](https://github.com/cyberbotics/webots/pull/5981)).
52+
- Fixed the extern controller connection to a target Webots instance when a snap one is running. ([#6002](https://github.com/cyberbotics/webots/pull/6002)).
5253

5354
## Webots R2023a
5455
Released on November 29th, 2022.

projects/default/controllers/ros/highlevel/RosControl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ namespace highlevel {
3636
mLastUpdate = ros::Time::now();
3737
}
3838

39-
void RosControl::write() { mWebotsHW->write(); }
39+
void RosControl::write() {
40+
mWebotsHW->write();
41+
}
4042
} // namespace highlevel

projects/robots/epfl/lis/controllers/blimp/js.h

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -467,25 +467,53 @@ class jsJoystick {
467467
#endif
468468
}
469469

470-
~jsJoystick() { close(); }
470+
~jsJoystick() {
471+
close();
472+
}
471473

472-
int getNumAxes() const { return num_axes; }
473-
int notWorking() const { return error; }
474-
void setError() { error = JS_TRUE; }
474+
int getNumAxes() const {
475+
return num_axes;
476+
}
477+
int notWorking() const {
478+
return error;
479+
}
480+
void setError() {
481+
error = JS_TRUE;
482+
}
475483

476-
float getDeadBand(int axis) const { return dead_band[axis]; }
477-
void setDeadBand(int axis, float db) { dead_band[axis] = db; }
484+
float getDeadBand(int axis) const {
485+
return dead_band[axis];
486+
}
487+
void setDeadBand(int axis, float db) {
488+
dead_band[axis] = db;
489+
}
478490

479-
float getSaturation(int axis) const { return saturate[axis]; }
480-
void setSaturation(int axis, float st) { saturate[axis] = st; }
491+
float getSaturation(int axis) const {
492+
return saturate[axis];
493+
}
494+
void setSaturation(int axis, float st) {
495+
saturate[axis] = st;
496+
}
481497

482-
void setMinRange(float *axes) { memcpy(min, axes, num_axes * sizeof(float)); }
483-
void setMaxRange(float *axes) { memcpy(max, axes, num_axes * sizeof(float)); }
484-
void setCenter(float *axes) { memcpy(center, axes, num_axes * sizeof(float)); }
498+
void setMinRange(float *axes) {
499+
memcpy(min, axes, num_axes * sizeof(float));
500+
}
501+
void setMaxRange(float *axes) {
502+
memcpy(max, axes, num_axes * sizeof(float));
503+
}
504+
void setCenter(float *axes) {
505+
memcpy(center, axes, num_axes * sizeof(float));
506+
}
485507

486-
void getMinRange(float *axes) { memcpy(axes, min, num_axes * sizeof(float)); }
487-
void getMaxRange(float *axes) { memcpy(axes, max, num_axes * sizeof(float)); }
488-
void getCenter(float *axes) { memcpy(axes, center, num_axes * sizeof(float)); }
508+
void getMinRange(float *axes) {
509+
memcpy(axes, min, num_axes * sizeof(float));
510+
}
511+
void getMaxRange(float *axes) {
512+
memcpy(axes, max, num_axes * sizeof(float));
513+
}
514+
void getCenter(float *axes) {
515+
memcpy(axes, center, num_axes * sizeof(float));
516+
}
489517

490518
void read(int *buttons, float *axes) {
491519
if (error) {

src/controller/c/system.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,40 +84,43 @@ const char *wbu_system_short_path(const char *path) {
8484
#endif
8585
}
8686

87+
// path to the 'webots-%d' folder computed by Webots instance
88+
// intern controllers only
89+
const char *wbu_system_webots_instance_path(bool refresh) {
90+
static const char *WEBOTS_INSTANCE_PATH = NULL;
91+
if (WEBOTS_INSTANCE_PATH && !refresh)
92+
return WEBOTS_INSTANCE_PATH;
93+
WEBOTS_INSTANCE_PATH = getenv("WEBOTS_INSTANCE_PATH");
94+
if (WEBOTS_INSTANCE_PATH && WEBOTS_INSTANCE_PATH[0])
95+
return WEBOTS_INSTANCE_PATH;
96+
return NULL;
97+
}
98+
99+
// compute the path to the tmp directory
100+
// extern controllers only
87101
const char *wbu_system_tmpdir() {
88102
static char *tmpdir = NULL;
89103
if (tmpdir)
90104
return tmpdir;
91-
// if WEBOTS_TMPDIR environment variable is defined, use it for the tmpdir
92-
const char *WEBOTS_TMPDIR = getenv("WEBOTS_TMPDIR");
93-
if (WEBOTS_TMPDIR && WEBOTS_TMPDIR[0]) {
94-
tmpdir = (char *)WEBOTS_TMPDIR;
95-
return tmpdir;
96-
}
97105
#ifdef _WIN32
98106
const char *LOCALAPPDATA = getenv("LOCALAPPDATA");
99107
assert(LOCALAPPDATA && LOCALAPPDATA[0]);
100108
const size_t len = strlen(LOCALAPPDATA) + 6; // adding "\\Temp"
101109
tmpdir = malloc(len);
102110
snprintf(tmpdir, len, "%s\\Temp", LOCALAPPDATA);
103111
#elif defined(__linux__)
104-
// if the ~/.WEBOTS_TMPDIR directory exists and contains some webots-* files,
105-
// use it as the tmpdir, otherwise fallback to /tmp
106-
const char *HOME = getenv("HOME");
107-
if (HOME && HOME[0]) {
108-
const size_t len = strlen(HOME) + strlen("/snap/webots/common/tmp") + 1;
109-
char *path = malloc(len);
110-
snprintf(path, len, "%s/snap/webots/common/tmp", HOME);
111-
DIR *dir = opendir(path);
112-
if (dir) {
113-
struct dirent *entry;
114-
while ((entry = readdir(dir))) {
115-
if (strncmp(entry->d_name, "webots-", 7) == 0) {
116-
tmpdir = path;
117-
break;
118-
}
112+
// choose between snap or default tmp path
113+
const char *WEBOTS_HOME = getenv("WEBOTS_HOME");
114+
if (WEBOTS_HOME && WEBOTS_HOME[0]) {
115+
// if WEBOTS_HOME environment variable contains snap path, use snap tmp folder
116+
if (strstr(WEBOTS_HOME, "/snap/webots") != NULL) {
117+
const char *HOME = getenv("HOME");
118+
if (HOME && HOME[0]) {
119+
const size_t len = strlen(HOME) + strlen("/snap/webots/common/tmp") + 1;
120+
char *path = malloc(len);
121+
snprintf(path, len, "%s/snap/webots/common/tmp", HOME);
122+
tmpdir = path;
119123
}
120-
closedir(dir);
121124
}
122125
}
123126
if (tmpdir == NULL)
@@ -131,13 +134,3 @@ const char *wbu_system_tmpdir() {
131134
#endif
132135
return tmpdir;
133136
}
134-
135-
const char *wbu_system_webots_instance_path(bool refresh) {
136-
static const char *WEBOTS_INSTANCE_PATH = NULL;
137-
if (WEBOTS_INSTANCE_PATH && !refresh)
138-
return WEBOTS_INSTANCE_PATH;
139-
WEBOTS_INSTANCE_PATH = getenv("WEBOTS_INSTANCE_PATH");
140-
if (WEBOTS_INSTANCE_PATH && WEBOTS_INSTANCE_PATH[0])
141-
return WEBOTS_INSTANCE_PATH;
142-
return NULL;
143-
}

src/webots/core/WbSysInfo.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ namespace WbSysInfo {
2929
#ifdef __linux__
3030
const QString &linuxCpuModelName();
3131
bool isRootUser();
32-
inline bool isSnap() { return qgetenv("SNAP_NAME") == "webots"; }
32+
inline bool isSnap() {
33+
return qgetenv("SNAP_NAME") == "webots";
34+
}
3335
#else
34-
inline bool isSnap() { return false; }
36+
inline bool isSnap() {
37+
return false;
38+
}
3539
#endif
3640
QString environmentVariable(const QString &name);
3741
void setEnvironmentVariable(const QString &name, const QString &value);

src/webots/gui/WbNewControllerWizard.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class WbLanguageWizardPage : public QWizardPage {
9292
#endif
9393
return WbNewControllerWizard::NAME;
9494
}
95-
void setButtonGroup(const QButtonGroup *buttonGroup) { mButtonGroup = buttonGroup; }
95+
void setButtonGroup(const QButtonGroup *buttonGroup) {
96+
mButtonGroup = buttonGroup;
97+
}
9698

9799
private:
98100
const QButtonGroup *mButtonGroup;

src/webots/maths/WbMathsUtilities.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ namespace WbMathsUtilities {
3232
bool isPowerOf2(unsigned int n);
3333
unsigned int nextPowerOf2(unsigned int n);
3434
int round(double n);
35-
inline double discretize(double value, double resolution) { return ((int)(value / resolution + 0.5)) * resolution; }
36-
inline double discretize(float value, float resolution) { return ((int)(value / resolution + 0.5f)) * resolution; }
35+
inline double discretize(double value, double resolution) {
36+
return ((int)(value / resolution + 0.5)) * resolution;
37+
}
38+
inline double discretize(float value, float resolution) {
39+
return ((int)(value / resolution + 0.5f)) * resolution;
40+
}
3741

3842
// performs two Graham scan and returns the indices of points in the convex hull
3943
int twoStepsConvexHull(const QVector<WbVector2> &points, QVector<int> &hullIndices);

src/webots/nodes/WbAbstractCamera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ WbAbstractCamera::WbAbstractCamera(const QString &modelName, WbTokenizer *tokeni
9898
init();
9999
}
100100

101-
WbAbstractCamera::WbAbstractCamera(const WbAbstractCamera &other) : WbRenderingDevice(other) {
101+
WbAbstractCamera::WbAbstractCamera(const WbAbstractCamera &other) : WbRenderingDevice(other), mInvisibleNodes() {
102102
init();
103103
}
104104

0 commit comments

Comments
 (0)