Skip to content

Commit

Permalink
Merge pull request #5950 from kit-ty-kate/fix-arch-32bit-on-64bit
Browse files Browse the repository at this point in the history
Fix the value of the 'arch' variable when the current OS is 32bit on a 64bit machine
  • Loading branch information
kit-ty-kate authored Sep 3, 2024
2 parents 4f4491e + 6887984 commit f9c7df9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -264,3 +265,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 `<sep>..<sep>` [#5561 @rjbou]
* Add `OpamStd.Sys.getconf` [#5950 @kit-ty-kate]
13 changes: 8 additions & 5 deletions src/core/opamStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/opamStd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions src/state/opamSysPoll.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit f9c7df9

Please sign in to comment.