2 * Copyright (c) 2013-present, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
13 * Computes some build identifiers based on the current commit. These IDs are
14 * used to ensure that clients and servers are the same version, even between
15 * releases. For example, if you build revision A and start a server, then check
16 * out and build revision B, it's convenient for the server to restart itself
19 * This fails gracefully when neither hg nor git are installed, or when neither
20 * .hg nor .git exist (e.g. when building from a tarball). This is fine because
21 * you can't move between commits in such a snapshot.
24 let out_file = Sys.argv
.(1) in
26 try read_process_output
"git" [|"git"; "rev-parse"; "HEAD"|]
28 try read_process_output
"hg" [|"hg"; "id"; "-i"|]
32 try read_process_output
"git" [|"git"; "log"; "-1"; "--pretty=tformat:%ct"|]
35 let raw = read_process_output
"hg" [|"hg"; "log"; "-r"; "."; "-T"; "{date|hgdate}\\n"|] in
36 String.sub
raw 0 (String.index
raw ' '
)
41 let content = Printf.sprintf
42 "const char* const BuildInfo_kRevision = %S;\nconst unsigned long BuildInfo_kRevisionCommitTimeUnix = %sul;\nconst char* const BuildInfo_kBuildMode = %S;\n"
43 rev time "" (* not implemented *) in
45 not
(Sys.file_exists
out_file) || string_of_file
out_file <> content in
47 with_out_channel
out_file @@ fun oc
->
48 output_string oc
content