class TestProject(TestCase):

    """test things related to the Project class"""

    def setUp(self):
        self.settings = ProjectSettings()

    def test_update(self):
        self.settings.update(settings_dict)

        assert self.settings.get_env_settings('iar') == settings_dict['tools']['iar']['path'][0]
        assert self.settings.get_env_settings('uvision') == settings_dict['tools']['uvision']['path'][0]
        assert self.settings.export_location_format == settings_dict['export_dir'][0]
예제 #2
0
    def testProjectToolspecificValid(self):
        self.project_dic['tool_specific'] = {}
        self.project_dic['tool_specific']['uvision'] = {}
        self.project_dic['tool_specific']['uvision']['build_dir'] = 'test_build'
        self.project_dic['tool_specific']['uvision']['debugger'] = 'test_debugger'
        self.project_dic['tool_specific']['uvision']['export_dir'] = 'test_export'
        self.project_dic['tool_specific']['uvision']['target'] = 'test_target'
        self.project_dic['tool_specific']['uvision']['output_type'] = 'test_lib'
        self.project_dic['tool_specific']['uvision']['tools_supported'] = ['test_tool']
        self.project_dic['tool_specific']['uvision']['includes'] = ['test_export']
        self.project_dic['tool_specific']['uvision']['linker_file'] = 'test_linker'
        self.project_dic['tool_specific']['uvision']['macros'] = ['test_macro']
        self.project_dic['tool_specific']['uvision']['misc'] = {'test_misc': 'test_value'}
        self.project_dic['tool_specific']['uvision']['template'] = 'test_template'

        project = Project('test_name', [self.project_dic], ProjectSettings())

        # Tool specific should be same as common, we can override anything there
        assert project.project['tool_specific']['uvision']['name'] == 'test_name'
        assert project.project['tool_specific']['uvision']['build_dir'] == 'test_build'
        assert project.project['tool_specific']['uvision']['debugger'] == 'test_debugger'
        assert project.project['tool_specific']['uvision']['export_dir'] == 'test_export'
        assert project.project['tool_specific']['uvision']['target'] == 'test_target'
        assert project.project['tool_specific']['uvision']['output_type'] == 'test_lib'
        assert project.project['tool_specific']['uvision']['tools_supported'][0] == 'test_tool'
        assert self.project_dic['tool_specific']['uvision']['includes'][0] == 'test_export'
        assert self.project_dic['tool_specific']['uvision']['linker_file'] == 'test_linker'
        assert self.project_dic['tool_specific']['uvision']['macros'][0] == 'test_macro'
        assert self.project_dic['tool_specific']['uvision']['misc']['test_misc'] == 'test_value'
        assert self.project_dic['tool_specific']['uvision']['template'] == 'test_template'
예제 #3
0
    def testProjectCommon(self):
        self.project_dic['common']['name'] = 'test_name'
        self.project_dic['common']['build_dir'] = 'test_build'
        self.project_dic['common']['debugger'] = 'test_debugger'
        self.project_dic['common']['export_dir'] = 'test_export'
        self.project_dic['common']['target'] = 'test_target'
        self.project_dic['common']['output_type'] = 'test_lib'
        self.project_dic['common']['tools_supported'] = ['test_tool']
        self.project_dic['common']['includes'] = ['test_export']
        self.project_dic['common']['linker_file'] = 'test_linker'
        self.project_dic['common']['macros'] = ['test_macro']
        self.project_dic['common']['misc'] = {'test_misc': 'test_value'}
        self.project_dic['common']['template'] = 'test_template'

        project = Project('test_name', [self.project_dic], ProjectSettings())

        assert project.project['common']['name'] == 'test_name'
        assert project.project['common']['build_dir'] == 'test_build'
        assert project.project['common']['debugger'] == 'test_debugger'
        assert project.project['common']['export_dir'] == 'test_export'
        assert project.project['common']['target'] == 'test_target'
        assert project.project['common']['output_type'] == 'test_lib'
        assert project.project['common']['tools_supported'][0] == 'test_tool'
        assert self.project_dic['common']['includes'][0] == 'test_export'
        assert self.project_dic['common']['linker_file'] == 'test_linker'
        assert self.project_dic['common']['macros'][0] == 'test_macro'
        assert self.project_dic['common']['misc']['test_misc'] == 'test_value'
        assert self.project_dic['common']['template'] == 'test_template'
예제 #4
0
    def setUp(self):
        if not os.path.exists('test_workspace'):
            os.makedirs('test_workspace')

        # create 3 files to test project
        with open(os.path.join(os.getcwd(), 'test_workspace/main.cpp'),
                  'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/file2.cpp'),
                  'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/file3.cpp'),
                  'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/header1.h'),
                  'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/header2.h'),
                  'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/header3.h'),
                  'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/linker.ld'),
                  'wt') as f:
            pass

        self.project = Project('project_1', [project_1_yaml, project_2_yaml],
                               ProjectSettings())
예제 #5
0
 def progen_build(self):
     """Build a project that was already generated by progen"""
     builder = ToolsSupported().get_tool(self.NAME)
     result = builder(self.builder_files_dict[self.NAME],
                      ProjectSettings()).build_project()
     if result == -1:
         raise FailedBuildException("Build Failed")
예제 #6
0
파일: exporters.py 프로젝트: t-ogihara/mbed
 def progen_gen_file(self, tool_name, project_data):
     """" Generate project using ProGen Project API """
     settings = ProjectSettings()
     project = Project(self.program_name, [project_data], settings)
     # TODO: Fix this, the inc_dirs are not valid (our scripts copy files), therefore progen
     # thinks it is not dict but a file, and adds them to workspace.
     project.project['common']['include_paths'] = self.resources.inc_dirs
     project.generate(tool_name, copied=not self.sources_relative)
예제 #7
0
 def progen_build(self):
     """Build a project that was already generated by progen"""
     print("Project {} exported, building for {}...".format(
         self.project_name, self.NAME))
     sys.stdout.flush()
     builder = ToolsSupported().get_tool(self.NAME)
     result = builder(self.builder_files_dict[self.NAME],
                      ProjectSettings()).build_project()
     if result == -1:
         raise FailedBuildException("Build Failed")
예제 #8
0
 def progen_gen_file(self, tool_name, project_data, progen_build=False):
     """ Generate project using ProGen Project API """
     settings = ProjectSettings()
     project = Project(self.program_name, [project_data], settings)
     # TODO: Fix this, the inc_dirs are not valid (our scripts copy files), therefore progen
     # thinks it is not dict but a file, and adds them to workspace.
     project.project['common']['include_paths'] = self.resources.inc_dirs
     project.generate(tool_name, copied=not self.sources_relative)
     if progen_build:
         print("Project exported, building...")
         result = project.build(tool_name)
         if result == -1:
             raise FailedBuildException("Build Failed")
예제 #9
0
    def setUp(self):
        if not os.path.exists('test_workspace'):
            os.makedirs('test_workspace')
        # write project file
        with open(os.path.join(os.getcwd(), 'test_workspace/project_1.yaml'), 'wt') as f:
            f.write(yaml.dump(project_1_yaml, default_flow_style=False))
        # write projects file
        with open(os.path.join(os.getcwd(), 'test_workspace/projects.yaml'), 'wt') as f:
            f.write(yaml.dump(projects_yaml, default_flow_style=False))

        self.project = Project('project_1',[project_1_yaml],
            ProjectSettings())

        self.workspace = ProjectWorkspace('workspace_project_1', [self.project],
            ProjectSettings(), {})


        # create 3 files to test project
        with open(os.path.join(os.getcwd(), 'test_workspace/main.cpp'), 'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/header1.h'), 'wt') as f:
            pass
        with open(os.path.join(os.getcwd(), 'test_workspace/linker.ld'), 'wt') as f:
            pass
    def setUp(self):
        if not os.path.exists('test_workspace'):
            os.makedirs('test_workspace')
        # write project file
        with open(os.path.join(os.getcwd(), 'test_workspace/project_1.yaml'),
                  'wt') as f:
            f.write(yaml.dump(project_1_yaml, default_flow_style=False))
        # write projects file
        with open(os.path.join(os.getcwd(), 'test_workspace/projects.yaml'),
                  'wt') as f:
            f.write(yaml.dump(projects_1_yaml, default_flow_style=False))

        self.project = next(Generator(projects_1_yaml).generate('project_1'))

        self.eclipse = EclipseGnuARM(self.project.project, ProjectSettings())
    def setUp(self):
        if not os.path.exists('test_workspace'):
            os.makedirs('test_workspace')
        # write project file
        with open(os.path.join(os.getcwd(), 'test_workspace/project_1.yaml'), 'wt') as f:
            f.write(yaml.dump(project_1_yaml, default_flow_style=False))
        with open(os.path.join(os.getcwd(), 'test_workspace/project_2.yaml'), 'wt') as f:
            f.write(yaml.dump(project_2_yaml, default_flow_style=False))
        # write projects file
        with open(os.path.join(os.getcwd(), 'test_workspace/projects.yaml'), 'wt') as f:
            f.write(yaml.dump(projects_1_yaml, default_flow_style=False))

        self.project = next(Generator(projects_1_yaml).generate('project_1'))
        self.project2 = next(Generator(projects_1_yaml).generate('project_2'))

        self.defintions = uVisionDefinitions()
        self.uvision = Uvision5(self.project.project, ProjectSettings())
예제 #12
0
    def progen_gen_file(self, project_data):
        """ Generate project using ProGen Project API
        Positional arguments:
        tool_name    - the tool for which to generate project files
        project_data - a dict whose base key, values are specified in
                       progen_get_project_data, the items will have been
                       modified by Exporter subclasses

        Keyword arguments:
        progen_build - A boolean that determines if the tool will build the
                       project
        """
        if not self.check_supported(self.NAME):
            raise TargetNotSupportedException("Target not supported")
        settings = ProjectSettings()
        exporter = ToolsSupported().get_tool(self.NAME)
        self.builder_files_dict = {
            self.NAME: exporter(project_data, settings).export_project()
        }
        for middle in self.builder_files_dict.values():
            for field, thing in middle.iteritems():
                if field == "files":
                    for filename in thing.values():
                        self.generated_files.append(filename)
예제 #13
0
 def progen_gen_file(self, tool_name, project_data):
     """" Generate project using ProGen Project API """
     settings = ProjectSettings()
     project = Project(self.program_name, [project_data], settings)
     project.generate(tool_name, copied=True)
예제 #14
0
 def setUp(self):
     settings = ProjectSettings()
     self.targets = Targets(settings.get_env_settings('definitions'))
예제 #15
0
    def testProjectToolSpecificNonvalid(self):
        project = Project('test_name', [self.project_dic], ProjectSettings())

        # non valid - no tool specified, tool specific should be empty array
        assert not project.project['tool_specific']
예제 #16
0
def test_output_directory_formatting():
    path, depth = Project._generate_output_dir(ProjectSettings(),'aaa/bbb/cccc/ddd/eee/ffff/ggg')

    assert depth == 7
    assert os.path.normpath(path) == os.path.normpath('../../../../../../../')
예제 #17
0
def main():
    logging_setup.init()
    logging.getLogger().setLevel(logging.INFO)

    p = argparse.ArgumentParser()

    p.add_argument('--version',
                   dest='show_version',
                   action='version',
                   version=pkg_resources.require("valinor")[0].version,
                   help='display the version')

    p.add_argument(
        '-t',
        '--tool',
        dest='ide_tool',
        default=None,
        help='Debug tool (IDE) to generate for. If omitted, a debug project ' +
        'will be generated for an IDE detected on your system, ' +
        'defaulting to opening a GDB debug session, if no known IDEs ' +
        'are detected')

    p.add_argument(
        '-d',
        '--project-dir',
        dest='project_dir',
        default=None,
        help='The directory in which to generate any necessary project files.  '
        + 'Defaults to the directory of the executable argument.')

    p.add_argument(
        '-n',
        '--no-open',
        dest='start_session',
        default=True,
        action='store_false',
        help='Do not open the debug session, just generate the necessary ' +
        'files to enable debugging, and print the command that would be ' +
        'necessary to proceed.')

    p.add_argument(
        '--target',
        dest='target',
        required=True,
        help='The target board to generate a project file for (e.g. K64F).')

    p.add_argument('executable', help='Path to the executable to debug.')

    args = p.parse_args()

    # check that the executable exists before we proceed, so we get a nice
    # error message if it doesn't
    if not os.path.isfile(args.executable):
        logging.error('cannot debug file "%s" that does not exist' %
                      args.executable)
        sys.exit(1)

    project_settings = ProjectSettings()
    update.update(None, False, False, project_settings)

    available_ides = ide_detection.available()
    ide_tool = args.ide_tool
    if not ide_tool:
        ide_tool = ide_detection.select(available_ides, args.target,
                                        project_settings)
        if ide_tool is None:
            if len(available_ides):
                logging.error('None of the detected IDEs supports "%s"',
                              args.target)
            else:
                logging.error('No IDEs were detected on this system!')
            logging.info('Searched for:\n  %s',
                         '\n  '.join(ide_detection.IDE_Preference))
    if ide_tool is None:
        logging.error(
            'No IDE tool available for target "%s". Please see ' +
            'https://github.com/0xc0170/project_generator for details ' +
            'on adding support.', args.target)
        sys.exit(1)

    file_name = os.path.split(args.executable)[1]
    file_base_name = os.path.splitext(file_name)[0]
    executable_dir = os.path.dirname(args.executable)

    projectfile_dir = args.project_dir or executable_dir

    # pass empty data to the tool for things we don't care about when just
    # debugging (in the future we could add source files by reading the debug
    # info from the file being debugged)
    data = {
        'name': file_base_name,  # project name
        'core': '',  # core
        'linker_file': '',  # linker command file
        'include_paths': [],  # include paths
        'source_paths': [],  # source paths
        'source_files_c': [],  # c source files
        'source_files_cpp': [],  # c++ source files
        'source_files_s': [],  # assembly source files
        'source_files_obj': [],  # object files
        'source_files_lib': [],  # libraries
        'macros': [],  # macros (defines)
        'project_dir': {
            'name': '.' + os.path.sep,
            'path': projectfile_dir
        },
        'output_dir':
        os.path.relpath(executable_dir, projectfile_dir) + os.path.sep,
        'misc': [],
        'target': args.target
    }

    exporter = tool.ToolsSupported().get_value(ide_tool, 'exporter')
    # generate debug project files (if necessary)
    projectfile_path, projectfiles = tool.export(exporter, data, ide_tool,
                                                 project_settings)
    if projectfile_path is None:
        logging.error("failed to generate project files")
        sys.exit(1)

    # perform any modifications to the executable itself that are necessary to
    # debug it (for example, to debug an ELF with Keil uVision, it must be
    # renamed to have the .axf extension)
    executable = tool.fixup_executable(exporter, args.executable, ide_tool)

    if args.start_session:
        launch_fn = ide_detection.get_launcher(ide_tool)
        if launch_fn is not None:
            launch_fn(projectfiles, executable)
        else:
            logging.warning('failed to open IDE')
            print 'project files have been generated in:', os.path.normpath(
                projectfile_path)
    else:
        print 'project files have been generated in:', os.path.normpath(
            projectfile_path)
예제 #18
0
def main():
    logging_setup.init()
    logging.getLogger().setLevel(logging.INFO)

    p = argparse.ArgumentParser()

    p.add_argument('--version', dest='show_version', action='version',
        version=pkg_resources.require("valinor")[0].version,
        help='display the version'
    )

    p.add_argument('-t', '--tool', dest='ide_tool', default=None,
        help='Debug tool (IDE) to generate for. If omitted, a debug project '+
             'will be generated for an IDE detected on your system, '+
             'defaulting to opening a GDB debug session, if no known IDEs '+
             'are detected'
    )

    p.add_argument('-d', '--project-dir', dest='project_dir', default=None,
        help='The directory in which to generate any necessary project files.  '+
             'Defaults to the directory of the executable argument.'
    )

    p.add_argument('-n', '--no-open', dest='start_session', default=True, action='store_false',
        help='Do not open the debug session, just generate the necessary '+
             'files to enable debugging, and print the command that would be '+
             'necessary to proceed.'
    )

    p.add_argument('--target', dest='target', required=True,
        help='The target board to generate a project file for (e.g. K64F).'
    )

    p.add_argument('executable',
        help='Path to the executable to debug.'
    )

    args = p.parse_args()

    # check that the executable exists before we proceed, so we get a nice
    # error message if it doesn't
    if not os.path.isfile(args.executable):
        logging.error('cannot debug file "%s" that does not exist' % args.executable)
        sys.exit(1)

    # Get setttings and generator (it updates targets def prior select)
    projects = {
        'projects' : {}
    }
    generator = Generator(projects)
    project_settings = ProjectSettings()

    available_ides = ide_detection.available()
    ide_tool = args.ide_tool
    if not ide_tool:
        ide_tool = ide_detection.select(available_ides, args.target, project_settings)
        if ide_tool is None:
            if len(available_ides):
                logging.error('None of the detected IDEs supports "%s"', args.target)
            else:
                logging.error('No IDEs were detected on this system!')
            logging.info('Searched for:\n  %s', '\n  '.join(ide_detection.IDE_Preference))
    if ide_tool is None:
        logging.error(
            'No IDE tool available for target "%s". Please see '+
            'https://github.com/project-generator/project_generator for details '+
            'on adding support.', args.target
        )
        sys.exit(1)

    file_name      = os.path.split(args.executable)[1]
    file_base_name = os.path.splitext(file_name)[0]
    executable_dir = os.path.dirname(args.executable)

    projectfile_dir = args.project_dir or executable_dir

    files = elf.get_files_from_executable(args.executable)

    # pass empty data to the tool for things we don't care about when just
    # debugging (in the future we could add source files by reading the debug
    # info from the file being debugged)
    project_data = {
        'common': {
            'target': [args.target],  # target
            'build_dir': ['.'],
            'linker_file': ['None'],
            'export_dir': ['.' + os.path.sep + projectfile_dir],
            'output_dir': {
                'rel_path' : [''],
                'path' : [os.path.relpath(executable_dir, projectfile_dir) + os.path.sep],
            },
            'sources': {'Source_Files':sorted([f for f in files], key=lambda file: os.path.basename(file))},
        }
    }

    project = Project(file_base_name, [project_data], project_settings)
    project.generate(ide_tool)

    # perform any modifications to the executable itself that are necessary to
    # debug it (for example, to debug an ELF with Keil uVision, it must be
    # renamed to have the .axf extension)
    executable = args.executable
    if ide_tool in ('uvision', 'uvision5'):
        new_exe_path = args.executable + '.axf'
        shutil.copy(args.executable, new_exe_path)
        executable = new_exe_path
    projectfiles = project.get_generated_project_files(ide_tool)
    if not projectfiles:
        logging.error("failed to generate project files")
        sys.exit(1)

    if args.start_session:
        launch_fn = ide_detection.get_launcher(ide_tool)
        if launch_fn is not None:
            try:
                launch_fn(projectfiles['files'], executable)
            except Exception as e:
                logging.error('failed to launch debugger: %s', e)
        else:
            logging.warning('failed to open IDE')
    print('project files have been generated in: %s' % os.path.join(os.getcwd(), os.path.normpath(projectfiles['path'])))
 def setUp(self):
     self.settings = ProjectSettings()
예제 #20
0
 def setUp(self):
     settings = ProjectSettings()
     self.targets = Targets(settings.get_env_settings('definitions'))