olofk / fusesoc

Package manager and build abstraction tool for FPGA/ASIC development
BSD 2-Clause "Simplified" License
1.21k stars 246 forks source link

Question: `env` section problem. #679

Open BaseHardware opened 8 months ago

BaseHardware commented 8 months ago

Hello, I am a newbie of fusesoc. I declared the script entries in my core file and added an env section to the entries to designate some environmental variables when executing commands in the script entry. The entries in the scripts section of my core file will be used in the pre_build or post_build section of the synth target.

However, I cannot see any environment variables declared in my core file. How can could it be? Am I wrong in writing the core file? The following codelet is a part of my core file:

targets:
  default: &default
    filesets:
      - test_files
    hooks:
      pre_build:
        - testscr

scripts:
  testscr:
    cmd:
      - "@python3 ./print_environ.py"
    env:
      test: testvar

print_environ.py does not show the environmental variable of test. Is this an intended behavior? How can I put an environment variable to my script?

BaseHardware commented 8 months ago

I think specifying the tool that I used is also important. It was vivado.

olofk commented 8 months ago

I think there might be something funky with env vars in scripts. Have a vague memory of this. Unfortunately don't have time myself to look into that right now. Maybe set it before running FuseSoC as a workaround?

BaseHardware commented 8 months ago

@olofk Thanks for your reply. I share my understanding of this problem: When I tested this problem with the tool 'ghdl', the problem disappeared and it seems the problem is related to the behavior of edalize.

Although I don't know the exact reason, let me say the apparent reason: If I use 'ghdl', the script is executed through the _run_scripts of the edatool class, which sets the environmental variables and any other configurations properly with the core file, while in 'vivado', the script is executed through the 'pre_build' section of the generated Makefile in the build directory, which does not perform such an initialization task for scripts.