Skip to content

Commit

Permalink
Fixed target directories and bad print statement in project.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
GPMueller authored Aug 28, 2018
2 parents 302a094 + 8dc23ec commit 1bf1cb7
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ deploy:
password: "$PYPIPASSWORD"
skip_cleanup: true
on:
all_branches: true
branch: master
condition: $DEPLOY = true
20 changes: 10 additions & 10 deletions clang_build/clang_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def __init__(self, args):
self.clangpp = "clang++"
self.clang_ar = "llvm-ar"
# Directory this was called from
self.callingdir = _Path().resolve()
self.calling_directory = _Path().resolve()
# Working directory is where the project root should be - this is searched for 'clang-build.toml'
self.workingdir = self.callingdir
self.working_directory = self.calling_directory

# Verbosity
if not args.debug:
Expand All @@ -139,14 +139,14 @@ def __init__(self, args):

# Working directory
if args.directory:
self.workingdir = args.directory.resolve()
self.working_directory = args.directory.resolve()

if not self.workingdir.exists():
error_message = f'ERROR: specified non-existent directory [{self.workingdir}]'
if not self.working_directory.exists():
error_message = f'ERROR: specified non-existent directory [{self.working_directory}]'
self.logger.error(error_message)
raise RuntimeError(error_message)

self.logger.info(f'Working directory: {self.workingdir}')
self.logger.info(f'Working directory: {self.working_directory}')

# Build type (Default, Release, Debug)
self.buildType = args.build_type
Expand All @@ -171,7 +171,7 @@ def build(args):
processpool = environment.processpool

# Check for build configuration toml file
toml_file = _Path(environment.workingdir, 'clang-build.toml')
toml_file = _Path(environment.working_directory, 'clang-build.toml')
if toml_file.exists():
logger.info('Found config file')

Expand All @@ -198,17 +198,17 @@ def build(args):

# Otherwise we try to build it as a simple hello world or mwe project
else:
files = _get_sources_and_headers({}, environment.workingdir, environment.build_directory)
files = _get_sources_and_headers({}, environment.working_directory, environment.build_directory)

if not files['sourcefiles']:
error_message = f'Error, no sources and no [clang-build.toml] found in folder: {environment.workingdir}'
error_message = f'Error, no sources and no [clang-build.toml] found in folder: {environment.working_directory}'
logger.error(error_message)
raise RuntimeError(error_message)
# Create target
target_list.append(
_Executable(
'main',
environment.workingdir,
environment.working_directory,
environment.build_directory.joinpath(environment.buildType.name.lower()),
files['headers'],
files['include_directories'],
Expand Down
75 changes: 37 additions & 38 deletions clang_build/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, config, environment, multiple_projects):

self.name = config.get("name", "")

self.workingdir = environment.workingdir
self.working_directory = environment.working_directory

# Project build directory
self.build_directory = environment.build_directory
Expand All @@ -44,31 +44,31 @@ def __init__(self, config, environment, multiple_projects):

self.external = "url" in config
if self.external:
downloaddir = self.build_directory.joinpath('external_sources')
download_directory = self.build_directory.joinpath('external_sources')
# Check if directory is already present and non-empty
if downloaddir.exists() and _os.listdir(str(downloaddir)):
_LOGGER.info(f'External project [[{self.name}]]: sources found in {str(downloaddir)}')
if download_directory.exists() and _os.listdir(str(download_directory)):
_LOGGER.info(f'External project [[{self.name}]]: sources found in {str(download_directory)}')
# Otherwise we download the sources
else:
_LOGGER.info(f'External project [[{self.name}]]: downloading to {str(downloaddir)}')
downloaddir.mkdir(parents=True, exist_ok=True)
_LOGGER.info(f'External project [[{self.name}]]: downloading to {str(download_directory)}')
download_directory.mkdir(parents=True, exist_ok=True)
try:
_subprocess.run(["git", "clone", config["url"], str(downloaddir)], stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, encoding='utf-8')
_subprocess.run(["git", "clone", config["url"], str(download_directory)], stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, encoding='utf-8')
except _subprocess.CalledProcessError as e:
error_message = f"Error trying to download external project [[{self.name}]]. Message " + e.output
_LOGGER.exception(error_message)
raise RuntimeError(error_message)
_LOGGER.info(f'External project [[{self.name}]]: downloaded')
self.workingdir = downloaddir
self.working_directory = download_directory

if "directory" in config:
self.workingdir = environment.workingdir.joinpath(config["directory"])
toml_file = _Path(self.workingdir, 'clang-build.toml')
self.working_directory = environment.working_directory.joinpath(config["directory"])
toml_file = _Path(self.working_directory, 'clang-build.toml')
if toml_file.exists():
environment.logger.info(f'Found config file {toml_file}')
config = toml.load(str(toml_file))
else:
error_message = f"Project {self.name}: could not find project file in directory {self.workingdir}"
error_message = f"Project {self.name}: could not find project file in directory {self.working_directory}"
_LOGGER.exception(error_message)
raise RuntimeError(error_message)

Expand Down Expand Up @@ -144,50 +144,49 @@ def __init__(self, config, environment, multiple_projects):
for target_name in _IteratorProgress(target_names_project, environment.progress_disabled, len(target_names_project)):
target_node = targets_and_subproject_targets[target_name]
# Directories
target_build_dir = self.build_directory if not multiple_targets else self.build_directory.joinpath(target_name)
target_root_dir = self.workingdir
target_build_directory = self.build_directory if not multiple_targets else self.build_directory.joinpath(target_name)
target_root_directory = self.working_directory

# If target is marked as external, try to fetch the sources
### TODO: external sources should be fetched before any sources are read in, i.e. even before the first target is created
external = "url" in target_node
if external:
downloaddir = target_build_dir.joinpath('external_sources')
download_directory = target_build_directory.joinpath('external_sources')
# Check if directory is already present and non-empty
if downloaddir.exists() and _os.listdir(str(downloaddir)):
_LOGGER.info(f'External target [{target_name}]: sources found in {str(downloaddir)}')
if download_directory.exists() and _os.listdir(str(download_directory)):
_LOGGER.info(f'External target [{target_name}]: sources found in {str(download_directory)}')
# Otherwise we download the sources
else:
_LOGGER.info(f'External target [{target_name}]: downloading to {str(downloaddir)}')
downloaddir.mkdir(parents=True, exist_ok=True)
_LOGGER.info(f'External target [{target_name}]: downloading to {str(download_directory)}')
download_directory.mkdir(parents=True, exist_ok=True)
try:
_subprocess.run(["git", "clone", target_node["url"], str(downloaddir)], stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, encoding='utf-8')
_subprocess.run(["git", "clone", target_node["url"], str(download_directory)], stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, encoding='utf-8')
except _subprocess.CalledProcessError as e:
error_message = f"Error trying to download external target [{target_name}]. Message " + e.output
_LOGGER.exception(error_message)
raise RuntimeError(error_message)
_LOGGER.info(f'External target [{target_name}]: downloaded')
# self.includeDirectories.append(downloaddir)
target_root_dir = downloaddir
# self.includeDirectories.append(download_directory)
target_root_directory = download_directory

if "version" in target_node:
version = target_node["version"]
try:
_subprocess.run(["git", "checkout", version], cwd=target_root_dir, stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, encoding='utf-8')
_subprocess.run(["git", "checkout", version], cwd=target_root_directory, stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, encoding='utf-8')
except _subprocess.CalledProcessError as e:
error_message = f"Error trying to checkout target [{target_name}] version \'{version}\'. Message " + e.output
_LOGGER.exception(error_message)
raise RuntimeError(error_message)

# Build directory for obj, bin etc. should be under build type folder, e.g. default
target_build_dir = target_build_dir.joinpath(environment.buildType.name.lower())
target_build_directory = target_build_directory.joinpath(environment.buildType.name.lower())

# Sub-directory, if specified
if 'directory' in target_node:
target_root_dir = target_root_dir.joinpath(target_node['directory'])
print(f"target {target_name} dir {target_root_dir}")
target_root_directory = target_root_directory.joinpath(target_node['directory'])

# Sources
files = _get_sources_and_headers(target_node, target_root_dir, target_build_dir)
files = _get_sources_and_headers(target_node, target_root_directory, target_build_directory)
# Dependencies
dependencies = []
for name in target_node.get('dependencies', []):
Expand Down Expand Up @@ -219,8 +218,8 @@ def __init__(self, config, environment, multiple_projects):
self.target_list.append(
_Executable(
target_name,
target_root_dir,
target_build_dir,
target_root_directory,
target_build_directory,
files['headers'],
files['include_directories'],
files['sourcefiles'],
Expand All @@ -236,8 +235,8 @@ def __init__(self, config, environment, multiple_projects):
self.target_list.append(
_SharedLibrary(
target_name,
self.workingdir,
target_build_dir,
target_root_directory,
target_build_directory,
files['headers'],
files['include_directories'],
files['sourcefiles'],
Expand All @@ -253,8 +252,8 @@ def __init__(self, config, environment, multiple_projects):
self.target_list.append(
_StaticLibrary(
target_name,
self.workingdir,
target_build_dir,
target_root_directory,
target_build_directory,
files['headers'],
files['include_directories'],
files['sourcefiles'],
Expand All @@ -273,8 +272,8 @@ def __init__(self, config, environment, multiple_projects):
self.target_list.append(
_HeaderOnly(
target_name,
self.workingdir,
target_build_dir,
target_root_directory,
target_build_directory,
files['headers'],
files['include_directories'],
environment.buildType,
Expand All @@ -292,8 +291,8 @@ def __init__(self, config, environment, multiple_projects):
self.target_list.append(
_HeaderOnly(
target_name,
self.workingdir,
target_build_dir,
target_root_directory,
target_build_directory,
files['headers'],
files['include_directories'],
environment.buildType,
Expand All @@ -305,8 +304,8 @@ def __init__(self, config, environment, multiple_projects):
self.target_list.append(
_Executable(
target_name,
self.workingdir,
target_build_dir,
target_root_directory,
target_build_directory,
files['headers'],
files['include_directories'],
files['sourcefiles'],
Expand Down
36 changes: 18 additions & 18 deletions clang_build/single_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,43 @@ def _needs_rebuild(object_file, source_file, depfile):
class SingleSource:
def __init__(
self,
sourceFile,
platformFlags,
source_file,
platform_flags,
current_target_root_path,
depfileDirectory,
objectDirectory,
depfile_directory,
object_directory,
include_strings,
compileFlags,
compile_flags,
clangpp):

# Get the relative file path
self.name = sourceFile.name
self.sourceFile = sourceFile
self.name = source_file.name
self.source_file = source_file

relpath = _os.path.relpath(sourceFile.parents[0], current_target_root_path)

# TODO: I'm not sure I understand the necessity/function of this part
if current_target_root_path.joinpath('src').exists():
# If the source file is in a directory called 'src', we do not create a
# subdirectory called 'src' in the build folder structure
relpath = _os.path.relpath(source_file.parents[0], current_target_root_path)
if current_target_root_path.joinpath('src').exists():
relpath = _os.path.relpath(relpath, 'src')

# Set name, extension and potentially produced output files
self.object_file = _Path(object_directory, relpath, self.source_file.stem + '.o')
self.depfile = _Path(depfile_directory, relpath, self.source_file.stem + '.d')

self.objectFile = _Path(objectDirectory, relpath, self.sourceFile.stem + '.o')
self.depfile = _Path(depfileDirectory, relpath, self.sourceFile.stem + '.d')

self.needs_rebuild = _needs_rebuild(self.objectFile, self.sourceFile, self.depfile)
self.needs_rebuild = _needs_rebuild(self.object_file, self.source_file, self.depfile)

flags = compileFlags + include_strings
flags = compile_flags + include_strings

self.compilation_failed = False

# prepare everything for dependency file generation
self.depfile.parents[0].mkdir(parents=True, exist_ok=True)
self.dependency_command = [clangpp, '-E', '-MMD', str(self.sourceFile), '-MF', str(self.depfile)] + flags
self.dependency_command = [clangpp, '-E', '-MMD', str(self.source_file), '-MF', str(self.depfile)] + flags

# prepare everything for compilation
self.objectFile.parents[0].mkdir(parents=True, exist_ok=True)
self.compile_command = [clangpp, '-c', str(self.sourceFile), '-o', str(self.objectFile)] + flags + platformFlags
self.object_file.parents[0].mkdir(parents=True, exist_ok=True)
self.compile_command = [clangpp, '-c', str(self.source_file), '-o', str(self.object_file)] + flags + platform_flags


def generate_depfile(self):
Expand Down
Loading

0 comments on commit 1bf1cb7

Please sign in to comment.