-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Move most of the external tools calls to a single module #3217
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* Copyright 2018 OCamlPro *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of the *) | ||
(* GNU Lesser General Public License version 2.1, with the special *) | ||
(* exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
type t = (string * string list) | ||
|
||
let unpack x = x | ||
let custom x = x | ||
|
||
let has_space (cmd, _) = String.contains cmd ' ' | ||
let cmd_to_string (cmd, _) = cmd | ||
|
||
let to_string (cmd, args) = | ||
(* TODO: Add backslashs to quotes for each args *) | ||
let quote x = if String.contains x ' ' then "'" ^ x ^ "'" else x in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This quoting logic seems like it might be replicated elsewhere in opam. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'll look around. I tried to be as close as the original code as possible (modulo quoting that is added because that seemed broken anyway) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that backslash-quoting in single quotes doesn't work for the shell. You have to write e.g. |
||
let args = List.map quote args in | ||
String.concat " " (cmd::args) | ||
|
||
module Unzip = struct | ||
let extract ~file ~dir = ("unzip", [file; "-d"; dir]) | ||
end | ||
|
||
module Tar = struct | ||
let extract_gzip ~file ~dir = ("tar", ["xfz"; file; "-C"; dir]) | ||
let extract_bzip2 ~file ~dir = ("tar", ["xfj"; file; "-C"; dir]) | ||
let extract_xz ~file ~dir = ("tar", ["xfJ"; file; "-C"; dir]) | ||
let extract_lzma ~file ~dir = ("tar", ["xfY"; file; "-C"; dir]) | ||
|
||
let create_gzip ~output ~inputs = ("tar", ("czhf" :: output :: inputs)) | ||
end | ||
|
||
module Patch = struct | ||
let apply ~file = ("patch", ["-p1"; "-i"; file]) | ||
end | ||
|
||
module Diff = struct | ||
let dirs ~dir1 ~dir2 = ("diff", ["-ruaN"; dir1; dir2]) | ||
end | ||
|
||
module Rm = struct | ||
let recursive ~dir = ("rm", ["-rf"; dir]) | ||
end | ||
|
||
module Cmd = struct | ||
let rm_recursive ~dir = ("cmd", ["/d"; "/v:off"; "/c"; "rd"; "/s"; "/q"; dir]) | ||
let get_os_version = ("cmd", ["/C"; "ver"]) | ||
end | ||
|
||
module Sw_vers = struct | ||
let get_os_version = ("sw_vers", ["-productVersion"]) | ||
end | ||
|
||
module Getprop = struct | ||
let get_os_version = ("getprop", ["ro.build.version.release"]) | ||
end | ||
|
||
module Sleep = struct | ||
let one_second = ("sleep", ["1"]) | ||
end | ||
|
||
module Cp = struct | ||
let cp ~src ~dst = ("cp", [src; dst]) | ||
let recursive ~srcs ~dst = ("cp", ("-PRp" :: srcs @ [dst])) | ||
end | ||
|
||
module Mv = struct | ||
let mv ~src ~dst = ("mv", [src; dst]) | ||
end | ||
|
||
module Install = struct | ||
let exec ~src ~dst = ("install", ["-m"; "0755"; src; dst]) | ||
let file ~src ~dst = ("install", ["-m"; "0644"; src; dst]) | ||
end | ||
|
||
module Sysctl = struct | ||
let get_hw_ncpu = ("sysctl", ["-n"; "hw.ncpu"]) | ||
end | ||
|
||
module Getconf = struct | ||
let get_nproc = ("getconf", ["_NPROCESSORS_ONLN"]) | ||
end | ||
|
||
module Lsb_release = struct | ||
let get_id = ("lsb_release", ["-i"; "-s"]) | ||
let get_release = ("lsb_release", ["-s"; "-r"]) | ||
end | ||
|
||
module Tput = struct | ||
let cols = ("tput", ["cols"]) | ||
end | ||
|
||
module Stty = struct | ||
let size = ("stty", ["size"]) | ||
end | ||
|
||
module Uname = struct | ||
let kern_name = ("uname", ["-s"]) | ||
let kern_version = ("uname", ["-r"]) | ||
let arch = ("uname", ["-m"]) | ||
let freebsd_version = ("uname", ["-U"]) | ||
end | ||
|
||
module Openssl = struct | ||
let sha256 ~file = ("openssl", ["sha256"; file]) | ||
let sha512 ~file = ("openssl", ["sha512"; file]) | ||
end | ||
|
||
module Git = struct | ||
let get_user_name = ("git", ["config"; "--get"; "user.name"]) | ||
let get_user_email = ("git", ["config"; "--get"; "user.email"]) | ||
end | ||
|
||
module OCaml = struct | ||
let vnum = ("ocaml", ["-vnum"]) | ||
end | ||
|
||
module Command = struct | ||
let lookup ~cmd = ("/bin/sh", ["-c"; "command -v "^cmd]) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* Copyright 2018 OCamlPro *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of the *) | ||
(* GNU Lesser General Public License version 2.1, with the special *) | ||
(* exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
type t | ||
|
||
val unpack : t -> (string * string list) | ||
|
||
(** NOTE: Please try to use this function as little as possible *) | ||
val custom : (string * string list) -> t | ||
|
||
val has_space : t -> bool | ||
val cmd_to_string : t -> string | ||
|
||
(** For printing only *) | ||
val to_string : t -> string | ||
|
||
module Unzip : sig | ||
val extract : file:string -> dir:string -> t | ||
end | ||
|
||
module Tar : sig | ||
val extract_gzip : file:string -> dir:string -> t | ||
val extract_bzip2 : file:string -> dir:string -> t | ||
val extract_xz : file:string -> dir:string -> t | ||
val extract_lzma : file:string -> dir:string -> t | ||
val create_gzip : output:string -> inputs:string list -> t | ||
end | ||
|
||
module Patch : sig | ||
val apply : file:string -> t | ||
end | ||
|
||
module Diff : sig | ||
val dirs : dir1:string -> dir2:string -> t | ||
end | ||
|
||
module Rm : sig | ||
val recursive : dir:string -> t | ||
end | ||
|
||
module Cmd : sig | ||
val rm_recursive : dir:string -> t | ||
val get_os_version : t | ||
end | ||
|
||
module Sw_vers : sig | ||
val get_os_version : t | ||
end | ||
|
||
module Getprop : sig | ||
val get_os_version : t | ||
end | ||
|
||
module Sleep : sig | ||
val one_second : t | ||
end | ||
|
||
module Cp : sig | ||
val cp : src:string -> dst:string -> t | ||
val recursive : srcs:string list -> dst:string -> t | ||
end | ||
|
||
module Mv : sig | ||
val mv : src:string -> dst:string -> t | ||
end | ||
|
||
module Install : sig | ||
val exec : src:string -> dst:string -> t | ||
val file : src:string -> dst:string -> t | ||
end | ||
|
||
module Sysctl : sig | ||
val get_hw_ncpu : t | ||
end | ||
|
||
module Getconf : sig | ||
val get_nproc : t | ||
end | ||
|
||
module Lsb_release : sig | ||
val get_id : t | ||
val get_release : t | ||
end | ||
|
||
module Tput : sig | ||
val cols : t | ||
end | ||
|
||
module Stty : sig | ||
val size : t | ||
end | ||
|
||
module Uname : sig | ||
val kern_name : t | ||
val kern_version : t | ||
val arch : t | ||
val freebsd_version : t | ||
end | ||
|
||
module Openssl : sig | ||
val sha256 : file:string -> t | ||
val sha512 : file:string -> t | ||
end | ||
|
||
module Git : sig | ||
val get_user_name : t | ||
val get_user_email : t | ||
end | ||
|
||
module OCaml : sig | ||
val vnum : t | ||
end | ||
|
||
module Command : sig | ||
val lookup : cmd:string -> t | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't copyright ocamlpro :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just copying the header from the other files. Should I put my name instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, in this instance I think it depends - is the module predominantly just refactoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think so.