Trick-17 / clang-build

Clang-based cross platform build system written in Python
https://clang-build.readthedocs.io
MIT License
8 stars 3 forks source link

Infer target folder from target name #120

Open NOhs opened 3 years ago

NOhs commented 3 years ago

The current example for clang_build for multiple targets is:

    my_project
    ├── shared_headers
    |   └── header1.hpp
    ├── my_executable
    |   ├── include
    |   |   ├── header1.hpp
    |   |   └── header2.hpp
    |   └── src
    |       ├── src1.cpp
    |       └── src2.hpp
    ├── my_lib
    |   ├── include
    |   |   └── header3.hpp
    |   └── src
    |       └── src3.hpp
    └── clang-build.toml
[additional_includes]
    directory = "shared_headers"
    target_type = "header only"

[my_library]
    directory = "my_lib"
    target_type = "shared library"
    dependencies = ["shared_headers"]

[app]
    directory    = "my_executable"
    dependencies = ["my_lib", "shared_headers"]

I would argue that the following TOML should be sufficient:

[shared_headers]

[my_lib]
    target_type = "shared library"
    dependencies = ["shared_headers"]

[my_executable]
    dependencies = ["my_lib", "shared_headers"]

The header-only should already work. The "directory" part currently does not work. I think the current implementation was chosen to allow for single named targets not requiring a subfolder. I am wondering if we should instead opt for another exception for single targets to allow for the simple toml file above to work.

Note that this would also encourage people to not name their folders differently to their targets in the toml file which would overall make it easier to navigate such projects.

GPMueller commented 3 years ago

In the first example, the dependencies should be "additional_includes" and in the second example the target [additional_includes] should be called [shared_headers], right?

I agree, it would be good to check for a directory with the target's name in any case. Then deviating from this default requires adding a directory = "...".

When a target is the only target, no directory is specified and no folder with the target name is found, then the project directory should be searched for sources, but never otherwise.

NOhs commented 3 years ago

I updated the second example. The first one I copy-pasted from the existing documentation. But you are right, the dependency has to be fixed in that example.

GPMueller commented 3 years ago

In TargetDescription, we currently have

@property
def root_directory(self):
    if self._download_directory:
        return self._download_directory / self._relative_directory
    else:
        return self.parent_project.directory / self._relative_directory

which could easily be replaced by

@property
def root_directory(self):
    if self._download_directory:
        return self._download_directory / self._relative_directory
    elif self._relative_directory:
        return self.parent_project.directory / self._relative_directory
    elif (self.parent_project.directory / self.name).exists():
        return self.parent_project.directory / self.name
    else:
        return self.parent_project.directory