Skip to content

Commit

Permalink
[wip] improving detection of proj dir and build dir
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Nov 16, 2020
1 parent 99fe4ed commit 72208b7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/c4/cmany/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ def _handle_hidden_args__skip_rest(args):

# -----------------------------------------------------------------------------
def add_basic(parser):
parser.add_argument("proj_dir", nargs="?", default=".",
help="""the directory where the project's CMakeLists.txt
is located. An empty argument will default to the
current directory ie, \".\". Passing a directory which
does not contain a CMakeLists.txt will cause an error.""")
parser.add_argument("--build-dir", default="./build",
help="set the build root (defaults to ./build)")
parser.add_argument("--install-dir", default="./install",
parser.add_argument("-P", "--proj-dir", default=None,
help="""the directory where the project's
CMakeLists.txt is located. An empty argument will
default to the current directory ie, "." or, if
the current directory is a build directory containing
CMakeCache.txt, the source directory for that
build directory. Passing a directory which
does not contain a CMakeLists.txt or CMakeCache.txt
will cause an error.""")
parser.add_argument("-B", "--build-root", default="./build",
help="set the build root (defaults to ./build). ")
parser.add_argument("-I", "--install-root", default="./install",
help="set the install root (defaults to ./install)")
parser.add_argument("-j", "--jobs", default=cpu_count(),
help="""use the given number of parallel jobs
Expand Down
35 changes: 33 additions & 2 deletions src/c4/cmany/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ def _getdir(attr_name, default, kwargs, cwd):
return d


def _is_cmake_folder(folder):
if folder is None:
return False
dbg("exists?", folder)
if not _pexists(folder):
dbg("does not exist:", folder)
return None
dbg("exists:", folder)
if _pexists(folder, "CMakeLists.txt"):
dbg("found CMakeLists.txt in", folder)
return folder
dbg("CMakeLists.txt not found in", folder)
if _pexists(folder, "CMakeCache.txt"):
dbg("found CMakeCache.txt in", folder)
return folder
dbg("CMakeCache.txt not found in", folder)
return None


# -----------------------------------------------------------------------------
class Project:

Expand All @@ -56,10 +75,18 @@ def __init__(self, **kwargs):
pdir = kwargs.get('proj_dir')
dbg("cwd:", cwd)
dbg("proj_dir:", pdir)
if pdir is None:
raise err.ProjDirNotFound(None)
if pdir == ".":
pdir = cwd
elif pdir is None:
dbg("proj_dir not given")
if pdir is None and self.targets:
dbg("is the first target a cmake directory?", self.targets[0])
pdir = _is_cmake_folder(self.targets[0])
if pdir is not None:
self.targets = self.targets[1:]
if pdir is None:
dbg("picking current directory", cwd)
pdir = cwd
pdir = util.abspath(pdir)
dbg("proj_dir, abs:", pdir)
#
Expand All @@ -81,6 +108,10 @@ def __init__(self, **kwargs):
self.install_dir = os.path.dirname(ch['CMAKE_INSTALL_PREFIX'].val)
self.root_dir = ch['CMAKE_HOME_DIRECTORY'].val
self.cmakelists = os.path.join(self.root_dir, "CMakeLists.txt")
else:
self.build_dir = None
self.install_dir = None
self.root_dir = pdir
#
self.root_dir = os.path.realpath(self.root_dir)
self.build_dir = os.path.realpath(self.build_dir)
Expand Down

0 comments on commit 72208b7

Please sign in to comment.