Skip to content

Commit

Permalink
Fix missing headers for old python versions on darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoH2O1999 committed Feb 2, 2023
1 parent e842c78 commit 3314789
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
56 changes: 47 additions & 9 deletions src/builder/darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class MacOSBuilder extends Builder {
await this.prepareSources();
core.debug('Sources ready');

// Configuring flags
// Configure flags

const flags: string[] = [];
if (semver.lt(this.specificVersion, '3.0.0')) {
Expand All @@ -64,8 +64,8 @@ export default class MacOSBuilder extends Builder {
});
sqlite = sqlite.trim();
core.info(`sqlite3 module path: ${sqlite}`);
process.env['LDFLAGS'] += ` -L${sqlite}/lib`;
process.env['CFLAGS'] += ` -I${sqlite}/include`;
process.env['LDFLAGS'] += `-L${sqlite}/lib `;
process.env['CFLAGS'] += `-I${sqlite}/include `;
process.env['CPPFLAGS'] += `-I${sqlite}/include`;
}
if (semver.gte(this.specificVersion, '3.7.0')) {
Expand All @@ -78,13 +78,13 @@ export default class MacOSBuilder extends Builder {
flags.join(' ')
);

// Running ./configure
// Run ./configure

core.startGroup('Configuring makefile');
await exec.exec(configCommand, [], {cwd: this.path});
core.endGroup();

// Running make and make install
// Run make and make install

core.startGroup('Running make');
await exec.exec('make', [], {cwd: this.path});
Expand Down Expand Up @@ -123,7 +123,8 @@ export default class MacOSBuilder extends Builder {
stdout: (buffer: Buffer) => {
zlibPath = zlibPath.concat(buffer.toString());
}
}
},
silent: true
});
zlibPath = zlibPath.trim();
let readLinePath = '';
Expand All @@ -132,7 +133,8 @@ export default class MacOSBuilder extends Builder {
stdout: (buffer: Buffer) => {
readLinePath = readLinePath.concat(buffer.toString());
}
}
},
silent: true
});
readLinePath = readLinePath.trim();

Expand Down Expand Up @@ -166,10 +168,10 @@ export default class MacOSBuilder extends Builder {
if (semver.lt(this.specificVersion, '3.7.0')) {
process.env[
'LDFLAGS'
] += `-L${this.sslPath}/lib -L${zlibPath}/lib -L${readLinePath}/lib`;
] += `-L${this.sslPath}/lib -L${zlibPath}/lib -L${readLinePath}/lib `;
process.env[
'CFLAGS'
] += `-I${this.sslPath}/include -I${zlibPath}/include -I${readLinePath}/lib`;
] += `-I${this.sslPath}/include -I${zlibPath}/include -I${readLinePath}/include `;
}
core.info(`OpenSSL path: ${this.sslPath}`);

Expand Down Expand Up @@ -317,4 +319,40 @@ export default class MacOSBuilder extends Builder {
}
return additionalPaths;
}

protected override async prepareSources(): Promise<void> {
await super.prepareSources();

// Fix for missing header files

if (
semver.gte(this.specificVersion, '3.0.0') &&
semver.lt(this.specificVersion, '3.1.0')
) {
core.info(
'Detected Python version==3.0.x. Applying fix for missing headers...'
);
let headerPath = '';
await exec.exec('xcrun --sdk macosx --show-sdk-path', [], {
listeners: {
stdout: (buffer: Buffer) => {
headerPath = headerPath.concat(buffer.toString());
}
},
silent: true
});
headerPath = headerPath.trim();
const h2py = fs
.readFileSync(path.join(this.path, 'Tools', 'scripts', 'h2py.py'))
.toString()
.replace(
"fp = open(filename, 'r')",
`filename=filename.replace('/usr/lib', '${headerPath}/usr/lib').replace('/usr/include', '${headerPath}/usr/include');fp=open(filename, 'r')`
);
fs.writeFileSync(
path.join(this.path, 'Tools', 'scripts', 'h2py.py'),
h2py
);
}
}
}
2 changes: 1 addition & 1 deletion src/builder/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class LinuxBuilder extends Builder {
await this.prepareSources();
core.debug('Sources ready');

// Configuring flags
// Configure flags

const flags: string[] = [];
if (semver.lt(this.specificVersion, '3.0.0')) {
Expand Down
6 changes: 3 additions & 3 deletions src/builder/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class WindowsBuilder extends Builder {

core.startGroup('Installing Python to temp folder');

// Detecting installer full path
// Detect installer full path

let buildPath = path.join(this.path, 'PCbuild');
switch (this.arch) {
Expand All @@ -107,7 +107,7 @@ export default class WindowsBuilder extends Builder {
const installer = path.join(buildPath, candidates[0]);
core.info(`Installer: ${installer}`);

// Generating exec arguments
// Generate exec arguments

const execArguments: string[] = [
`TargetDir=${path.join(this.path, this.buildSuffix())}`,
Expand All @@ -134,7 +134,7 @@ export default class WindowsBuilder extends Builder {
);
}

// Cleaning environment
// Clean environment

core.debug('Cleaning environment...');
await this.cleanEnvironment();
Expand Down

0 comments on commit 3314789

Please sign in to comment.