Пример #1
0
def update_project_view_title(t):
    new_name = Project.root().file().name()
    new_short_name = Project.root().name()
    view = MDI.get("Project View")

    if view is not None:
        view.rename(new_name, new_short_name)
        t.remove()
Пример #2
0
def on_gps_started(hook):
    # Set the preferences. You can adjust them at your convenience.
    Preference("Doc-Process-Body").set(True)
    Preference("Doc-Show-Private").set(True)
    Preference("Doc-References").set(True)
    Preference("Doc-Up-To-Date-Only").set(False)

    # Generate documentation for the root projects and all subprojects.
    Project.root().generate_doc(recursive=True)

    # Try to exit every 10 seconds.
    delayed_exit(10000)
Пример #3
0
def add_breakpoint_exception():
    context = current_context()
    global autocont_br
    # Only consider base names of files, since the debugger does not always
    # show the full name in the "frame" command
    f = "%s:%s" % (os.path.basename(
        context.file().path), context.location().line())
    if f in autocont_br:
        autocont_br.remove(f)
    else:
        autocont_br.add(f)
    if Preference("Plugins/debugger/save_autocont_br").get():
        Project.root().set_property("autocont_br", "--".join(autocont_br),
                                    True)
Пример #4
0
def indent_all(menu):
    for f in Project.root().sources(recursive=True):
        ed = EditorBuffer.get(f)
        ed.indent()
        ed.save()
        ed.close()
    Console().write("Done indenting")
Пример #5
0
def on_compilation_finished(*args):
    obj_dirs = Project.root().object_dirs(False)
    path = obj_dirs[0] if obj_dirs else dirname(Project.root().file().path)
    base = file_name_pref.get()

    if not base:
        Console().write(
            "plugin save_on_compile.py: no file name is specified in the"
            " preferences\n")
    else:
        try:
            full = join(path, base)
            with open(full, "w") as f:
                f.write(Console().get_text())
            Console().write("Output saved in %s\n" % (full, ))
        except Exception:
            Console().write(
                "plugin save_on_compile.py: error saving in '%s'\n" % (full, ))
Пример #6
0
    def compute_buildfile(self):
        """Compute the build file to use. By default, we look in the project
           itself. If none is specified there, we default on the build file
           found in the same directory as the root project"""

        root_dir = os.path.dirname(Project.root().file().path)
        self.buildfile = Project.root().get_attribute_as_string(
            self.build_file_attr, self.pkg_name)

        self.buildfile = os.path.join(root_dir, self.buildfile)
        if not os.path.isfile(self.buildfile):
            for f in self.default_build_files:
                self.buildfile = os.path.join(root_dir, f)
                if os.path.isfile(self.buildfile):
                    break
                self.buildfile = None
        Logger("MAKE").log("Build file for %s is %s" %
                           (self.pkg_name, self.buildfile))
Пример #7
0
def on_project_view_changed(h):
    global autocont_br
    try:
        autocont_br = set(
            Project.root().get_property("autocont_br").split("--"))
        Console().write(
            "The debugger will not stop when an exception is raised at " +
            "\n".join(autocont_br))
    except:
        autocont_br = set()
Пример #8
0
def on_compilation_finished(category, target_name, mode_name, status):
    obj_dirs = Project.root().object_dirs(False)
    path = obj_dirs[0] if obj_dirs else dirname(Project.root().file().path)
    base = file_name_pref.get()

    if not base:
        Console().write(
            "plugin save_on_compile.py: no file name is specified in the"
            + " preferences\n")
    else:
        try:
            full = join(path, base)
            with open(full, "w") as f:
                f.write(Console().get_text())
            Console().write("Output saved in %s\n" % (full, ))
        except:
            Console().write(
                "plugin save_on_compile.py: error saving in '%s'\n" % (
                    full, ))
Пример #9
0
def compute_project_dependencies(output):
    try:
        depends_on = dict()
        current_deps = dict()
        for p in Project.root().dependencies(recursive=True):
            current_deps[p] = [cur for cur in p.dependencies(recursive=False)]
            tmp = dict()
            previous = p
            for s in p.sources(recursive=False):
                for imp in s.imports(include_implicit=True,
                                     include_system=False):
                    ip = imp.project(default_to_root=False)
                    if ip and ip != p:
                        if show_single_file:
                            if ip != previous:
                                tmp[ip] = [(s, imp)]
                        else:
                            try:
                                tmp[ip].append((s, imp))
                            except KeyError:
                                tmp[ip] = [(s, imp)]
                        previous = ip
            depends_on[p] = tmp

        no_source_projects = [
            s.strip().lower() for s in Preference(
                "Plugins/dependencies/no_src_prj").get().split(",")
        ]

        for p in depends_on:
            output.set_current_project(p)
            for dep in depends_on[p]:
                output.add_dependency(dep, newdep=dep not in current_deps[p])
                for reason in depends_on[p][dep]:
                    output.explain_dependency(reason[0], reason[1])

                try:
                    current_deps[p].remove(dep)
                except:
                    pass

            for dep in current_deps[p]:
                if dep.path.lower() not in no_source_projects:
                    output.add_dependency(dep, newdep=False, removed=True)

        output.close()
    except:
        Console().write("Unexpected exception " + traceback.format_exc())
Пример #10
0
def global_entities(where=None):
    """Return all global entities in where, which should either be an instance
       of GPS.File, GPS.Project, or None. In the latter case, all global
       entities in the application are returned"""
    result = []
    if not where:
        for p in Project.root().dependencies(recursive=True):
            result.extend(global_entities(p))

    elif isinstance(where, Project):
        for s in where.sources():
            result.extend(global_entities(s))

    elif isinstance(where, File):
        for e in where.entities():
            if e.attributes()["global"]:
                result.append(e)
    return result
Пример #11
0
def remove_gcov():
    "Cleanup the gcov coverage files"

    if not MDI.yes_no_dialog(
            "This will remove all .gcov and .gcda files, are you sure ?"):
        return

    # Look in all the projects

    for p in Project.root().dependencies(True):
        object_dirs = p.object_dirs(False)

        if len(object_dirs) > 0:
            object_dir = object_dirs[0]

            # Browse in the object dirs
            for f in os.listdir(object_dir):
                #  if f is a .gcda or a .gcov, remove it
                if f.find(".gcda") != -1 or f.find(".gcov") != -1:
                    os.remove(object_dir + os.sep + f)
Пример #12
0
def EntityIterator(where):
    """Return all entities from WHERE"""
    if not where:
        ignore_projects = [
            s.strip().lower() for s in Preference(
                "Plugins/unused_entities/ignoreprj").get().split(",")
        ]

        for p in Project.root().dependencies(recursive=True):
            if p.name().lower() not in ignore_projects:
                Console().write("Searching unused entities in project " +
                                p.name() + "\n")
                for s in p.sources():
                    for e in s.entities(local=True):
                        yield e
    elif isinstance(where, Project):
        for s in where.sources():
            for e in s.entities(local=True):
                yield e
    elif isinstance(where, File):
        for e in where.entities(local=True):
            yield e
Пример #13
0
def run_gcov():
    "Run gcov to generate the coverage files"
    # Verify that the version of gcov is recent enough to support response
    # files and reading of .gc?? data in multiple directories.

    try:
        p = Process("gcov --version")
        out = p.get_result()
        p = re.compile("[1-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]")
        found = p.findall(out)
        if not found:
            MDI.dialog("Could not find a date in the output of gcov.")
        else:
            date = found[0]
            if int(date) < 20071005:
                MDI.dialog("Your version of gcov is dated " + str(date) +
                           ".\nThis plugin requires gcov for GNAT dated " +
                           "20071005 or later.")
                return
    except Exception:
        MDI.dialog("""Could not read gcov version number.

Make sure you are using gcov for GNAT dated 20071005 or later.""")

    # Determine the root project
    root_project = Project.root()

    # Determine where to create the gcov info
    GCOV_ROOT = os.getenv("GCOV_ROOT")

    if not GCOV_ROOT:
        root_object_dirs = root_project.object_dirs(False)
        if not root_object_dirs:
            MDI.dialog("""The root project does not have an object directory.
 Please add one, or set the enviroment variable GCOV_ROOT to
 the directory where you would like the gcov files to be
 generated.""")
            return
        else:
            gcov_dir = root_object_dirs[0]

    else:
        gcov_dir = GCOV_ROOT

    if not os.access(gcov_dir, os.R_OK and os.W_OK):
        MDI.dialog(""" Could not access the directory:

   """ + gcov_dir + """

Please point the environment variable GCOV_ROOT to a directory
on which you have permission to read and write.
         """)

    input_file = os.path.abspath(os.path.join(gcov_dir, "gcov_input.txt"))

    # List all the projects
    projects = root_project.dependencies(True)
    # List all object dirs
    object_dirs = root_project.object_dirs(True)

    # Write the response file
    res = open(input_file, 'w')

    gcda_file_found = False
    gcno_file_found = False

    for p in projects:
        sources = p.sources(False)

        for s in sources:
            n = s.path
            basename = n[max(n.rfind('\\'), n.rfind('/')) + 1:len(n)]
            unit = basename[0:basename.rfind('.')]

            for object_dir in object_dirs:
                gcda = object_dir + os.sep + unit + ".gcda"

                # If we have not yet found at least one .gcno file, attempt to
                # find one. This is to improve the precision of error messages,
                # and detect the case where compilation was successful but the
                # executable has never been run.

                if not gcno_file_found:
                    gcno = object_dir + os.sep + unit + ".gcno"
                    if os.access(gcno, os.F_OK):
                        gcno_file_found = True

                if os.access(gcda, os.F_OK):
                    gcda_file_found = True
                    # Write one entry in response file

                    # Escape all backslashes.
                    gcda = gcda.replace('\\', '\\\\')

                    res.write('"' + gcda + '"' + "\n")
                    break

    res.close()

    open(input_file).read()

    if not gcno_file_found:
        # No gcno file was found: display an appropriate message.
        MDI.dialog(
            """ No ".gcno" file was found in any of the object directories.

Make sure you have compiled the sources of interest with
the "Code coverage" flags.""")

    else:
        if not gcda_file_found:
            # Some gcno files were found, but no gcna files.
            MDI.dialog(
                """ No ".gcda" file was found in any of the object directories.

Make sure you have run the executable(s) at least once.
""")

        else:
            # Run gcov
            Gcov_Process("gcov", "@%s" % input_file, directory=gcov_dir)