Exemplo n.º 1
0
def setup():
    global java_compilers
    global missing_compilers

    # Get the names and paths for know Java compilers
    names = ['javac']
    for name in names:
        paths = Find.program_paths(name)
        if len(paths) == 0:
            missing_compilers.append(name)
            continue

        if name in ['javac']:
            comp = JavaCompiler(name=name,
                                path=paths[0],
                                debug='-g',
                                no_warnings='-nowarn',
                                verbose='-verbose',
                                deprecation='-deprecation',
                                runtime='java',
                                jar='jar')
            java_compilers[comp._name] = comp

    # Make sure there is at least one Java compiler installed
    if len(java_compilers) == 0:
        Print.status("Setting up Java module")
        Print.fail()
        Print.exit("No Java compiler found. Install one and try again.")
Exemplo n.º 2
0
def setup():
	global linkers

	# Get the names and paths for know linkers
	names = ['ld', 'link.exe']
	for name in names:
		paths = Find.program_paths(name)
		if len(paths) == 0:
			continue

		if name == 'link.exe':
			link = Linker(
				name            = 'link.exe',
				setup           = '/nologo',
				out_file        = '/out:',
				shared          = '/dll '
			)
			linkers[link._name] = link
		elif name == 'ld':
			link = Linker(
				name            = 'ld',
				setup           = '',
				out_file        = '-o ',
				shared          = '-G'
			)
			linkers[link._name] = link

	# Make sure there is at least one linker installed
	if len(linkers) == 0:
		Print.status("Setting up Linker module")
		Print.fail()
		Print.exit("No Linker found. Install one and try again.")
Exemplo n.º 3
0
def import_rscript(globals_var, locals_var):
    # Make sure there is an rscript file
    if not os.path.isfile('rscript'):
        return None

    # Load the rscript file into this namespace
    # Get a list of all the things in the script
    names = []
    with open('rscript', 'rb') as f:
        code = None
        try:
            code = compile(f.read(), 'rscript', 'exec')
            names = [name for name in code.co_names]
        except Exception as e:
            Print.exit(e)

        exec(code, globals_var, locals_var)

    # Get just the target functions
    targets = {}
    for name in names:
        if name in globals_var and not name.startswith('_'):
            if hasattr(globals_var[name], '__call__'):
                targets[name] = globals_var[name]

    return targets
Exemplo n.º 4
0
def remove_dir(name, and_children = False):
	Print.status("Removing the dir '{0}'".format(name))
	success = False

	# Make sure we are not removing the current directory
	if name == os.getcwd():
		Print.fail()
		Print.exit("Can't remove the current directory '{0}'.".format(name))

	try:
		for entry in glob_names(name):
			if os.path.islink(entry):
				os.unlink(entry)
			elif os.path.isdir(entry):
				if and_children:
					shutil.rmtree(entry)
				else:
					os.rmdir(entry)
		success = True
	except OSError as e:
		if 'No such file or directory' in e:
			success = True

	if success:
		Print.ok()
	else:
		Print.fail()
		Print.exit("Failed to remove the dir '{0}'.".format(name))
Exemplo n.º 5
0
def ldconfig():
	# Setup the message
	Print.status("Running 'ldconfig'")

	# Skip ldconfig on Cygwin
	if Config.os_type in OSType.Cygwin:
		Print.ok()
		return

	# Find ldconfig
	prog = Find.program_paths('ldconfig')
	if not prog:
		Print.fail()
		Print.exit("Could not find 'ldconfig'.")

	# Run the process
	runner = findlib.ProcessRunner(prog[0])
	runner.run()
	runner.is_done
	runner.wait()

	# Success or failure
	if runner.is_failure:
		Print.fail(runner.stdall)
		Print.exit("Failed run 'ldconfig'.")
	elif runner.is_success or runner.is_warning:
		Print.ok()
Exemplo n.º 6
0
def do_as_normal_user(cb):
	prev_id = -1

	# Change the user to the normal user
	if not Config.os_type in OSType.withoutRoot:
		prev_id = os.geteuid()
		user_id = get_normal_user_id()
		os.setegid(user_id)
		os.seteuid(user_id)

	# Run the cb as the normal user
	exception = False
	is_exiting = False
	try:
		cb()
	except SystemExit as err:
		# Don't save any exit() exceptions. Just exit
		is_exiting = True
	except Exception as err:
		exception = traceback.format_exc()
	except StandardError as err:
		exception = traceback.format_exc()
	except BaseException as err:
		exception = traceback.format_exc()
	finally:
		# Return the user to normal
		if not Config.os_type in OSType.withoutRoot:
			os.setegid(prev_id)
			os.seteuid(prev_id)

	if is_exiting:
		sys.exit(1)
	if exception:
		Print.exit(exception)
Exemplo n.º 7
0
    def build_shared_library(self, out_file, inc_files, link_files=[]):
        # Make sure the extension is valid
        if not out_file.endswith('.dll'):
            Print.exit(
                "Out file extension should be '.dll' not '.{0}'.".format(
                    out_file.split('.')[-1]))

        # Setup the messages
        task = 'Building'
        result = out_file
        plural = 'C# shared libraries'
        singular = 'C# shared library'
        command = '"{0}" {1} -target:library {2}{3} {4} {5}'.format(
            self._path, self.csflags, self._opt_out_file, out_file,
            str.join(' ', inc_files), str.join(' ', link_files))
        command = to_native(command)

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

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

            return True

        # Create the event
        event = Process.Event(task, result, plural, singular, command, setup)
        Process.add_event(event)
Exemplo n.º 8
0
def require_not_root():
	# On Windows/Cygwin/BeOS it does not matter if we are root. So just return
	if Config.os_type in OSType.withoutRoot:
		return

	# Make sure we are NOT root
	if os.getuid() == 0:
		Print.exit("Must not be run as root.")
Exemplo n.º 9
0
def require_programs(prog_names):
	for prog_name in prog_names:
		Print.status("Checking for program '{0}'".format(prog_name))
		if len(findlib.program_paths(prog_name)):
			Print.ok()
		else:
			Print.fail()
			Print.exit("Install the program '{0}' and try again.".format(prog_name))
Exemplo n.º 10
0
def require_environmental_variable(env_name, version_cb = None):
	Print.status("Checking for environmental variable '{0}'".format(env_name))

	if not os.environ.get(env_name):
		message = "The environmental variable '{0}' was not found. Set it and try again."
		Print.fail()
		Print.exit(message.format(env_name))
	else:
		Print.ok()
Exemplo n.º 11
0
def get_normal_user_name():
	# Get the name from the environmental variable
	user_name = \
		os.getenv('SUDO_USER') or \
		os.getenv('USER') or \
		os.getenv('LOGNAME')

	# Make sure we got a name
	if not user_name:
		Print.exit('Failed to get the normal user name.')

	return user_name
Exemplo n.º 12
0
def require_header_file(header_name, version_str = None):
	Print.status("Checking for header file '{0}'".format(header_name))

	# If the header is not installed, make them install it to continue
	if not findlib.get_header_file(header_name, version_str):
		ver = "(Any version)"
		if version_str:
			ver = version_str

		message = "Header file '{0} {1}' not installed. Install and try again."
		Print.fail()
		Print.exit(message.format(header_name, ver))
	else:
		Print.ok()
Exemplo n.º 13
0
def require_shared_library(lib_name, version_str = None):
	Print.status("Checking for shared library '{0}'".format(lib_name))

	# If the shared library is not installed, make them install it to continue
	if not findlib.get_shared_library(lib_name, version_str):
		# Get the version requirement lambda as a printable string
		ver = "(Any version)"
		if version_str:
			ver = version_str

		message = "Shared library '{0} {1}' not installed. Install and try again."
		Print.fail()
		Print.exit(message.format(lib_name, ver))
	else:
		Print.ok()
Exemplo n.º 14
0
def get_default_compiler():
	global c_compilers

	if Config.os_type in OSType.Windows:
		# Make sure Windows SDK tools are found
		if not 'WINDOWSSDKDIR' in os.environ and not 'WINDOWSSDKVERSIONOVERRIDE' in os.environ:
			Print.status("Setting up cl.exe")
			Print.fail()
			Print.exit('Windows SDK not found. Must be run from Windows SDK Command Prompt.')

		return c_compilers.get('cl.exe')
	elif Config.os_type in OSType.Unix:
		return c_compilers.get('clang') or c_compilers.get('gcc')
	else:
		return c_compilers.get('gcc') or c_compilers.get('clang')

	return None
Exemplo n.º 15
0
def run_print(command):
    Print.status("Running C++ program")

    native_command = to_native(command)
    runner = findlib.ProcessRunner(native_command)
    runner.run()
    runner.is_done
    runner.wait()

    if runner.is_success or runner.is_warning:
        Print.ok()
        sys.stdout.write(command + '\n')
        sys.stdout.write(runner.stdall)
    elif runner.is_failure:
        Print.fail()
        sys.stdout.write(command + '\n')
        sys.stdout.write(runner.stdall)
        Print.exit('Failed to run command.')
Exemplo n.º 16
0
def require_static_or_shared_library(lib_name, version_str = None):
	Print.status("Checking for static/shared library '{0}'".format(lib_name))

	shared_file = get_shared_library(lib_name, version_str)
	static_file = get_shared_library(lib_name, version_str)

	# Make them install the lib if neither was found
	if not shared_file and not static_file:
		# Get the version requirement lambda as a printable string
		ver = "(Any version)"
		if version_str:
			ver = version_str

		message = "Shared/Static library '{0} {1}' not installed. Install and try again."
		Print.fail()
		Print.exit(message.format(lib_name, ver))
	else:
		Print.ok()
Exemplo n.º 17
0
    def wait(self):
        # Wait for the process to complete
        self._runner.wait()

        # Display the message
        if Event.is_concurrent:
            Print.status("   '{0}'".format(self._result))

        # Success or failure
        if self._runner.is_success:
            Print.ok()
            self._status = 'success'
        elif self._runner.is_warning:
            Print.warning(self._runner.stderr)
            self._status = 'success'
        else:
            Print.fail(self._runner.stdall)
            Print.exit("{0} failed. Try again.".format(self._task))
            self._status = 'failure'
Exemplo n.º 18
0
def remove_file(name, ignore_failure = False):
	Print.status("Removing the file '{0}'".format(name))
	success = False

	try:
		for entry in glob_names(name):
			if os.path.islink(entry):
				os.unlink(entry)
			elif os.path.isfile(entry):
				os.remove(entry)
		success = True
	except Exception as e:
		if ignore_failure:
			success = True

	if success:
		Print.ok()
	else:
		Print.fail()
		Print.exit("Failed to remove the file '{0}'.".format(name))
Exemplo n.º 19
0
def do_on_fail_exit(start_message, fail_message, cb):
    Print.status(start_message)

    # Run it if it is a function
    if hasattr(cb, '__call__'):
        try:
            cb()
            Print.ok()
        except Exception as e:
            Print.fail()
            Print.exit(fail_message)
    # Or run it as a process if a string
    elif type(cb) == str:
        runner = findlib.ProcessRunner(cb)
        runner.run()
        runner.is_done
        runner.wait()
        if runner.is_success or runner.is_warning:
            Print.ok()
        elif runner.is_failure:
            Print.fail()
            Print.exit(fail_message)
Exemplo n.º 20
0
def concurrent_end():
    ready_events = Event.events
    running_events = []

    while len(ready_events) or len(running_events):
        #print(CPU.get_utilization(), CPU.cpus_free)

        # Check for events that are done
        for event in running_events[:]:
            # Check if it is done
            if event.is_done:
                event.wait()

            # Success. Keep going
            if event._status == 'success':
                running_events.remove(event)
                CPU.cpus_free += 1
            # Failure. Stop events and exit
            elif event._status == 'failure':
                Print.exit("Event failed.")

        # Check for events that need to start
        while CPU.cpus_free > 0 and CPU.get_utilization() < 90.0 and len(
                ready_events):
            event = ready_events.pop()
            if event.run():
                CPU.cpus_free -= 1
                running_events.insert(0, event)

        # Sleep if all the cpu cores are busy, or have already started
        if CPU.get_utilization() >= 90.0:
            time.sleep(0.1)

    # Clear all the events
    CPU.cpus_free = CPU.cpus_total * 10  # 10 jobs per core
    Event.events = []
    Event.is_concurrent = False
    Event.is_first_concurrent = False
Exemplo n.º 21
0
def setup():
    global cs_compilers
    global missing_compilers

    # Get the names and paths for know C# compilers
    names = ['dmcs', 'csc']
    for name in names:
        paths = Find.program_paths(name)
        if len(paths) == 0:
            missing_compilers.append(name)
            continue

        if name in ['dmcs']:
            comp = CSCompiler(name=name,
                              path=paths[0],
                              out_file='-out:',
                              debug='-debug',
                              warnings_all='-warn:4',
                              warnings_as_errors='-warnaserror',
                              optimize='-optimize',
                              runtime='mono')
            cs_compilers[comp._name] = comp
        elif name in ['csc']:
            comp = CSCompiler(name=name,
                              path=paths[0],
                              out_file='-out:',
                              debug='-debug',
                              warnings_all='-warn:4',
                              warnings_as_errors='-warnaserror',
                              optimize='-optimize',
                              runtime='')
            cs_compilers[comp._name] = comp

    # Make sure there is at least one C# compiler installed
    if len(cs_compilers) == 0:
        Print.status("Setting up C# module")
        Print.fail()
        Print.exit("No C# compiler found. Install one and try again.")
Exemplo n.º 22
0
def require_root():
	is_root = False

	# Cygwin and BeOS
	if Config.os_type in OSType.Cygwin or Config.os_type in OSType.BeOS:
		# Cygwin has no root user
		is_root = True
	# Windows
	elif Config.os_type in OSType.Windows:
		try:
			# Only Admin can read the C:\windows\temp
			sys_root = os.environ.get('SystemRoot', 'C:\windows')
			temp = os.listdir(os.path.join(sys_root, 'temp'))
			is_root = True
		except:
			pass
	# Linux / Unix
	elif os.getuid() == 0:
		is_root = True

	# Make sure we are root
	if not is_root:
		Print.exit("Must be run as root.")
Exemplo n.º 23
0
def setup():
    global d_compilers
    global missing_compilers

    # Get the names and paths for know D compilers
    compilers = {
        'dmd': ['dmd', r'dmd[0-9]*'],
        'ldc': ['ldc', r'ldc[0-9]*'],
        #gdc
    }
    for name, alt_names in compilers.items():
        paths = Find.program_paths(*alt_names)
        if len(paths) == 0:
            missing_compilers.append(name)
            continue

        if name in ['dmd2', 'dmd']:
            comp = DCompiler(name=name,
                             path=paths[0],
                             setup='',
                             out_file='-of',
                             no_link='-c',
                             lib='-lib',
                             debug='-g',
                             warnings_all='-w',
                             optimize='-O',
                             compile_time_flags='-version=',
                             link='-Wl,-as-needed',
                             interface='-H',
                             interface_file='-Hf',
                             interface_dir='-Hd',
                             unittest='-unittest')
            d_compilers[comp._name] = comp
        elif name in ['ldc2', 'ldc']:
            comp = DCompiler(name=name,
                             path=paths[0],
                             setup='',
                             out_file='-of',
                             no_link='-c',
                             lib='-lib',
                             debug='-g',
                             warnings_all='-w',
                             optimize='-O2',
                             compile_time_flags='-d-version=',
                             link='-Wl,-as-needed',
                             interface='-H',
                             interface_file='-Hf=',
                             interface_dir='-Hd=',
                             unittest='-unittest')
            d_compilers[comp._name] = comp
        elif name in ['gdc']:
            # http://wiki.dlang.org/GDC/Using_GDC
            comp = DCompiler(name=name,
                             path=paths[0],
                             setup='',
                             out_file='-o ',
                             no_link='-c',
                             lib='-lib',
                             debug='-g',
                             warnings_all='-Werror',
                             optimize='-O2',
                             compile_time_flags='-f-version=',
                             link='-Wl,-as-needed',
                             interface='-fintfc=',
                             interface_file='-fintfc-file=',
                             interface_dir='-fintfc-dir=',
                             unittest='-unittest')
            d_compilers[comp._name] = comp

    # Make sure there is at least one D compiler installed
    if len(d_compilers) == 0:
        Print.status("Setting up D module")
        Print.fail()
        Print.exit("No D compiler found. Install one and try again.")
Exemplo n.º 24
0
        print("COMMANDS:")
        print("    ./raise help    - Print the help menu")
        print(
            "    ./raise update  - Downloads the Raise libraries into a directory named \".lib_raise\" or \"lib_raise\"."
        )
        print("")

        # Print all the targets
        if targets:
            no_doc = "No docstring is provided for this target."
            print("TARGETS:")
            for t in targets:
                doc = targets[t].__doc__ or no_doc
                print("    ./raise {0} - {1}".format(t, doc))
                print("")
            Print.exit("No target specified. Found targets are {0}.".format(
                target_list))

    if not targets:
        Print.exit("No 'rscript' file found.")

    # Exit if there is no target with that name
    if not Config.target_name in targets:
        Print.exit("No target named '{0}'. Found targets are {1}.".format(
            Config.target_name, target_list))

    # Inspect the source code if specified
    if Config.is_inspect:
        import inspect
        target = targets[Config.target_name]
        code = inspect.getsourcelines(target)[0]
        code = str.join(' ', code)
Exemplo n.º 25
0
def _on_exit(message):
	Terminal.exit(message)
Exemplo n.º 26
0
 def signal_handler(signal, frame):
     Print.exit('Exit called by the keyboard.')
     sys.exit(1)
Exemplo n.º 27
0
def require_file_extension(file_name, *required_extensions):
    extension = os.path.splitext(file_name)[-1].lower()
    if not extension in required_extensions:
        Print.exit("File extension should be '{0}' on '{1}'.".format(
            str.join(', ', required_extensions), file_name))
Exemplo n.º 28
0
def setup():
    global cxx_compilers
    global missing_compilers

    # Figure out if OS X has the dev tools installed
    OSX_HAS_TOOLS = False
    if Config.os_type in OSType.MacOS:
        result = findlib.run_and_get_stdout(
            'pkgutil --pkg-info=com.apple.pkg.CLTools_Executables')
        if result:
            OSX_HAS_TOOLS = True

    # Get the names and paths for known C++ compilers
    compilers = {
        'g++': ['g++', r'g++[0-9]*', r'g++-[0-9|\.]*'],
        'clang++': ['clang++'],
        'cl.exe': ['cl.exe']
    }
    for name, alt_names in compilers.items():
        paths = Find.program_paths(*alt_names)
        if len(paths) == 0:
            missing_compilers.append(name)
            continue

        standards = {
            Standard.std1998: '-std=c++98',
            Standard.std2003: '-std=c++03',
            Standard.std2011: '-std=c++11',
            Standard.std201x: '-std=c++1x',
            Standard.gnu1998: '-std=gnu++98',
            Standard.gnu2003: '-std=gnu++03',
            Standard.gnu2011: '-std=gnu++11',
            Standard.gnu201x: '-std=gnu++1x'
        }

        if name == 'g++':
            # On Mac OS X skip this compiler if it is clang pretending to be g++
            if Config.os_type in OSType.MacOS and OSX_HAS_TOOLS:
                version = findlib.run_and_get_stdout('g++ --version')
                if version and 'clang' in version.lower():
                    missing_compilers.append(name)
                    continue

            comp = CXXCompiler(name='g++',
                               path=paths[0],
                               standards=standards,
                               setup='',
                               out_file='-o ',
                               no_link='-c',
                               debug='-g',
                               position_independent_code='-fPIC',
                               warnings_all='-Wall',
                               warnings_extra='-Wextra',
                               warnings_as_errors='-Werror',
                               optimize_zero='-O0',
                               optimize_one='-O1',
                               optimize_two='-O2',
                               optimize_three='-O3',
                               optimize_size='-Os',
                               compile_time_flags='-D',
                               link='-shared -Wl,-as-needed')
            cxx_compilers[comp._name] = comp
        elif name == 'clang++':
            comp = CXXCompiler(name='clang++',
                               path=paths[0],
                               standards=standards,
                               setup='',
                               out_file='-o ',
                               no_link='-c',
                               debug='-g',
                               position_independent_code='-fPIC',
                               warnings_all='-Wall',
                               warnings_extra='-Wextra',
                               warnings_as_errors='-Werror',
                               optimize_zero='-O0',
                               optimize_one='-O1',
                               optimize_two='-O2',
                               optimize_three='-O3',
                               optimize_size='-Os',
                               compile_time_flags='-D',
                               link='-shared')
            cxx_compilers[comp._name] = comp
        elif name == 'cl.exe':
            # http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
            comp = CXXCompiler(name='cl.exe',
                               path=paths[0],
                               standards=None,
                               setup='/nologo /EHsc',
                               out_file='/Fe',
                               no_link='/c',
                               debug='/Zi',
                               position_independent_code='',
                               warnings_all='/Wall',
                               warnings_extra=None,
                               warnings_as_errors='/WX',
                               optimize_zero='/Od',
                               optimize_one='/O1',
                               optimize_two='/O2',
                               optimize_three='/Ox',
                               optimize_size='/Os',
                               compile_time_flags='/D',
                               link='/LDd')
            cxx_compilers[comp._name] = comp

    # Make sure there is at least one C++ compiler installed
    if len(cxx_compilers) == 0:
        Print.status("Setting up C++ module")
        Print.fail()
        Print.exit("No C++ compiler found. Install one and try again.")