def build_tensorflow()

in tools/build_utils.py [0:0]


def build_tensorflow(tf_version,
                     src_dir,
                     artifacts_dir,
                     target_arch,
                     verbosity,
                     use_intel_tf,
                     cxx_abi,
                     target=""):
    # In order to build TensorFlow, we need to be in the virtual environment
    pwd = os.getcwd()

    src_dir = os.path.abspath(src_dir)
    print("SOURCE DIR: " + src_dir)

    # Update the artifacts directory
    artifacts_dir = os.path.join(os.path.abspath(artifacts_dir), "tensorflow")
    print("ARTIFACTS DIR: %s" % artifacts_dir)

    os.chdir(src_dir)

    base = sys.prefix
    python_lib_path = os.path.join(base, 'lib', 'python%s' % sys.version[:3],
                                   'site-packages')
    python_executable = os.path.join(base, "bin", "python")

    print("PYTHON_BIN_PATH: " + python_executable)

    # Set the TensorFlow configuration related variables
    os.environ["PYTHON_BIN_PATH"] = python_executable
    os.environ["PYTHON_LIB_PATH"] = python_lib_path
    os.environ["TF_ENABLE_XLA"] = "0"
    if (platform.system() == 'Darwin'):
        os.environ["TF_CONFIGURE_IOS"] = "0"
    os.environ["TF_NEED_OPENCL_SYCL"] = "0"
    os.environ["TF_NEED_COMPUTECPP"] = "0"
    os.environ["TF_NEED_ROCM"] = "0"
    os.environ["TF_NEED_MPI"] = "0"
    os.environ["TF_NEED_CUDA"] = "0"
    os.environ["TF_NEED_TENSORRT"] = "0"
    os.environ["TF_DOWNLOAD_CLANG"] = "0"
    os.environ["TF_SET_ANDROID_WORKSPACE"] = "0"
    os.environ["CC_OPT_FLAGS"] = "-march=" + target_arch + " -Wno-sign-compare"

    command_executor("./configure")

    cmd = [
        "bazel",
        "build",
        "--config=opt",
        "--config=noaws",
        "--config=nohdfs",
        "--config=nonccl",
    ]
    if use_intel_tf:
        print("Building Intel-Tensorflow")
        cmd.extend([
            "--config=mkl",
        ])
    # Build the python package
    if (tf_version.startswith("v1.") or tf_version.startswith("1.")):
        cmd.extend([
            "--config=v1",
        ])
    else:
        cmd.extend([
            "--config=v2",
        ])

    cmd.extend(["--cxxopt=-D_GLIBCXX_USE_CXX11_ABI=" + cxx_abi])

    # If target is not specified, we assume default TF wheel build
    if target == '':
        target = "//tensorflow/tools/pip_package:build_pip_package"

    cmd.extend([target])

    if verbosity:
        cmd.extend(['-s'])

    command_executor(cmd)

    # If target is not specified, we assume default TF wheel build and copy the wheel to artifacts dir
    if target == '//tensorflow/tools/pip_package:build_pip_package':
        command_executor([
            "bazel-bin/tensorflow/tools/pip_package/build_pip_package",
            artifacts_dir
        ])

        # Get the name of the TensorFlow pip package
        tf_wheel_files = glob.glob(
            os.path.join(artifacts_dir, "tensorflow-*.whl"))
        print("TF Wheel: %s" % tf_wheel_files[0])

    # popd
    os.chdir(pwd)