Skip to content

Commit 0181fea

Browse files
authored
fixlink on ldflags (hmenyus#34)
1 parent e3bf22d commit 0181fea

3 files changed

Lines changed: 52 additions & 16 deletions

File tree

index.js

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,65 @@ const nodecallspython = require("./build/Release/nodecallspython");
55

66
class Interpreter
77
{
8+
loadPython(dir)
9+
{
10+
let found = false;
11+
const debug = process.env.NODECALLSPYTHON_DEBUG !== undefined;
12+
if (debug)
13+
console.log("Loading python from " + dir);
14+
15+
if (fs.existsSync(dir))
16+
{
17+
fs.readdirSync(dir).forEach(file => {
18+
if (file.match(/libpython.*\.so/))
19+
{
20+
try
21+
{
22+
const filename = path.join(dir, file);
23+
if (debug)
24+
console.log("Running fixlink on " + filename);
25+
26+
this.fixlink(filename);
27+
found = true;
28+
}
29+
catch(e)
30+
{
31+
console.error(e);
32+
}
33+
}
34+
});
35+
}
36+
37+
if (!found && debug)
38+
console.log("Not found");
39+
40+
return found;
41+
}
42+
843
constructor()
944
{
1045
this.py = new nodecallspython.PyInterpreter();
1146
if (process.platform === "linux")
1247
{
1348
const stdout = execSync("python3-config --configdir");
49+
let found = false;
1450
if (stdout)
1551
{
1652
const dir = stdout.toString().trim();
17-
if (fs.existsSync(dir))
53+
const res = this.loadPython(dir);
54+
if (res)
55+
found = true;
56+
}
57+
58+
if (!found)
59+
{
60+
const stdout = execSync("python3-config --ldflags");
61+
if (stdout)
1862
{
19-
fs.readdirSync(dir).forEach(file => {
20-
if (file.match(/libpython.*\.so/))
21-
{
22-
try
23-
{
24-
this.fixlink(path.join(dir, file));
25-
}
26-
catch(e)
27-
{
28-
console.error(e);
29-
}
30-
}
63+
const split = stdout.toString().trim().split(" ");
64+
split.forEach(s => {
65+
if (s.startsWith("-L"))
66+
this.loadPython(s.substring(2));
3167
});
3268
}
3369
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-calls-python",
3-
"version": "1.7.2",
3+
"version": "1.7.3",
44
"license": "MIT",
55
"description": "This module lets you run python code inside node without spawning new processes",
66
"authors": [

0 commit comments

Comments
 (0)