From 6e609158e681fad05056dad6e4674da46897f39b Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Thu, 26 Aug 2021 14:39:47 -0700 Subject: [PATCH] Fix race condition between hack and hack_ffi targets Summary: We use `hphp/hack/dev_env.sh` to set up various environment variables for OCaml and Rust compilation; this ends with `eval $(opam env)`. It turns out that if you try to run `opam env` while another instance of `opam` is running, the output is: ``` Another process has locked /Users/fredemmott/code/hhvm/build/hphp/hack/opam/hack-switch/.opam-switch/lock, waiting (C-c to abort)... lock acquired. OPAM_SWITCH_PREFIX=...... normal output here ``` ... which can't be evaled. This happens when doing a parallel build as both the `hack` (typechecker) and `hack_ffi` (rust stuff, both for the typechecker and hackc embedded in HHVM) targets use dev_env.sh Fix this by splitting out a `dev_env_common.sh.in` and a `dev_env_rust_only.sh.in`, and making the `hack_ffi` target use the `dev_env_rust_only.sh` CMake generates the `.sh` from the `.sh.in` Reviewed By: kavoor Differential Revision: D30583055 fbshipit-source-id: 0770bfc6528db15dd455398567f3d31beaed37c3 --- hphp/hack/CMakeLists.txt | 4 +++- hphp/hack/dev_env.sh.in | 22 +--------------------- hphp/hack/dev_env_common.sh.in | 28 ++++++++++++++++++++++++++++ hphp/hack/dev_env_rust_only.sh.in | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 hphp/hack/dev_env_common.sh.in create mode 100644 hphp/hack/dev_env_rust_only.sh.in diff --git a/hphp/hack/CMakeLists.txt b/hphp/hack/CMakeLists.txt index 336fbaa3738da..61bf3fcd8bdc3 100644 --- a/hphp/hack/CMakeLists.txt +++ b/hphp/hack/CMakeLists.txt @@ -124,7 +124,7 @@ set(CARGO_BUILD "${CMAKE_SOURCE_DIR}/hphp/hack/scripts/build_rust_to_ocaml.sh") add_custom_target( hack_ffi COMMAND - . "${CMAKE_CURRENT_BINARY_DIR}/dev_env.sh" && + . "${CMAKE_CURRENT_BINARY_DIR}/dev_env_rust_only.sh" && ${CARGO_BUILD} hack_parser_ffi rust_parser_ffi && ${CARGO_BUILD} rust_facts_ffi rust_facts_ffi && ${CARGO_BUILD} compile_ffi compile_ffi && @@ -185,6 +185,8 @@ add_dependencies(libdecl_cpp_ffi_stubs hack_ffi) set_target_properties(libdecl_cpp_ffi_stubs PROPERTIES IMPORTED_LOCATION ${LIBRUST_DECL_PATH}) configure_file(dev_env.sh.in dev_env.sh ESCAPE_QUOTES @ONLY) +configure_file(dev_env_common.sh.in dev_env_common.sh ESCAPE_QUOTES @ONLY) +configure_file(dev_env_rust_only.sh.in dev_env_rust_only.sh ESCAPE_QUOTES @ONLY) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_client DESTINATION bin diff --git a/hphp/hack/dev_env.sh.in b/hphp/hack/dev_env.sh.in index c855bf1fff776..ef4858ac76d3e 100644 --- a/hphp/hack/dev_env.sh.in +++ b/hphp/hack/dev_env.sh.in @@ -1,4 +1,3 @@ -#!/bin/sh # Copyright (c) 2019, Facebook, Inc. # All rights reserved. # @@ -11,24 +10,5 @@ # # source $BUILD_DIR/hphp/hack/dev_env.sh -export CMAKE_SOURCE_DIR="@CMAKE_SOURCE_DIR@" -export CMAKE_INSTALL_FULL_SYSCONFDIR="@CMAKE_INSTALL_FULL_SYSCONFDIR@" -export CMAKE_INSTALL_FULL_BINDIR="@CMAKE_INSTALL_FULL_BINDIR@" - -export HACK_NO_CARGO_VENDOR=true -export OPAMROOT="@OPAMROOT@" -export PYTHONPATH="@HPHP_HOME@" # needed for verify.py for `hack_dune_test` -export CARGO_HOME="@CMAKE_CURRENT_BINARY_DIR@/cargo_home" -export RUSTC="@RUSTC_BIN_DIR@/rustc" -export DUNE_BUILD_DIR="@DUNE_BUILD_DIR@" -export HACK_SOURCE_ROOT="@CMAKE_CURRENT_SOURCE_DIR@" -export HACK_BUILD_ROOT="@HACK_BUILD_ROOT@" -export HACK_BIN_DIR="@CMAKE_BINARY_DIR@/hphp/hack/bin" -export PATH="@RUSTC_BIN_DIR@:@CARGO_BIN_DIR@:$(dirname "@OPAM_EXECUTABLE@"):$PATH" - -export HACK_EXTRA_INCLUDE_PATHS="@extra_include_paths@" -export HACK_EXTRA_LINK_OPTS="@extra_link_opts@" -export HACK_EXTRA_LIB_PATHS="@extra_lib_paths@" -export HACK_EXTRA_NATIVE_LIBRARIES="@extra_native_libraries@" - +. "@CMAKE_CURRENT_BINARY_DIR@/dev_env_common.sh" eval $(opam env) diff --git a/hphp/hack/dev_env_common.sh.in b/hphp/hack/dev_env_common.sh.in new file mode 100644 index 0000000000000..0f702ab641d80 --- /dev/null +++ b/hphp/hack/dev_env_common.sh.in @@ -0,0 +1,28 @@ +#!/bin/sh +# Copyright (c) 2019, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the "hack" directory of this source tree. + +# Do not use this file directly - either use dev_env.sh or dev_env_rust_only.sh + +export CMAKE_SOURCE_DIR="@CMAKE_SOURCE_DIR@" +export CMAKE_INSTALL_FULL_SYSCONFDIR="@CMAKE_INSTALL_FULL_SYSCONFDIR@" +export CMAKE_INSTALL_FULL_BINDIR="@CMAKE_INSTALL_FULL_BINDIR@" + +export HACK_NO_CARGO_VENDOR=true +export OPAMROOT="@OPAMROOT@" +export PYTHONPATH="@HPHP_HOME@" # needed for verify.py for `hack_dune_test` +export CARGO_HOME="@CMAKE_CURRENT_BINARY_DIR@/cargo_home" +export RUSTC="@RUSTC_BIN_DIR@/rustc" +export DUNE_BUILD_DIR="@DUNE_BUILD_DIR@" +export HACK_SOURCE_ROOT="@CMAKE_CURRENT_SOURCE_DIR@" +export HACK_BUILD_ROOT="@HACK_BUILD_ROOT@" +export HACK_BIN_DIR="@CMAKE_BINARY_DIR@/hphp/hack/bin" +export PATH="@RUSTC_BIN_DIR@:@CARGO_BIN_DIR@:$(dirname "@OPAM_EXECUTABLE@"):$PATH" + +export HACK_EXTRA_INCLUDE_PATHS="@extra_include_paths@" +export HACK_EXTRA_LINK_OPTS="@extra_link_opts@" +export HACK_EXTRA_LIB_PATHS="@extra_lib_paths@" +export HACK_EXTRA_NATIVE_LIBRARIES="@extra_native_libraries@" diff --git a/hphp/hack/dev_env_rust_only.sh.in b/hphp/hack/dev_env_rust_only.sh.in new file mode 100644 index 0000000000000..1bc915f88eb10 --- /dev/null +++ b/hphp/hack/dev_env_rust_only.sh.in @@ -0,0 +1,14 @@ +# Copyright (c) 2019, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the "hack" directory of this source tree. + +# This file is processed by cmake; the produced file is intended for both +# internal usage by the build system, and for direct usage by people working on +# Hack itself from CMake builds: +# +# . $BUILD_DIR/hphp/hack/dev_env_rust_only.sh + +. "@CMAKE_CURRENT_BINARY_DIR@/dev_env_common.sh" +# Nothing else to do for rust :)