def run_generator( archive, directory, output, output_archive_only=False, tests='', output_archive='', jiri_manifest=None): """Run the generator. Returns 0 on success, non-zero otherwise. Note that only one of archive or directory should be specified. Args: archive: Path to an SDK tarball archive. directory: Path to an unpackaged SDK. output: The output directory. tests: The directory where to generate tests. Defaults to empty string. """ # Remove any existing output. if os.path.exists(output): shutil.rmtree(output) builder = GNBuilder( archive=archive, directory=directory, output=output, local_dir=SCRIPT_DIR, jiri_manifest=jiri_manifest) if not builder.run(): return 1 if tests: # Create the tests workspace if not create_test_workspace(tests): return 1 # Copy the GN SDK to the test workspace wrkspc_sdk_dir = os.path.join(tests, 'third_party', 'fuchsia-sdk') copy_tree(output, wrkspc_sdk_dir) # Copy test metadata to the workspace. meta/manifest.json tells the # emulator tools where the SDK for integration testing is located. # This must be done after the GN SDK is copied into the test workspace, # which would otherwise overwrite these contents. testdata = os.path.join(SCRIPT_DIR, 'testdata') copy_tree( os.path.join(testdata, 'meta'), os.path.join(wrkspc_sdk_dir, 'meta')) if output_archive: if not create_archive(output_archive, output): return 1 if output_archive_only: shutil.rmtree(output) return 0
def finalize(self, arch, types): # Copy the common files. The destination of these files is relative to # the root of the fuchsia_sdk. copy_tree(self.local('base'), self.output, allow_overwrite=False) # Copy any additional files that would normally not be included for each in EXTRA_COPY: self.copy_file(each.src, each.base, each.dest) self.write_additional_files()
def create_test_workspace(output): # Remove any existing output. shutil.rmtree(output, True) # Copy the base tests. copy_tree(os.path.join(SCRIPT_DIR, 'test_project'), output) # run.py file builder = Frontend(local_dir=SCRIPT_DIR) run_py_path = os.path.join(output, 'run.py') builder.write_file( path=run_py_path, template_name='run_py', data=TestData()) make_executable(run_py_path) return True
def finalize(self, arch, types): # Copy the common files. The destination of these files is relative to # the root of the fuchsia_sdk. copy_tree(self.local('base'), self.output, allow_overwrite=False) self.write_additional_files() # Find CIPD prebuilt gn. gn_path = os.path.join(FUCHSIA_ROOT, 'prebuilt', 'third_party', 'gn', '*', 'gn') gn = glob.glob(gn_path)[0] # Format gn files. for root, _, files in os.walk(self.output): for f in (f for f in files if f.endswith(('.gn', '.gni'))): subprocess.call([gn, 'format', os.path.join(root, f)])
def run_generator(archive, directory, output, tests='', output_archive='', jiri_manifest=None): """Run the generator. Returns 0 on success, non-zero otherwise. Note that only one of archive or directory should be specified. Args: archive: Path to an SDK tarball archive. directory: Path to an unpackaged SDK. output: The output directory. tests: The directory where to generate tests. Defaults to empty string. """ # Remove any existing output. if os.path.exists(output): shutil.rmtree(output) builder = GNBuilder(archive=archive, directory=directory, output=output, local_dir=SCRIPT_DIR, jiri_manifest=jiri_manifest) if not builder.run(): return 1 if tests: # Create the tests workspace if not create_test_workspace(tests): return 1 # Copy the GN SDK to the test workspace wrkspc_sdk_dir = os.path.join(tests, 'third_party', 'fuchsia-sdk') copy_tree(output, wrkspc_sdk_dir) if output_archive: if not create_archive(output_archive, output): return 1 return 0
def prepare(self, arch, types): self.target_arches = arch['target'] # Copy the common files. shutil.copytree(self.local('base', 'common'), self.output) # Copy C/C++ files if needed. if ('sysroot' in types or 'cc_source_library' in types or 'cc_prebuilt_library' in types): self.has_cc = True copy_tree(self.local('base', 'cc'), self.output) # Copy Dart files if needed. if 'dart_library' in types: self.has_dart = True copy_tree(self.local('base', 'dart'), self.output) self.install_crosstool(arch) self.workspace_info.with_cc = self.has_cc self.workspace_info.with_dart = self.has_dart self.workspace_info.target_arches = self.target_arches
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. write_file( os.path.join(output, 'WORKSPACE'), 'workspace', { 'sdk_path': os.path.relpath(sdk, output), 'with_cc': workspace_info.with_cc, 'with_dart': workspace_info.with_dart, }) 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
def prepare(self, arch, types): self.target_arches = arch['target'] cc_types = ('sysroot', 'cc_source_library', 'cc_prebuilt_library') self.has_cc = any(t in types for t in cc_types) if self.install: # Copy the common files. shutil.copytree(self.local('base', 'common'), self.output) # Copy C/C++ files if needed. if self.has_cc: copy_tree(self.local('base', 'cc'), self.output) # Copy Dart files if needed. if 'dart_library' in types: # fxb/41514 : disable dart/flutter bits # self.has_dart = True # copy_tree(self.local('base', 'dart'), self.output) pass self.install_crosstool(arch) self.workspace_info.with_cc = self.has_cc self.workspace_info.with_dart = self.has_dart self.workspace_info.target_arches = self.target_arches
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
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