From 68879847460273553e9c94a558c3ea8002edd351 Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 10 May 2024 16:53:58 +0100 Subject: [PATCH] Fix the value of the 'arch' variable when the current OS is 32bit on a 64bit machine --- master_changes.md | 2 ++ src/core/opamStd.ml | 13 ++++++++----- src/core/opamStd.mli | 3 +++ src/state/opamSysPoll.ml | 20 +++++++++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/master_changes.md b/master_changes.md index 47973be912d..0ad10fdaac1 100644 --- a/master_changes.md +++ b/master_changes.md @@ -61,6 +61,7 @@ users) ## Show ## Var/Option + * Fix the value of the 'arch' variable when the current OS is 32bit on a 64bit machine [#5950 @kit-ty-kate - fix #5949] ## Update / Upgrade @@ -261,3 +262,4 @@ users) * `OpamStd.Env`: add `env_string_list` for parsing string list environment variables (comma separated) [#5682 @desumn] * `OpamHash`: export `compare_kind` [#5561 @rjbou] * `OpamFilename`: add `might_escape` to check if a path is escapable, ie contains `..` [#5561 @rjbou] + * Add `OpamStd.Sys.getconf` [#5950 @kit-ty-kate] diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index e18e58849ca..142ccb59e59 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -995,19 +995,22 @@ module OpamSys = struct let etc () = "/etc" - let uname = + let memo_command = let memo = Hashtbl.create 7 in - fun arg -> - try Hashtbl.find memo arg with Not_found -> + fun cmd arg -> + try Hashtbl.find memo (cmd, arg) with Not_found -> let r = try - with_process_in "uname" arg + with_process_in cmd arg (fun ic -> Some (OpamString.strip (input_line ic))) with Unix.Unix_error _ | Sys_error _ | Not_found -> None in - Hashtbl.add memo arg r; + Hashtbl.add memo (cmd, arg) r; r + let uname = memo_command "uname" + let getconf = memo_command "getconf" + let system = let system = Lazy.from_fun OpamStubs.getPathToSystem in fun () -> Lazy.force system diff --git a/src/core/opamStd.mli b/src/core/opamStd.mli index 4e89f7115a3..b31145537bc 100644 --- a/src/core/opamStd.mli +++ b/src/core/opamStd.mli @@ -513,6 +513,9 @@ module Sys : sig (** The output of the command "uname", with the given argument. Memoised. *) val uname: string -> string option + (** The output of the command "getconf", with the given argument. Memoised. *) + val getconf: string -> string option + (** Append .exe (only if missing) to executable filenames on Windows *) val executable_name : string -> string diff --git a/src/state/opamSysPoll.ml b/src/state/opamSysPoll.ml index ebcfb2ffcd5..936ee9025da 100644 --- a/src/state/opamSysPoll.ml +++ b/src/state/opamSysPoll.ml @@ -47,9 +47,23 @@ let poll_arch () = end | _ -> None in - match raw with - | None | Some "" -> None - | Some a -> Some (normalise_arch a) + let normalised = + match raw with + | None | Some "" -> None + | Some a -> Some (normalise_arch a) + in + match Sys.os_type with + | "Unix" | "Cygwin" -> + (match normalised with + | Some ("x86_64" | "arm64" | "ppc64" as arch) -> + (match OpamStd.Sys.getconf "LONG_BIT", arch with + | Some "32", "x86_64" -> Some "x86_32" + | Some "32", "arm64" -> Some "arm32" + | Some "32", "ppc64" -> Some "ppc32" + | _ -> normalised + | exception (Unix.Unix_error _ | Sys_error _ | Not_found) -> normalised) + | _ -> normalised) + | _ -> normalised let arch = Lazy.from_fun poll_arch let normalise_os raw =