def create_test_workspace(sdk, output, workspace_info):
    # Remove any existing output.
    shutil.rmtree(output, True)

    # Copy the base tests.
    copy_tree(os.path.join(SCRIPT_DIR, 'tests', 'common'), output)
    if workspace_info.with_cc:
        copy_tree(os.path.join(SCRIPT_DIR, 'tests', 'cc'), output)
    if workspace_info.with_dart:
        copy_tree(os.path.join(SCRIPT_DIR, 'tests', 'dart'), output)

    # WORKSPACE file.
    workspace = model.TestWorkspace(os.path.relpath(sdk, output),
                                    workspace_info.with_cc,
                                    workspace_info.with_dart)
    write_file(os.path.join(output, 'WORKSPACE'), 'workspace', workspace)

    # .bazelrc file.
    crosstool = model.Crosstool(workspace_info.target_arches)
    write_file(os.path.join(output, '.bazelrc'), 'bazelrc', crosstool)

    # run.py file
    write_file(os.path.join(output, 'run.py'),
               'run_py',
               crosstool,
               is_executable=True)

    if workspace_info.with_cc:
        # Generate tests to verify that headers compile fine.
        for target, files in workspace_info.headers.iteritems():
            if not files:
                continue
            dir = os.path.join(output, 'headers', target[2:])
            write_file(make_dir(os.path.join(dir, 'BUILD')), 'headers_build', {
                'dep': target,
                'headers': files,
            })
            write_file(make_dir(os.path.join(dir, 'headers.cc')), 'headers',
                       {'headers': files})

    # Tests that generated FIDL bindings are usable.
    for library in workspace_info.fidl_libraries:
        dir = os.path.join(output, 'fidl', library)
        write_file(make_dir(os.path.join(dir, 'BUILD')), 'fidl_build', {
            'library': library,
        })
        write_file(make_dir(os.path.join(dir, 'header_test.cc')),
                   'fidl_headers', {
                       'header': library.replace('_', '/') + '/cpp/fidl.h',
                   })

    return True
Example #2
0
 def install_crosstool(self, arches):
     '''Generates crosstool.bzl based on the availability of sysroot
     versions.
     '''
     if not self.has_cc:
         return
     crosstool = model.Crosstool(arches['target'])
     self.write_file(self.dest('build_defs', 'crosstool.bzl'),
                     'crosstool_bzl', crosstool)
     self.write_file(self.dest('build_defs', 'BUILD.crosstool'),
                     'crosstool', crosstool)
     self.write_file(self.dest('build_defs', 'CROSSTOOL.in'),
                     'crosstool_in', crosstool)
     self.write_file(self.dest('build_defs', 'toolchain', 'BUILD'),
                     'toolchain_build', crosstool)
Example #3
0
    def install_crosstool(self, arches):
        '''Generates crosstool.bzl based on the availability of sysroot
        versions.
        '''
        if not self.has_cc or not self.install:
            return

        crosstool = model.Crosstool(arches['target'])
        crosstool_base = self.dest('build_defs', 'internal', 'crosstool')
        self.write_file(self.dest(crosstool_base, 'crosstool.bzl'),
                        'crosstool_bzl', crosstool)
        self.write_file(self.dest(crosstool_base, 'BUILD.crosstool'),
                        'crosstool', crosstool)
        self.write_file(
            self.dest(crosstool_base, 'cc_toolchain_config.bzl.in'),
            'cc_toolchain_config_bzl_in', crosstool)
        self.write_file(self.dest('build_defs', 'toolchain', 'BUILD'),
                        'toolchain_build', crosstool)
Example #4
0
 def install_crosstool(self):
     sysroot_dir = self.dest('arch')
     if not os.path.isdir(sysroot_dir):
         return
     crosstool = model.Crosstool()
     for arch in os.listdir(sysroot_dir):
         if arch in ARCH_MAP:
             crosstool.arches.append(model.Arch(arch, ARCH_MAP[arch]))
         else:
             print('Unknown target arch: %s' % arch)
     self.write_file(self.dest('build_defs', 'crosstool.bzl'),
                     'crosstool_bzl', crosstool)
     self.write_file(self.dest('build_defs', 'BUILD.crosstool'),
                     'crosstool', crosstool)
     self.write_file(self.dest('build_defs', 'CROSSTOOL.in'),
                     'crosstool_in', crosstool)
     self.write_file(self.dest('build_defs', 'toolchain', 'BUILD'),
                     'toolchain_build', crosstool)
Example #5
0
def create_test_workspace(sdk, output, workspace_info):
    # Remove any existing output.
    shutil.rmtree(output, True)

    # Copy the base tests.
    copy_tree(os.path.join(SCRIPT_DIR, 'tests', 'common'), output)
    if workspace_info.with_cc:
        copy_tree(os.path.join(SCRIPT_DIR, 'tests', 'cc'), output)
    if workspace_info.with_dart:
        copy_tree(os.path.join(SCRIPT_DIR, 'tests', 'dart'), output)

    # WORKSPACE file.
    workspace = model.TestWorkspace(os.path.relpath(sdk, output),
                                    workspace_info.with_cc,
                                    workspace_info.with_dart)
    write_file(os.path.join(output, 'WORKSPACE'), 'workspace', workspace)

    # .bazelrc file.
    crosstool = model.Crosstool(workspace_info.target_arches)
    write_file(os.path.join(output, '.bazelrc'), 'bazelrc', crosstool)

    # run.py file
    write_file(os.path.join(output, 'run.py'),
               'run_py',
               crosstool,
               is_executable=True)

    if workspace_info.with_cc:
        # Generate test to verify that headers compile fine.
        headers = workspace_info.headers
        header_base = os.path.join(output, 'headers')
        write_file(make_dir(os.path.join(
            header_base, 'BUILD')), 'headers_build', {
                'deps': list(filter(lambda k: headers[k], headers.keys())),
            })
        write_file(make_dir(os.path.join(header_base, 'headers.cc')),
                   'headers', {
                       'headers': headers,
                   })

    return True