Skip to content

Commit

Permalink
Added error checking to bundle and redistributable
Browse files Browse the repository at this point in the history
  • Loading branch information
GPMueller committed Nov 30, 2019
1 parent 3d58a42 commit 01a64ca
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 16 deletions.
20 changes: 18 additions & 2 deletions clang_build/clang_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from .logging_stream_handler import TqdmHandler as _TqdmHandler
from .errors import CompileError as _CompileError
from .errors import LinkError as _LinkError
from .errors import BundleError as _BundleError
from .errors import RedistributableError as _RedistributableError

_v = _VersionInfo('clang-build').semantic_version()
__version__ = _v.release_string()
Expand Down Expand Up @@ -323,15 +325,29 @@ def build(args):
for target in target_list:
target.bundle()

# TODO: Check for bundling errors
# Check for bundling errors
errors = {}
for target in target_list:
if target.__class__ is not _HeaderOnly:
if target.unsuccessful_bundle:
errors[target.identifier] = target.bundle_report
if errors:
raise _BundleError('Bundling was unsuccessful', errors)

if environment.redistributable:
progress_bar.update()
logger.info('Generate redistributable')
for target in target_list:
target.redistributable()

# TODO: Check for errors creating the redistributables
# Check for redistibutable errors
errors = {}
for target in target_list:
if target.__class__ is not _HeaderOnly:
if target.unsuccessful_redistributable:
errors[target.identifier] = target.redistributable_report
if errors:
raise _RedistributableError('Creating redistributables was unsuccessful', errors)

progress_bar.update()
logger.info('clang-build finished.')
Expand Down
29 changes: 29 additions & 0 deletions clang_build/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ class LinkError(RuntimeError):
Error that is raised if linking was
not successful.
'''
def __init__(self, message, error_dict=None):
'''
:param message: Message of the error
:param error_dict: A dict containing all errors
that occurred during compilation
'''
super().__init__(message)
self.error_dict = error_dict

class BundleError(RuntimeError):
'''
Error that is raised if creating a bundle
was not successful.
'''
def __init__(self, message, error_dict=None):
'''
:param message: Message of the error
:param error_dict: A dict containing all errors
that occurred during compilation
'''
super().__init__(message)
self.error_dict = error_dict


class RedistributableError(RuntimeError):
'''
Error that is raised if creating a
redistributable was not successful.
'''
def __init__(self, message, error_dict=None):
'''
:param message: Message of the error
Expand Down
55 changes: 41 additions & 14 deletions clang_build/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ def bundle(self):
bundle_files = []
for dependency in self.dependency_targets:
bundle_files += dependency.bundle()
self.unsuccessful_bundle = False
return bundle_files

def redistributable(self):
pass
self.unsuccessful_redistributable = False


class HeaderOnly(Target):
Expand Down Expand Up @@ -474,19 +475,27 @@ def bundle(self):
for dependency in self.dependency_targets:
bundle_files += dependency.bundle()

self.unsuccessful_bundle = False

### Copy
for bundle_file in bundle_files:
_shutil.copy(bundle_file, self.output_folder)
try:
_shutil.copy(bundle_file, self.output_folder)
except _subprocess.CalledProcessError as error:
self.unsuccessful_bundle = True
self.bundle_report = error.output.decode('utf-8').strip()

return [self.outfile] + bundle_files

def redistributable(self):
self.unsuccessful_redistributable = False
if _platform.PLATFORM == 'osx':
appfolder = self.redistributable_folder.joinpath(f"{self.outname}.app")
binfolder = appfolder.joinpath('Contents', 'MacOS')
binfolder.mkdir(parents=True, exist_ok=True)
with appfolder.joinpath('Contents', 'Info.plist').open(mode='w') as plist:
plist.write(f"""<?xml version="1.0" encoding="UTF-8"?>
try:
binfolder.mkdir(parents=True, exist_ok=True)
with appfolder.joinpath('Contents', 'Info.plist').open(mode='w') as plist:
plist.write(f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
Expand All @@ -510,16 +519,28 @@ def redistributable(self):
<integer>0</integer>
</dict>
</plist>""")
_shutil.copy(self.outfile, binfolder)
bundle_files = self.bundle()
for bundle_file in bundle_files:
_shutil.copy(bundle_file, binfolder)
_shutil.copy(self.outfile, binfolder)
bundle_files = self.bundle()
for bundle_file in bundle_files:
_shutil.copy(bundle_file, binfolder)
except _subprocess.CalledProcessError as error:
self.unsuccessful_redistributable = True
self.redistributable_report = error.output.decode('utf-8').strip()
elif _platform.PLATFORM == 'linux':
self.redistributable_folder.mkdir(parents=True, exist_ok=True)
# TODO: gather includes and shared libraries
try:
self.redistributable_folder.mkdir(parents=True, exist_ok=True)
# TODO: gather includes and shared libraries
except _subprocess.CalledProcessError as error:
self.unsuccessful_redistributable = True
self.redistributable_report = error.output.decode('utf-8').strip()
elif _platform.PLATFORM == 'windows':
self.redistributable_folder.mkdir(parents=True, exist_ok=True)
# TODO: gather includes and shared libraries
try:
self.redistributable_folder.mkdir(parents=True, exist_ok=True)
# TODO: gather includes and shared libraries
except _subprocess.CalledProcessError as error:
self.unsuccessful_redistributable = True
self.redistributable_report = error.output.decode('utf-8').strip()


def add_default_flags(self):
super().add_default_flags()
Expand Down Expand Up @@ -601,9 +622,15 @@ def bundle(self):
for dependency in self.dependency_targets:
bundle_files += dependency.bundle()

self.unsuccessful_bundle = False

### Copy
for bundle_file in bundle_files:
_shutil.copy(bundle_file, self.output_folder)
try:
_shutil.copy(bundle_file, self.output_folder)
except _subprocess.CalledProcessError as error:
self.unsuccessful_bundle = True
self.bundle_report = error.output.decode('utf-8').strip()

return self_bundle_files + bundle_files

Expand Down

0 comments on commit 01a64ca

Please sign in to comment.