def checkout(self, ref, ref_is_sha, pull_after_update, stdout=sys.stdout, stderr=sys.stderr): if not os.path.exists(self.root_path): common.check_execute(['mkdir', '-p', self.root_path], stdout=stdout, stderr=stderr) path = os.path.join(self.root_path, self.project['path']) if self.project['repository'] == 'Git': if os.path.exists(path): if ref_is_sha: common.git_update(self.project['url'], ref, path, incremental=self.skip_clean, stdout=stdout, stderr=stderr) else: if not self.skip_clean: common.git_clean(path, stdout=stdout, stderr=stderr) common.git_checkout(ref, path, force=True, stdout=stdout, stderr=stderr) if pull_after_update: common.git_pull(path, stdout=stdout, stderr=stderr) else: common.git_clone(self.project['url'], path, ref, stdout=stdout, stderr=stderr) else: raise common.Unreachable('Unsupported repository: %s' % self.project['repository'])
def strip_resource_phases(repo_path, stdout=sys.stdout, stderr=sys.stderr): """Strip resource build phases from a given project.""" command = ['perl', '-i', '-00ne', 'print unless /Begin PBXResourcesBuildPhase/'] for root, dirs, files in os.walk(repo_path): for filename in files: if filename == 'project.pbxproj': pbxfile = os.path.join(root, filename) common.check_execute(command + [pbxfile], stdout=stdout, stderr=stderr)
def test_swift_package(path, swiftc, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr, added_swift_flags=None, incremental=False): """Test a Swift package manager project.""" swift = os.path.join(os.path.dirname(swiftc), 'swift') if not incremental: clean_swift_package(path, swiftc, sandbox_profile) env = os.environ env['SWIFT_EXEC'] = swiftc command = [swift, 'test', '-C', path, '--verbose'] if added_swift_flags is not None: for flag in added_swift_flags.split(): command += ["-Xswiftc", flag] if (swift_branch not in ['swift-3.0-branch', 'swift-3.1-branch']): command.insert(2, '--disable-sandbox') return common.check_execute(command, timeout=3600, sandbox_profile=sandbox_profile, stdout=stdout, stderr=stderr, env=env)
def build_swift_package(path, swiftc, configuration, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr, added_swift_flags=None, incremental=False): """Build a Swift package manager project.""" swift = os.path.join(os.path.dirname(swiftc), 'swift') if not incremental: clean_swift_package(path, swiftc, sandbox_profile, stdout=stdout, stderr=stderr) env = os.environ env['SWIFT_EXEC'] = swiftc env['SWIFT_SOURCE_COMPAT_SUITE'] = "1" command = [ swift, 'build', '-C', path, '--verbose', '--configuration', configuration ] if (swift_branch not in ['swift-3.0-branch', 'swift-3.1-branch']): command.insert(2, '--disable-sandbox') if added_swift_flags is not None: for flag in added_swift_flags.split(): command += ["-Xswiftc", flag] return common.check_execute(command, timeout=3600, sandbox_profile=sandbox_profile, stdout=stdout, stderr=stderr, env=env)
def build_swift_package(path, swiftc, configuration, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr, incremental=False, stats_path=None): """Build a Swift package manager project.""" swift = swiftc[:-1] if not incremental: clean_swift_package(path, swiftc, sandbox_profile, stdout=stdout, stderr=stderr) env = os.environ env['SWIFT_EXEC'] = swiftc command = [ swift, 'build', '-C', path, '--verbose', '--configuration', configuration ] if stats_path is not None: command += ['-Xswiftc', '-stats-output-dir', '-Xswiftc', stats_path] if (swift_branch not in ['swift-3.0-branch', 'swift-3.1-branch']): command.insert(2, '--disable-sandbox') return common.check_execute(command, timeout=3600, sandbox_profile=sandbox_profile, stdout=stdout, stderr=stderr, env=env)
def test(self, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr, incremental=False): """Test the project target.""" return common.check_execute( self.get_test_command(incremental=incremental), sandbox_profile=sandbox_profile, stdout=stdout, stderr=stdout)
def clean_swift_package(path, swiftc, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr): """Clean a Swift package manager project.""" swift = os.path.join(os.path.dirname(swiftc), 'swift') if swift_branch == 'swift-3.0-branch': command = [swift, 'build', '-C', path, '--clean'] else: command = [swift, 'package', '-C', path, 'clean'] if (swift_branch not in ['swift-3.0-branch', 'swift-3.1-branch']): command.insert(2, '--disable-sandbox') return common.check_execute(command, sandbox_profile=sandbox_profile, stdout=stdout, stderr=stderr)
def test_swift_package(path, swiftc, sandbox_profile, stdout=sys.stdout, stderr=sys.stderr, incremental=False, stats_path=None): """Test a Swift package manager project.""" swift = swiftc[:-1] if not incremental: clean_swift_package(path, swiftc, sandbox_profile) env = os.environ env['SWIFT_EXEC'] = swiftc command = [swift, 'test', '-C', path, '--verbose'] if stats_path is not None: command += ['-Xswiftc', '-stats-output-dir', '-Xswiftc', stats_path] return common.check_execute(command, timeout=3600, sandbox_profile=sandbox_profile, stdout=stdout, stderr=stderr, env=env)
def dispatch(root_path, repo, action, swiftc, swift_version, sandbox_profile_xcodebuild, sandbox_profile_package, added_swift_flags, should_strip_resource_phases=False, stdout=sys.stdout, stderr=sys.stderr, incremental=False, stats_path=None): """Call functions corresponding to actions.""" if stats_path is not None: if os.path.exists(stats_path): shutil.rmtree(stats_path) common.check_execute(['mkdir', '-p', stats_path]) if action['action'] == 'BuildSwiftPackage': return build_swift_package(os.path.join(root_path, repo['path']), swiftc, action['configuration'], sandbox_profile_package, stdout=stdout, stderr=stderr, incremental=incremental, stats_path=stats_path) elif action['action'] == 'TestSwiftPackage': return test_swift_package(os.path.join(root_path, repo['path']), swiftc, sandbox_profile_package, stdout=stdout, stderr=stderr, incremental=incremental, stats_path=stats_path) elif re.match(r'^(Build|Test)Xcode(Workspace|Project)(Scheme|Target)$', action['action']): match = re.match( r'^(Build|Test)Xcode(Workspace|Project)(Scheme|Target)$', action['action']) build_settings = { 'CONFIGURATION': action['configuration'], 'SWIFT_EXEC': swiftc, } other_swift_flags = [] if swift_version: other_swift_flags += ['-swift-version', swift_version] build_settings['SWIFT_VERSION'] = swift_version if stats_path is not None: other_swift_flags += ['-stats-output-dir', stats_path] if added_swift_flags: other_swift_flags.append(added_swift_flags) if other_swift_flags: other_swift_flags = ['$(OTHER_SWIFT_FLAGS)'] + other_swift_flags build_settings['OTHER_SWIFT_FLAGS'] = ' '.join(other_swift_flags) is_workspace = match.group(2).lower() == 'workspace' project_path = os.path.join(root_path, repo['path'], action[match.group(2).lower()]) has_scheme = match.group(3).lower() == 'scheme' xcode_target = \ XcodeTarget(project_path, action[match.group(3).lower()], action['destination'], get_sdk_platform_path(action['destination'], stdout=stdout, stderr=stderr), build_settings, is_workspace, has_scheme) if should_strip_resource_phases: strip_resource_phases(os.path.join(root_path, repo['path']), stdout=stdout, stderr=stderr) if match.group(1) == 'Build': return xcode_target.build(sandbox_profile_xcodebuild, stdout=stdout, stderr=stderr, incremental=incremental) else: return xcode_target.test(sandbox_profile_xcodebuild, stdout=stdout, stderr=stderr, incremental=incremental) else: raise common.Unimplemented("Unknown action: %s" % action['action'])
def main(): args = parse_args() common.set_swift_branch(args.swift_branch) common.debug_print('** REPRODUCE **') skip_swift_build = args.skip_swift_build if args.swiftc: skip_swift_build = True if not skip_swift_build: # Only prompt for deletion if directories exist have_existing_dirs = False if os.path.exists('./build') or os.path.exists('./swift') or \ os.path.exists('./cmark'): have_existing_dirs = True # Optionally clean up previous source/build directories should_cleanup = False should_clone = False if have_existing_dirs and not args.skip_cleanup: if not args.no_prompt: response = raw_input( 'Delete all build and source directories ' 'in current working directory? (y/n): ').strip().lower() if response == 'y': should_cleanup = True else: should_cleanup = True if should_cleanup: common.check_execute( ['./cleanup', args.swift_branch, '--skip-ci-steps']) should_clone = True else: should_clone = True # Build and install Swift and associated projects run_command = [ './run', args.swift_branch, '--skip-ci-steps', '--skip-runner' ] if not should_clone: run_command += ['--skip-clone'] if args.assertions: run_command += ['--assertions'] common.check_execute(run_command, timeout=3600) # Build specified indexed project. Otherwise, build all indexed projects runner_command = [ './runner.py', '--projects', 'projects.json', '--swift-branch', args.swift_branch, '--swift-version', '3', '--include-actions', 'action.startswith("Build")', ] if args.swiftc: runner_command += ['--swiftc', args.swiftc] else: runner_command += [ '--swiftc', './build/compat_macos/install/toolchain/usr/bin/swiftc' ] if args.add_swift_flags: runner_command += ['--add-swift-flags=%s' % args.add_swift_flags] if args.project_path: runner_command += [ '--include-repos', 'path == "%s"' % args.project_path ] if args.sandbox_profile_xcodebuild: runner_command += [ '--sandbox-profile-xcodebuild', args.sandbox_profile_xcodebuild ] if args.sandbox_profile_package: runner_command += [ '--sandbox-profile-package', args.sandbox_profile_package ] common.check_execute(runner_command) return 0