From f4e5493ff2e39926d881d0e14ff9a50ec6700b48 Mon Sep 17 00:00:00 2001 From: Jonathon Love Date: Wed, 14 Feb 2024 17:11:47 +1100 Subject: [PATCH] Added support for separate arches under macos --- compilerr.js | 5 ++--- index.js | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/compilerr.js b/compilerr.js index f8daee5..8d2654f 100644 --- a/compilerr.js +++ b/compilerr.js @@ -12,7 +12,7 @@ const snapshots = require('./snapshots'); const temp = require('temp'); temp.track(); -const compile = function(srcDir, moduleDir, paths, packageInfo, log, options) { +const compile = function(srcDir, moduleDir, paths, packageInfo, rVersion, log, options) { options = options || {}; @@ -32,10 +32,9 @@ const compile = function(srcDir, moduleDir, paths, packageInfo, log, options) { break; } - let rVersion = packageInfo.rVersion; let snapshot = snapshots[rVersion]; let included = (packageInfo.name === 'jmv' ? snapshot.base_packages : snapshot.jmv_packages); - let buildDir = path.join(srcDir, 'build', `R${ rVersion }-${ platform }`); + let buildDir = path.join(srcDir, 'build', `R${ packageInfo.rVersion }-${ platform }`); let mirror = options.mirror || snapshot.mran_url; try { diff --git a/index.js b/index.js index 658693e..55228ce 100755 --- a/index.js +++ b/index.js @@ -221,7 +221,8 @@ try { rVersionOutput = child_process.execSync(cmd, { encoding: 'UTF-8', env: env }); } - let rVersion = /R version ([0-9]+\.[0-9]+\.[0-9]+)/g.exec(rVersionOutput); + let rVersion = /^R version ([0-9]+\.[0-9]+\.[0-9]+)/.exec(rVersionOutput); + let rArch = /Platform: ([^-]+)/.exec(rVersionOutput)[1]; if (rVersion === null && process.platform === 'win32') { rVersion = [ undefined, '3.4.1' ]; @@ -231,6 +232,18 @@ try { throw 'unable to determine R version'; rVersion = rVersion[1]; + if (rArch === 'aarch64') + rArch = 'arm64'; + else if (rArch == 'x86_64') + rArch = 'x64'; + + const versionParts = /^([0-9]+)\.([0-9]+)/.exec(rVersion); + const versionAsInt = 100 * parseInt(versionParts[1]) + parseInt(versionParts[2]); + + let rVersionAndArch = rVersion; + if (process.platform === 'darwin' && versionAsInt > 401) // macOS + > 4.1 + rVersionAndArch = `${ rVersion }-${ rArch }`; + let mirror; let skipRemotes = args['skip-remotes']; @@ -522,13 +535,13 @@ try { if (isBuilding || isInstallingTo) { - packageInfoLite.rVersion = rVersion; + packageInfoLite.rVersion = rVersionAndArch; content = '---\n' + yaml.safeDump(packageInfoLite) + '\n...\n'; fs.writeFileSync(path.join(modDir, 'jamovi.yaml'), content); console.log('wrote: jamovi.yaml'); - packageInfo.rVersion = rVersion; + packageInfo.rVersion = rVersionAndArch; content = '---\n' + yaml.safeDump(packageInfo) + '\n...\n'; fs.writeFileSync(path.join(modDir, 'jamovi-full.yaml'), content); @@ -543,7 +556,7 @@ try { } log.debug('compiling R package'); - compileR(srcDir, modDir, paths, packageInfo, log, { mirror, skipRemotes, skipDeps: args['skip-deps'] }); + compileR(srcDir, modDir, paths, packageInfo, rVersion, log, { mirror, skipRemotes, skipDeps: args['skip-deps'] }); log.debug('compiled'); if (isBuilding) {