olofk / fusesoc

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

Weird behaviour when the target name is changed #629

Open shariethernet opened 1 year ago

shariethernet commented 1 year ago

When I change the target name to certain specific names like pp, ap app etc.,and run fusesoc using the command fusesoc run --target=pp mycore I get the below error

Filepath /home/local/nu/shg/edalize_primepower_example/build/power_0/ap-primepower/power_0.eda.yml
Traceback (most recent call last):
  File "/home/unga/shg/.local/bin/fusesoc", line 11, in <module>
    load_entry_point('fusesoc', 'console_scripts', 'fusesoc')()
  File "/home/unga/shg/work/fusesoc/fusesoc/main.py", line 745, in main
    fusesoc(args)
  File "/home/unga/shg/work/fusesoc/fusesoc/main.py", line 735, in fusesoc
    args.func(cm, args)
  File "/home/unga/shg/work/fusesoc/fusesoc/main.py", line 293, in run
    run_backend(
  File "/home/unga/shg/work/fusesoc/fusesoc/main.py", line 426, in run_backend
    edalizer.to_yaml(edam_file)
  File "/home/unga/shg/work/fusesoc/fusesoc/edalizer.py", line 508, in to_yaml
    return utils.yaml_fwrite(edam_file, self.edam)
  File "/home/unga/shg/work/fusesoc/fusesoc/utils.py", line 153, in yaml_fwrite
    with open(filepath, "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/local/nu/shg/edalize_primepower_example/build/power_0/ap-primepower/power_0.eda.yml'

When I manually create the directory /home/local/nu/shg/edalize_primepower_example/build/power_0/ap-primepower/ and then run this command it works. For other names of target it works.

The one significant difference is that the target names are bigger in the second case, and hence the paths are very long. Would this be an issue?

shariethernet commented 1 year ago

I narrowed it down to the file name in the fileset. I have a very large path name in the file key for in one of the fileset used by the target. Whenever I have this specific long absolute path I get the above error. I replaced that path with a shorter relative path, then there is no error. As these files and the .core files are autogenerated, and are located in various locations, are there any work arounds? (The one I could think of is to create an empty build directory in advance, in that case, there is no error irrespective of that path length)

shariethernet commented 1 year ago

UPDATE: It appears that when none of the files in the included file sets are relative paths and they constitute only absolute paths, the directory is not created. I fixed it by modifying the yaml_write function in https://github.com/olofk/fusesoc/blob/main/fusesoc/utils.py to check if the directory for the file path exists, if not create the directory and then write the yaml.

I am not sure if this is the fix. But this seemed to do the job.

def yaml_fwrite(filepath, content, preamble=""):
    directory = os.path.dirname(filepath)
    if not os.path.exists(directory):
        os.makedirs(directory)
    with open(filepath, "w") as f:
        f.write(preamble)
        f.write(yaml.dump(content, Dumper=YamlDumper))