Beispiel #1
0
def uninstall_header(name, dir_name=None):
    # Make sure the extension is valid
    Helpers.require_file_extension(name, '.h')

    # Get the location header are stored in
    prog_root = None
    if Config.os_type in OSType.Windows:
        prog_root = os.environ.get('programfiles', 'C:\Program Files')
    else:
        prog_root = '/usr/include/'

    # Get the native install source and dest
    source = to_native(name)
    install_dir = os.path.join(prog_root, dir_name or '')
    dest = os.path.join(install_dir, source)

    # Remove
    def fn():
        # Remove the file
        if os.path.isfile(dest):
            os.remove(dest)
        # Remove the dir if empty
        if dir_name and os.path.isdir(
                install_dir) and not os.listdir(install_dir):
            shutil.rmtree(install_dir)

    Process.do_on_fail_exit(
        "Uninstalling the header '{0}'".format(name),
        "Failed to uninstall the header '{0}'.".format(name), lambda: fn())
Beispiel #2
0
def install_header(name, dir_name=None):
    # Make sure the extension is valid
    Helpers.require_file_extension(name, '.h')

    # Get the location headers are stored in
    prog_root = None
    if Config.os_type in OSType.Windows:
        prog_root = os.environ.get('programfiles', 'C:\Program Files')
    else:
        prog_root = '/usr/include/'

    # Get the native install source and dest
    source = to_native(name)
    install_dir = os.path.join(prog_root, dir_name or '')
    dest = os.path.join(install_dir, source)

    # Install
    def fn():
        # Make the dir if needed
        if dir_name and not os.path.isdir(install_dir):
            os.mkdir(install_dir)

        # Copy the file
        shutil.copy2(source, dest)

    Process.do_on_fail_exit("Installing the header '{0}'".format(name),
                            "Failed to install the header '{0}'.".format(name),
                            lambda: fn())
Beispiel #3
0
    def build_object(self, o_file, cxx_files, i_files=[]):
        # Make sure the extension is valid
        Helpers.require_file_extension(o_file, '.o')

        # Setup the messages
        task = 'Building'
        result = o_file
        plural = 'C++ objects'
        singular = 'C++ object'
        command = '"{0}" {1} {2} {3}{4} {5} {6}'.format(
            self._path, self.cxxflags, self._opt_no_link, self._opt_out_file,
            o_file, str.join(' ', cxx_files), str.join(' ', i_files))
        command = to_native(command)

        def setup():
            # Skip if the files have not changed since last build
            to_update = [to_native(o_file)]
            triggers = [to_native(t) for t in cxx_files + i_files]
            if not FS.is_outdated(to_update, triggers):
                return False

            # Create the output directory if it does not exist
            FS.create_path_dirs(o_file)

            return True

        # Create the event
        event = Process.Event(task, result, plural, singular, command, setup)
        Process.add_event(event)
Beispiel #4
0
	def build_shared_library(self, so_file, o_files):
		# Make sure the extension is valid
		Helpers.require_file_extension(so_file, '.so')

		# Setup the messages
		task = 'Building'
		result = so_file
		plural = 'C shared libraries'
		singular = 'C shared library'
		command = "{0} {1} {2} {3} {4}{5}".format(
					self._name,
					self._opt_setup,
					self._opt_link,
					str.join(' ', o_files),
					self._opt_out_file,
					so_file)
		command = to_native(command)

		def setup():
			# Skip if the files have not changed since last build
			to_update = [to_native(so_file)]
			triggers = [to_native(t) for t in o_files]
			if not FS.is_outdated(to_update, triggers):
				return False

			# Create the output directory if it does not exist
			FS.create_path_dirs(so_file)

			return True

		# Create the event
		event = Process.Event(task, result, plural, singular, command, setup)
		Process.add_event(event)
Beispiel #5
0
def install_program(name, dir_name):
    # Make sure the extension is valid
    Helpers.require_file_extension(name, '.exe')

    # Get the location programs are stored in
    prog_root = None
    if Config.os_type in OSType.Windows:
        prog_root = os.environ.get('programfiles', 'C:\Program Files')
    else:
        prog_root = '/usr/lib/'

    # Get the native install source and dest
    source = to_native(name)
    install_dir = os.path.join(prog_root, dir_name or '')
    dest = os.path.join(install_dir, source)

    # Install
    def fn():
        # Make the dir if needed
        if dir_name and not os.path.isdir(install_dir):
            os.mkdir(install_dir)

        # Copy the file
        shutil.copy2(source, dest)

        if not Config.os_type in OSType.Windows:
            script_name = Helpers.before(name, '.')
            script_path = os.path.join('/usr/bin/', script_name)
            with open(script_path, 'w') as f:
                f.write("#!/usr/bin/env bash\n")
                f.write("\n")
                f.write(
                    "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/{0}\n".
                    format(dir_name))
                f.write("THIS_EXE=\"/usr/lib/{0}/{1}.exe\"\n".format(
                    dir_name, script_name))
                f.write("exec mono $THIS_EXE \"$@\"\n")
                f.write("\n")
            st = os.stat(script_path)
            os.chmod(script_path,
                     st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

    Process.do_on_fail_exit(
        "Installing the program '{0}'".format(name),
        "Failed to install the program '{0}'.".format(name), lambda: fn())
Beispiel #6
0
    def build_static_library(self,
                             o_file,
                             d_files,
                             i_files=[],
                             l_files=[],
                             generate_headers=False):
        # Make sure the extension is valid
        Helpers.require_file_extension(o_file, '.a')

        # Setup the messages
        task = 'Building'
        result = o_file
        plural = 'D static libraries'
        singular = 'D static library'

        command = '"{0}" {1} {2} {3}{4} {5} {6} {7}'.format(
            self._path, self.dflags, self._opt_lib, self._opt_out_file, o_file,
            str.join(' ', d_files), str.join(' ', i_files),
            str.join(' ', l_files))
        if generate_headers:
            command += "  {0}import {1}".format(
                self._opt_interface_dir,
                self._opt_interface,
            )
        command = to_native(command)

        def setup():
            # Skip if the files have not changed since last build
            to_update = [to_native(o_file)]
            triggers = [to_native(t) for t in d_files + i_files + l_files]
            if not FS.is_outdated(to_update, triggers):
                return False

            # Create the output directory if it does not exist
            FS.create_path_dirs(o_file)

            return True

        # Create the event
        event = Process.Event(task, result, plural, singular, command, setup)
        Process.add_event(event)