コード例 #1
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())
コード例 #2
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)
コード例 #3
0
ファイル: exporters.py プロジェクト: TemcoHeng/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=True)
コード例 #4
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")
コード例 #5
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'
コード例 #6
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'
コード例 #7
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],
                               Generator(projects_yaml))

        self.workspace = ProjectWorkspace('workspace_project_1',
                                          [self.project],
                                          Generator(projects_yaml))

        # 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
コード例 #8
0
ファイル: exporters.py プロジェクト: tung7970/mbed-os
 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')

        # 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())
コード例 #10
0
def test_output_directory_formatting():
    path, depth = Project._generate_output_dir('aaa/bbb/cccc/ddd/eee/ffff/ggg')

    assert depth == 7
    assert os.path.normpath(path) == os.path.normpath('../../../../../../../')
コード例 #11
0
ファイル: exporters.py プロジェクト: phantomGik/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)
     project.generate(tool_name, copied=True)
コード例 #12
0
ファイル: main.py プロジェクト: ARMmbed/yotta_osx_installer
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

    # 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': [''],
            'debugger': ['cmsis-dap'],   # TODO: find out what debugger is connected
            '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],
            }
        }
    }

    project = Project(file_base_name, [project_data], generator)
    project.export(ide_tool, False)

    # 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 == 'uvision':
        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:
            launch_fn(projectfiles['files'], executable)
        else:
            logging.warning('failed to open IDE')
            print 'project files have been generated in:', os.path.normpath(projectfiles['path'])
    else:
        print 'project files have been generated in:', os.path.normpath(projectfiles['path'])
コード例 #13
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('../../../../../../../')
コード例 #14
0
ファイル: exporters.py プロジェクト: kqkq/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)
     project.generate(tool_name, copied=True)
コード例 #15
0
ファイル: main.py プロジェクト: sreekanth370/valinor
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'])))
コード例 #16
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']
コード例 #17
0
class TestProjectDict(TestCase):

    """test things related to the Project class, using python dicts"""

    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())

    def tearDown(self):
        # remove created directory
        shutil.rmtree('test_workspace', ignore_errors=True)

    def test_name(self):
        assert self.project.name == 'project_1'

    def test_project_attributes(self):
        self.project._fill_export_dict('uvision')
        assert self.project.project['export']['macros'] == project_1_yaml['common']['macros'] + project_2_yaml['common']['macros'] 
        assert set(self.project.project['export']['include_files'].keys()) & set(['default'] + list(project_2_yaml['common']['includes'].keys()))

        # no c or asm files, empty dics
        assert self.project.project['export']['source_files_c'] == dict()
        assert self.project.project['export']['source_files_s'] == dict()
        # source groups should be equal
        assert self.project.project['export']['source_files_cpp'].keys() == merge_recursive(project_1_yaml['common']['sources'], project_2_yaml['common']['sources']).keys()

    def test_sources_groups(self):
        self.project._fill_export_dict('uvision')
        source_groups = []
        for dic in self.project.project['export']['sources']:
            for k, v in dic.items():
                source_groups.append(k)
        assert source_groups == list(project_1_yaml['common']['sources'].keys()) + list(project_2_yaml['common']['sources'].keys())

    def test_copy(self):
        # test copy method which should copy all files to generated project dir by default
        self.project._fill_export_dict('uvision', True)
        self.project._copy_sources_to_generated_destination()

    def test_set_output_dir_path(self):
        self.project._fill_export_dict('uvision')
        # we use default one in this class
        assert self.project.project['export']['output_dir']['path'] == os.path.join('generated_projects', 'uvision_project_1')
コード例 #18
0
class TestProjectDict(TestCase):
    """test things related to the Project class, using python dicts"""
    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())

    def tearDown(self):
        # remove created directory
        shutil.rmtree('test_workspace', ignore_errors=True)

    def test_name(self):
        assert self.project.name == 'project_1'

    def test_project_attributes(self):
        self.project._fill_export_dict('uvision')
        assert set(self.project.project['export']['macros'] +
                   [None]) & set(project_1_yaml['common']['macros'] +
                                 project_2_yaml['common']['macros'])
        assert set(self.project.project['export']['include_files'].keys()
                   ) & set(['default'] +
                           list(project_2_yaml['common']['includes'].keys()))

        # no c or asm files, empty dics
        assert self.project.project['export']['source_files_c'] == dict()
        assert self.project.project['export']['source_files_s'] == dict()
        # source groups should be equal
        assert self.project.project['export']['source_files_cpp'].keys(
        ) == merge_recursive(project_1_yaml['common']['sources'],
                             project_2_yaml['common']['sources']).keys()

    def test_sources_groups(self):
        self.project._fill_export_dict('uvision')
        source_groups = []
        for dic in self.project.project['export']['sources']:
            for k, v in dic.items():
                source_groups.append(k)
        assert source_groups == list(
            project_1_yaml['common']['sources'].keys()) + list(
                project_2_yaml['common']['sources'].keys())

    def test_copy(self):
        # test copy method which should copy all files to generated project dir by default
        self.project._fill_export_dict('uvision', True)
        self.project._copy_sources_to_generated_destination()

    def test_set_output_dir_path(self):
        self.project._fill_export_dict('uvision')
        # we use default one in this class
        assert self.project.project['export']['output_dir'][
            'path'] == os.path.join('generated_projects', 'uvision_project_1')