NobuoTsukamoto / meta-tensorflow-lite

Yocto layer for TensorFlow Lite interpreter with Python / C++.
MIT License
33 stars 18 forks source link

Cmake invocations blank out environment #57

Closed davidsj2 closed 12 months ago

davidsj2 commented 1 year ago

The tensorflow build git clones a bunch of repos during configure. For example, the file: tensorflow/lite/tools/cmake/modules/abseil-cpp.cmake includes a block:

OverridableFetchContent_Declare(
  abseil-cpp
  GIT_REPOSITORY https://github.com/abseil/abseil-cpp
  # Sync with tensorflow/third_party/absl/workspace.bzl
  GIT_TAG 273292d1cfc0a94a65082ee350509af1d113344d
  GIT_SHALLOW TRUE
  GIT_PROGRESS TRUE
  PREFIX "${CMAKE_BINARY_DIR}"
  SOURCE_DIR "${CMAKE_BINARY_DIR}/abseil-cpp"
)

In turn, that gets converted into something like:

# try the clone 3 times in case there is an odd git clone issue
set(error_code 1)
set(number_of_tries 0)
while(error_code AND number_of_tries LESS 3)
  execute_process(
    COMMAND "/disk01/user/qemu/dist/build/tmp/hosttools/git" 
            clone --no-checkout --depth 1 --no-single-branch --progress --config "advice.detachedHead=false" "https://github.com/abseil/abseil-cpp" "abseil-cpp"
    WORKING_DIRECTORY "/disk01/user/qemu/dist/build/tmp/work/riscv64-freedomusdk-linux/python3-tensorflow-lite/2.10.0-r0/build"
    RESULT_VARIABLE error_code
  )
  math(EXPR number_of_tries "${number_of_tries} + 1")

The problem is that when this gets run as part of the yocto compilation, the current environment isn't passed through. As I'm building behind a corporate proxy, I have proxy env variables and a ~/.gitconfig with proxy configuration that needs to be used. All of these fetches are timing out when this layer is pulled in. I changed /disk01/user/qemu/dist/build/tmp/hosttools/git from a symlink to /usr/bin/git to a simple shell script that resembles:

#!/bin/bash
touch /tmp/git.txt
echo "git $@" >> /tmp/git.txt
env | grep -i proxy >> /tmp/git.txt
/usr/bin/git config --list --show-origin >> /tmp/git.txt
/usr/bin/git "$@"

When the project is configured as part of the yocto build, the following shows up in /tmp/git.txt:

git clone --no-checkout --depth 1 --no-single-branch --progress --config advice.detachedHead=false https://github.com/abseil/abseil-cpp abseil-cpp
file:/tmp/tmpvku62bhk/.gitconfig    user.email=kas@example.com
file:/tmp/tmpvku62bhk/.gitconfig    user.name=Kas User

So the env has been blanked (otherwise all of the proxy variables would have been added) and it's notnot using my ~/.gitconfig, but a generated one from kas. Note I am building from https://github.com/sifive/freedom-u-sdk via: kas build --update ./freedom-u-sdk/scripts/kas/qemuriscv64.yml

NobuoTsukamoto commented 1 year ago

I don't have a corporate proxy environment, so I can't reproduce the problem. Is the following yocto wiki helpful?

davidsj2 commented 1 year ago

Hey, unfortunately that isn't of any help. There are lots of other recipes that are being pulled in that those instructions do work for, but unfortunately something within this layer is blanking the environment.

I don't think you need a proxy to reproduce the "problem". If you set any arbitrary environment variable, you should see it getting cleared when this step is executed:

OverridableFetchContent_Declare(
  abseil-cpp
  GIT_REPOSITORY https://github.com/abseil/abseil-cpp
  # Sync with tensorflow/third_party/absl/workspace.bzl
  GIT_TAG 273292d1cfc0a94a65082ee350509af1d113344d
  GIT_SHALLOW TRUE
  GIT_PROGRESS TRUE
  PREFIX "${CMAKE_BINARY_DIR}"
  SOURCE_DIR "${CMAKE_BINARY_DIR}/abseil-cpp"
)

Need to make sure that those git clones get the current environment to ensure proxy settings in the link you provided are preserved.

NobuoTsukamoto commented 1 year ago

Will an error occur if you build tensorflow lite with cmake without using yocto in your environment?