Skip to content

Commit

Permalink
feat: Add proper support for IBM i
Browse files Browse the repository at this point in the history
Python 3.9 on IBM i now properly returns "os400" for sys.platform
instead of claiming to be AIX as it did previously. While the IBM i PASE
environment is compatible with AIX, it is a subset and has numerous
differences which makes it beneficial to distinguish, however this means
that it now needs explicit support here.
  • Loading branch information
kadler committed Mar 3, 2022
1 parent 245cd5b commit 8f41ead
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions addon.gypi
Expand Up @@ -103,6 +103,11 @@
'-Wl,-bimport:<(node_exp_file)'
],
}],
[ 'OS=="os400"', {
'ldflags': [
'-Wl,-bimport:<(node_exp_file)'
],
}],
[ 'OS=="zos"', {
'cflags': [
'-q64',
Expand Down
12 changes: 9 additions & 3 deletions gyp/pylib/gyp/common.py
Expand Up @@ -454,6 +454,8 @@ def GetFlavor(params):
return "aix"
if sys.platform.startswith(("os390", "zos")):
return "zos"
if sys.platform == "os400":
return "os400"

return "linux"

Expand All @@ -463,9 +465,13 @@ def CopyTool(flavor, out_path, generator_flags={}):
to |out_path|."""
# aix and solaris just need flock emulation. mac and win use more complicated
# support scripts.
prefix = {"aix": "flock", "solaris": "flock", "mac": "mac", "win": "win"}.get(
flavor, None
)
prefix = {
"aix": "flock",
"os400": "flock",
"solaris": "flock",
"mac": "mac",
"win": "win",
}.get(flavor, None)
if not prefix:
return

Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/flock_tool.py
Expand Up @@ -41,7 +41,7 @@ def ExecFlock(self, lockfile, *cmd_list):
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
if sys.platform.startswith("aix"):
if sys.platform.startswith("aix") or sys.platform == "os400":
# Python on AIX is compiled with LARGEFILE support, which changes the
# struct size.
op = struct.pack("hhIllqq", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
Expand Down
1 change: 1 addition & 0 deletions gyp/test_gyp.py
Expand Up @@ -116,6 +116,7 @@ def main(argv=None):
else:
format_list = {
"aix5": ["make"],
"os400": ["make"],
"freebsd7": ["make"],
"freebsd8": ["make"],
"openbsd5": ["make"],
Expand Down
2 changes: 2 additions & 0 deletions lib/build.js
Expand Up @@ -11,6 +11,8 @@ function build (gyp, argv, callback) {
var platformMake = 'make'
if (process.platform === 'aix') {
platformMake = 'gmake'
} else if (process.platform === 'os400') {
platformMake = 'gmake'
} else if (process.platform.indexOf('bsd') !== -1) {
platformMake = 'gmake'
} else if (win && argv.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions lib/configure.js
Expand Up @@ -153,12 +153,12 @@ function configure (gyp, argv, callback) {
// For AIX and z/OS we need to set up the path to the exports file
// which contains the symbols needed for linking.
var nodeExpFile
if (process.platform === 'aix' || process.platform === 'os390') {
var ext = process.platform === 'aix' ? 'exp' : 'x'
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
var ext = process.platform === 'os390' ? 'x' : 'exp'
var nodeRootDir = findNodeDirectory()
var candidates

if (process.platform === 'aix') {
if (process.platform === 'aix' || process.platform === 'os400') {
candidates = [
'include/node/node',
'out/Release/node',
Expand Down Expand Up @@ -215,7 +215,7 @@ function configure (gyp, argv, callback) {
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
if (process.platform === 'aix' || process.platform === 'os390') {
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
argv.push('-Dnode_exp_file=' + nodeExpFile)
}
argv.push('-Dnode_gyp_dir=' + nodeGypDir)
Expand Down
2 changes: 1 addition & 1 deletion test/test-find-node-directory.js
Expand Up @@ -4,7 +4,7 @@ const test = require('tap').test
const path = require('path')
const findNodeDirectory = require('../lib/find-node-directory')

const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']
const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix', 'os400']

// we should find the directory based on the directory
// the script is running in and it should match the layout
Expand Down

0 comments on commit 8f41ead

Please sign in to comment.