Reorder expected/actual in LSP assertions
[hiphop-php.git] / hphp / hack / scripts / gen_build_id.ml
blob9694f5fb91dc6efd503e58228e1e05f7b1700ea9
1 (*
2 * Copyright (c) 2013-present, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 #use "utils.ml"
12 (**
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
17 * using revision B.
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.
23 let () =
24 let out_file = Sys.argv.(1) in
25 let rev =
26 try read_process_output "git" [|"git"; "rev-parse"; "HEAD"|]
27 with Failure _ ->
28 try read_process_output "hg" [|"hg"; "id"; "-i"|]
29 with Failure _ -> ""
31 let time =
32 try read_process_output "git" [|"git"; "log"; "-1"; "--pretty=tformat:%ct"|]
33 with Failure _ ->
34 try
35 let raw = read_process_output "hg" [|"hg"; "log"; "-r"; "."; "-T"; "{date|hgdate}\\n"|] in
36 String.sub raw 0 (String.index raw ' ')
37 with
38 | Failure _ -> "0"
39 | Not_found -> "0"
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
44 let do_dump =
45 not (Sys.file_exists out_file) || string_of_file out_file <> content in
46 if do_dump then
47 with_out_channel out_file @@ fun oc ->
48 output_string oc content