Skip to content

Commit 8330f4a

Browse files
committed
Abstract detectUbuntuCodename
1 parent 037e562 commit 8330f4a

4 files changed

Lines changed: 40 additions & 42 deletions

File tree

lib/native_loader.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,10 @@
1717
const fs = require('fs');
1818
const path = require('path');
1919
const debug = require('debug')('rclnodejs');
20+
const { detectUbuntuCodename } = require('./utils');
2021

2122
let nativeModule = null;
2223

23-
/**
24-
* Detect Ubuntu codename from /etc/os-release
25-
* @returns {string|null} Ubuntu codename (e.g., 'noble', 'jammy') or null
26-
*/
27-
function detectUbuntuCodename() {
28-
if (process.platform !== 'linux') {
29-
return null;
30-
}
31-
32-
try {
33-
const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
34-
const match = osRelease.match(/^VERSION_CODENAME=(.*)$/m);
35-
return match ? match[1].trim() : null;
36-
} catch {
37-
return null;
38-
}
39-
}
40-
4124
// Simplified loader: only use prebuilt binaries with exact Ubuntu/ROS2/arch match
4225
// Note: Prebuilt binaries are only supported on Linux (Ubuntu) platform
4326
function customFallbackLoader() {

lib/utils.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2025, The Robot Web Tools Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
const fs = require('fs');
16+
17+
/**
18+
* Detect Ubuntu codename from /etc/os-release
19+
* @returns {string|null} Ubuntu codename (e.g., 'noble', 'jammy') or null if not detectable
20+
*/
21+
function detectUbuntuCodename() {
22+
if (process.platform !== 'linux') {
23+
return null;
24+
}
25+
26+
try {
27+
const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
28+
const match = osRelease.match(/^VERSION_CODENAME=(.*)$/m);
29+
return match ? match[1].trim() : null;
30+
} catch (e) {
31+
return null;
32+
}
33+
}
34+
35+
module.exports = {
36+
detectUbuntuCodename,
37+
};

scripts/install.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,7 @@
1515
const fs = require('fs');
1616
const path = require('path');
1717
const { execSync } = require('child_process');
18-
19-
function detectUbuntuCodename() {
20-
if (process.platform !== 'linux') {
21-
return null;
22-
}
23-
24-
try {
25-
const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
26-
const match = osRelease.match(/^VERSION_CODENAME=(.*)$/m);
27-
return match ? match[1].trim() : null;
28-
} catch {
29-
return null;
30-
}
31-
}
18+
const { detectUbuntuCodename } = require('../lib/utils');
3219

3320
function getRosDistro() {
3421
return process.env.ROS_DISTRO || null;

scripts/tag_prebuilds.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@
1414

1515
const fs = require('fs');
1616
const path = require('path');
17-
18-
function detectUbuntuCodename() {
19-
try {
20-
const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
21-
const match = osRelease.match(/^VERSION_CODENAME=(.*)$/m);
22-
return match ? match[1].trim() : null;
23-
} catch (e) {
24-
return null;
25-
}
26-
}
17+
const { detectUbuntuCodename } = require('../lib/utils');
2718

2819
function tagPrebuilds() {
2920
const rosDistro = process.env.ROS_DISTRO;

0 commit comments

Comments
 (0)