def _addSteps4SystemCompiler(f, stage_idx=0, clean=True, jobs=None, extra_configure_args=None, env=None): # Index is zero-based, so we want to use a human friendly number instead. stage_num = stage_idx + 1 # Directories to use on this stage. obj_dir = f.stage_objdirs[stage_idx] src_dir = LLVMBuildFactory.pathRelativeTo(f.llvm_srcdir, obj_dir) install_dir = LLVMBuildFactory.pathRelativeTo( f.stage_installdirs[stage_idx], obj_dir) # This stage could use incremental build. # Clean stage1, only if requested. f.addStep( steps.RemoveDirectory(name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=clean)) f.addStep( steps.RemoveDirectory(name='clean-%s-dir' % f.stage_installdirs[stage_idx], dir=f.stage_installdirs[stage_idx], haltOnFailure=False, flunkOnFailure=False, doStepIf=clean)) # Reconcile the cmake options for this stage. # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults. CmakeCommand.applyDefaultOptions( cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'OFF'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), # Do not expect warning free build by the system toolchain. ('-DLLVM_ENABLE_WERROR=', 'OFF'), ]) # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ('-DCMAKE_INSTALL_PREFIX=', install_dir), ]) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DLLVM_ENABLE_PROJECTS=', ";".join(f.depends_on_projects)), ]) # Note: On this stage we do not care of warnings, as we build with # a system toolchain and cannot control the environment. # Warnings are likely, and we ignore them. # Create configuration files with cmake f.addStep( CmakeCommand( name="cmake-configure-stage%s" % stage_num, description=["stage%s cmake configure" % stage_num], haltOnFailure=True, flunkOnWarnings=False, options=cmake_args, path=src_dir, env=env, workdir=obj_dir, )) # Build clang by the system compiler f.addStep( NinjaCommand( name="build-stage%s-compiler" % stage_num, jobs=jobs, haltOnFailure=True, flunkOnWarnings=False, description=["build stage%s compiler" % stage_num], env=env, workdir=obj_dir, )) # Test stage1 compiler f.addStep( NinjaCommand( name="test-stage%s-compiler" % stage_num, targets=["check-all"], # or "check-llvm", "check-clang" jobs=jobs, haltOnFailure=True, flunkOnWarnings=False, description=["test stage%s compiler" % stage_num], env=env, workdir=obj_dir, )) # Install stage1 compiler f.addStep( NinjaCommand( name="install-stage%s-compiler" % stage_num, targets=["install"], jobs=jobs, haltOnFailure=True, description=["install stage%s compiler" % stage_num], env=env, workdir=obj_dir, ))
def _addSteps4StagedCompiler(f, stage_idx=1, use_stage_idx=-1, jobs=None, extra_configure_args=None, env=None): if use_stage_idx < 0: use_stage_idx = stage_idx - 1 # Index is zero-based, so we want to use a human friendly number instead. stage_num = stage_idx + 1 # Directories to use on this stage. obj_dir = f.stage_objdirs[stage_idx] src_dir = LLVMBuildFactory.pathRelativeTo(f.llvm_srcdir, obj_dir) install_dir = LLVMBuildFactory.pathRelativeTo( f.stage_installdirs[stage_idx], obj_dir) staged_install = f.stage_installdirs[use_stage_idx] # Always do a clean build for the staged compiler. f.addStep( steps.RemoveDirectory( name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, )) f.addStep( steps.RemoveDirectory( name='clean-%s-dir' % f.stage_installdirs[stage_idx], dir=f.stage_installdirs[stage_idx], haltOnFailure=False, flunkOnFailure=False, )) # Reconcile the cmake options for this stage. # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ]) # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ('-DCMAKE_INSTALL_PREFIX=', install_dir), ]) cmake_args.append( WithProperties("-DCMAKE_CXX_COMPILER=%(builddir)s/" + staged_install + "/bin/clang++")) cmake_args.append( WithProperties("-DCMAKE_C_COMPILER=%(builddir)s/" + staged_install + "/bin/clang")) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DLLVM_ENABLE_PROJECTS=', ";".join(f.depends_on_projects)), ]) # Create configuration files with cmake f.addStep( CmakeCommand( name="cmake-configure-stage%s" % stage_num, description=["stage%s cmake configure" % stage_num], haltOnFailure=True, options=cmake_args, path=src_dir, env=env, workdir=obj_dir, )) # Build clang by the staged compiler f.addStep( NinjaCommand( name="build-stage%s-compiler" % stage_num, jobs=jobs, haltOnFailure=True, description=["build stage%s compiler" % stage_num], timeout=10800, # LTO could take time. env=env, workdir=obj_dir, )) # Test just built compiler f.addStep( NinjaCommand( name="test-stage%s-compiler" % stage_num, targets=["check-all"], jobs=jobs, haltOnFailure=True, description=["test stage%s compiler" % stage_num], timeout=10800, # LTO could take time. env=env, workdir=obj_dir, )) # Install just built compiler f.addStep( NinjaCommand( name="install-stage%s-compiler" % stage_num, targets=["install"], jobs=jobs, haltOnFailure=True, description=["install stage%s compiler" % stage_num], timeout=10800, # LTO could take time. env=env, workdir=obj_dir, ))
def getSphinxDocsBuildFactory( llvm_html=False, # Build LLVM HTML documentation llvm_man=False, # Build LLVM man pages clang_html=False, # Build Clang HTML documentation clang_tools_html=False, # Build Clang Extra Tools HTML documentation lld_html=False, # Build LLD HTML documentation libcxx_html=False, # Build Libc++ HTML documentation libunwind_html=False, # Build libunwind HTML documentation lldb_html=False, # Build LLDB HTML documentation extra_configure_args=None, **kwargs): if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults for the config flags. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-G', 'Ninja'), ('-DLLVM_ENABLE_SPHINX=', 'ON'), ('-DSPHINX_OUTPUT_HTML=', 'ON'), ('-DSPHINX_OUTPUT_MAN=', 'ON'), ('-DLLDB_INCLUDE_TESTS=', 'OFF'), ('-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'OFF'), ]) llvm_srcdir = 'llvm/src' llvm_objdir = 'llvm/build' depends_on_projects = ['llvm'] if clang_html or clang_tools_html or lldb_html: depends_on_projects.append('clang') if clang_tools_html: depends_on_projects.append('clang-tools-extra') if lld_html: depends_on_projects.append('lld') if lldb_html: depends_on_projects.append('lldb') if libcxx_html: depends_on_projects.append('libcxx') depends_on_projects.append('libcxxabi') if libunwind_html: depends_on_projects.append('libunwind') f = UnifiedTreeBuilder.getCmakeBuildFactory( depends_on_projects=depends_on_projects, llvm_srcdir=llvm_srcdir, obj_dir=llvm_objdir, extra_configure_args=cmake_args, **kwargs) # Pass through all the extra arguments. if llvm_html: f.addStep( NinjaCommand(name="docs-llvm-html", haltOnFailure=True, description=["Build LLVM Sphinx HTML documentation"], workdir=llvm_objdir, targets=['docs-llvm-html'])) if llvm_man: f.addStep( NinjaCommand(name="docs-llvm-man", haltOnFailure=True, description=["Build LLVM Sphinx man pages"], workdir=llvm_objdir, targets=['docs-llvm-man'])) if clang_html: f.addStep( NinjaCommand(name="docs-clang-html", haltOnFailure=True, description=["Build Clang Sphinx HTML documentation"], workdir=llvm_objdir, targets=['docs-clang-html'])) if clang_tools_html: f.addStep( NinjaCommand( name="docs-clang-tools-html", haltOnFailure=True, description=[ "Build Clang Extra Tools Sphinx HTML documentation" ], workdir=llvm_objdir, targets=['docs-clang-tools-html'])) if lld_html: f.addStep( NinjaCommand(name="docs-lld-html", haltOnFailure=True, description=["Build LLD Sphinx HTML documentation"], workdir=llvm_objdir, targets=['docs-lld-html'])) if lldb_html: f.addStep( NinjaCommand(name="docs-lldb-html", haltOnFailure=True, description=["Build LLDB Sphinx HTML documentation"], workdir=llvm_objdir, targets=['docs-lldb-html'])) if libcxx_html: f.addStep( NinjaCommand( name="docs-libcxx-html", haltOnFailure=True, description=["Build Libc++ Sphinx HTML documentation"], workdir=llvm_objdir, targets=['docs-libcxx-html'])) if libunwind_html: f.addStep( NinjaCommand( name="docs-libunwind-html", haltOnFailure=True, description=["Build libunwind Sphinx HTML documentation"], workdir=llvm_objdir, targets=['docs-libunwind-html'])) return f
def getFactory( depends_on_projects = None, targets = None, checks = None, clean = False, extra_configure_args = None, llvm_srcdir = None, obj_dir = None, env = None, **kwargs): # Prepare environmental variables. Set here all env we want for all steps. merged_env = { 'TERM' : 'dumb' # Make sure Clang doesn't use color escape sequences. } if env: # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) if depends_on_projects: depends_on_projects = list(depends_on_projects) else: depends_on_projects = ['llvm', 'lld'] if checks is None: checks = [] # No check unless requested specifically. if extra_configure_args is None: cmake_args = list() else: cmake_args = list(extra_configure_args) # Some options are required for this build no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DLLVM_OPTIMIZED_TABLEGEN=', 'OFF'), ('-DLLVM_BUILD_STATIC=', 'ON'), ('-DLLVM_ENABLE_PIC=', 'OFF'), ]) # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-G', 'Ninja'), ('-DLLVM_LIT_ARGS=', '-v -vv'), ]) f = UnifiedTreeBuilder.getCmakeBuildFactory( depends_on_projects=depends_on_projects, clean=clean, llvm_srcdir=llvm_srcdir, obj_dir=obj_dir, extra_configure_args=cmake_args, env=merged_env, **kwargs) # Pass through all the extra arguments. if targets: step_name = "build-{}".format("-".join(targets)) step_description=["Build"] step_description.extend(targets) else: step_name = "build-unified-tree" step_description=["Build", "unified", "tree"] f.addStep(NinjaCommand(name=step_name, targets=targets, description=step_description, haltOnFailure=kwargs.get('haltOnFailure', True), env=merged_env, workdir=f.obj_dir, **kwargs # Pass through all the extra arguments. )) # Test just built components if requested. if checks: f.addStep(NinjaCommand(name="test-{}".format("-".join(checks)), targets=checks, description=[ "Test", "just", "built", "components"], haltOnFailure=kwargs.get('haltOnFailure', True), env=merged_env, workdir=f.obj_dir, **kwargs # Pass through all the extra arguments. )) # Copy just built LLD executable to the test suite directory # to avoid load from a hard drive overhead. f.addStep( ShellCommand( name="copy-lld-to-test-suite", description=[ "Copy", "LLD", "executable", "to", "the", "performance", "test", "suite", ], command=[ "cp", "-aL", "./{}/bin/ld.lld".format(f.obj_dir), "./lld-speed-test/ld.lld" ], env=merged_env, workdir='.' ) ) # Run the performance test suite. perf_command = [ "python", "%(builddir)s/lld-benchmark.py", "--machine=%(workername)s", "--revision=%(got_revision)s", "--linker=./ld.lld", ".", ] f.addStep( ShellCommand( name="performance-test-suite", description=[ "LLD", "performance","test","suite", ], command=WithProperties(" ".join(perf_command)), workdir="./lld-speed-test", env=merged_env ) ) return f
def addCmakeSteps( f, cleanBuildRequested, obj_dir, install_dir = None, extra_configure_args = None, env = None, stage_name = None, **kwargs): # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # This is an incremental build, unless otherwise has been requested. # Remove obj and install dirs for a clean build. # TODO: Some Windows slaves do not handle RemoveDirectory command well. # So, consider running "rmdir /S /Q <dir>" if the build runs on Windows. f.addStep(RemoveDirectory(name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) if install_dir: install_dir_rel = LLVMBuildFactory.pathRelativeToBuild( install_dir, obj_dir) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir_rel), ]) f.addStep(RemoveDirectory(name='clean-%s-dir' % install_dir, dir=install_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) # Reconcile the cmake options for this build. # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ('-DLLVM_LIT_ARGS=', '"-v"'), ]) # Create configuration files with cmake, unless this has been already done # for an incremental build. if stage_name: step_name = "cmake-configure-%s" % stage_name else: stage_name = "" step_name = "cmake-configure" src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) f.addStep(CmakeCommand(name=step_name, description=["Cmake", "configure", stage_name], options=cmake_args, path=src_dir, haltOnFailure=kwargs.get('haltOnFailure', True), env=env, workdir=obj_dir, **kwargs # Pass through all the extra arguments. ))
def getLLVMDocsBuildFactory(clean=False, depends_on_projects=None, extra_configure_args=None, env=None, **kwargs): if depends_on_projects is None: # All the projects by default. _depends_on_projects = [ "llvm", "clang", "clang-tools-extra", "libcxx", "libcxxabi", "libunwind", "lld", "lldb", "flang", "openmp", "polly", ] else: # Make a local copy of depends_on_projects, as we are going to modify # that. _depends_on_projects = depends_on_projects[:] # Some projects are interdependent for the purpose of documentation. # Enforce the dependencies. if ("clang-tools-extra" in _depends_on_projects or \ "lldb" in _depends_on_projects ) and "clang" not in _depends_on_projects: _depends_on_projects.append("clang") if "libcxx" in _depends_on_projects and \ "libcxxabi" not in _depends_on_projects: _depends_on_projects.append("libcxxabi") if "libcxxabi" in _depends_on_projects and \ "libcxx" not in _depends_on_projects: _depends_on_projects.append("libcxx") # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Prepare environmental variables. Set here all env we want everywhere. merged_env = { 'TERM': 'dumb' # Be cautious and disable color output from all tools. } if env is not None: # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) CmakeCommand.applyDefaultOptions(cmake_args, [ ("-G", "Ninja"), ("-DLLVM_ENABLE_SPHINX=", "ON"), ("-DSPHINX_OUTPUT_HTML=", "ON"), ("-DSPHINX_OUTPUT_MAN=", "OFF"), ("-DSPHINX_WARNINGS_AS_ERRORS=", "OFF"), ("-DLLVM_ENABLE_ASSERTIONS=", "OFF"), ("-DCMAKE_BUILD_TYPE=", "Release"), ]) # Build docs for each of the projects this builder depends on docs = [ llvm_docs[project] for project in llvm_docs.keys() if project in _depends_on_projects ] f = UnifiedTreeBuilder.getCmakeBuildFactory( clean=clean, depends_on_projects=_depends_on_projects, extra_configure_args=cmake_args, env=merged_env, **kwargs) # Pass through all the extra arguments. UnifiedTreeBuilder.addNinjaSteps(f, targets=[d[0] for d in docs], checks=[], env=merged_env, **kwargs) # Publish just built documentation for target, local_path, remote_path in docs: f.addStep( ShellCommand( name="Publish %s" % target, description=[ "Publish", "just", "built", "documentation", "fior", "%s" % target, ], command=[ 'rsync', '-vrl', '--delete', '--force', '--delay-updates', '--delete-delay', '--ignore-times', '--checksum', '-p', '--chmod=Du=rwx,Dg=rwx,Do=rx,Fu=rw,Fg=rw,Fo=r', "%s" % local_path, "lists.llvm.org:web/%s" % remote_path, ], env=merged_env, )) return f
def getCmakeWithMSVCBuildFactory( clean = True, # False for incremental builds. depends_on_projects = None, # List of projects to listen. cmake_cache = None, # Path to a cmake cache file. extra_configure_args = None, # Extra CMake args if any. llvm_srcdir = None, # Source code root directory. obj_dir = None, # Build tree root directory. install_dir = None, # Directory to install the results to. checks = None, # List of checks to test the build. checks_on_target = None, # [(<name>,[<command tokens>])] array of # check name and command to run on target. jobs = None, # Restrict a degree of parallelism. env = None, # Environmental variables for all steps. # VS tools environment variable if using MSVC. # For example, "autodetect" to auto detect, %VS140COMNTOOLS% to select # the VS 2015 toolchain, or empty string if environment is already set. vs=None, **kwargs): if vs is None: # We autodetect Visual Studio, unless otherwise is requested. vs = "autodetect" if install_dir is None: install_dir = 'install' # Prepare environmental variables. Set here all env we want for all steps. merged_env = { 'TERM' : 'dumb' # Make sure Clang doesn't use color escape sequences. } if env is not None: assert not vs, "Cannot have custom builder env vars with VS setup." # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() if depends_on_projects is None: depends_on_projects = [ 'llvm', 'compiler-rt', 'clang', 'clang-tools-extra', 'libunwind', 'libcxx', 'libcxxabi', 'lld', ] if checks is None: # Check only host-side tools. Target-side tests should run on a target. checks=[ "check-llvm", "check-clang", "check-lld", ] source_remove_requested = lambda step: step.build.getProperty("clean") clean_build_requested = lambda step: \ clean or \ step.build.getProperty("clean", \ default=step.build.getProperty("clean_obj") \ ) f = LLVMBuildFactory( depends_on_projects=depends_on_projects, llvm_srcdir=llvm_srcdir, obj_dir=obj_dir, install_dir=install_dir, cleanBuildRequested=clean_build_requested, **kwargs) # Pass through all the extra arguments. # Remove the source code tree if requested. # NOTE: Somehow RemoveDirectory buildbot command often fails on Windows, # as somthing keeps a lock. We use rm command instead realying on a shell # to support that. f.addStep(ShellCommand(name='clean-%s-dir' % f.monorepo_dir, command=['rm','-rf', f.monorepo_dir], warnOnFailure=True, haltOnFailure=False, flunkOnFailure=False, description='Remove the source code', workdir='.', env=merged_env, doStepIf=source_remove_requested)) # Get the source code. f.addGetSourcecodeSteps(**kwargs) # Remove the build directory if requested. f.addStep(ShellCommand(name='clean-%s-dir' % f.obj_dir, command=['rm','-rf', f.obj_dir], warnOnFailure=True, haltOnFailure=False, flunkOnFailure=False, description='Remove build directory', workdir='.', env=merged_env, doStepIf=clean_build_requested)) if vs: # Configure MSVC environment if requested. f.addStep(SetProperty( command=builders_util.getVisualStudioEnvironment(vs, None), extract_fn=builders_util.extractSlaveEnvironment)) merged_env = Property('slave_env') # Since this is a build of a cross toolchain, we build only the host-side # tools first by the host system compiler. Libraries will be cross-compiled. cmake_args.append(InterpolateToPosixPath( '-DLLVM_AR=%(workdir)s/' + f.obj_dir + '/bin/llvm-ar.exe')), CmakeCommand.applyDefaultOptions(cmake_args, [ ('-G', 'Ninja'), ('-DLLVM_ENABLE_PROJECTS=', 'llvm;clang;clang-tools-extra;lld'), ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCMAKE_CXX_FLAGS=', '-D__OPTIMIZE__'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_LIT_ARGS=', '-v -vv'), ]) if install_dir: install_dir_rel = LLVMBuildFactory.pathRelativeTo( install_dir, f.obj_dir) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir_rel), ]) # Remove the build directory if requested. f.addStep(ShellCommand(name='clean-%s-dir' % install_dir, command=['rm','-rf', install_dir], warnOnFailure=True, haltOnFailure=False, flunkOnFailure=False, description='Remove install directory', workdir='.', env=merged_env, doStepIf=clean_build_requested)) src_dir_rel = LLVMBuildFactory.pathRelativeTo(f.llvm_srcdir, f.obj_dir) # Add given cmake cache at the very end. if cmake_cache: cmake_args.append('-C%s' % cmake_cache) f.addStep(CmakeCommand(name="cmake-configure", haltOnFailure=True, description=["Cmake", "configure"], options=cmake_args, path=src_dir_rel, workdir=f.obj_dir, env=merged_env, **kwargs # Pass through all the extra arguments. )) f.addStep(NinjaCommand(name="build-%s" % f.monorepo_dir, haltOnFailure=True, description=["Build", f.monorepo_dir], workdir=f.obj_dir, env=merged_env, **kwargs # Pass through all the extra arguments. )) # Test the components if requested one check at a time. for check in checks: f.addStep( LitTestCommand( haltOnFailure=False, # We want to test as much as we could. name='test-%s' % check, command=["ninja", WithProperties(check)], description=[ "Testing", "just", "built", "components", "for", check], descriptionDone=[ "Test", "just", "built", "components", "for", check, "completed"], env=merged_env, **kwargs # Pass through all the extra arguments. )) # Run commands on a target if requested. if checks_on_target: for check, cmd in checks_on_target: f.addStep( LitTestCommand( haltOnFailure=False, # We want to test as much as we could. name='test-%s' % check, command=cmd, description=[ "Testing", "just", "built", "components", "for", check], descriptionDone=[ "Test", "just", "built", "components", "for", check, "completed"], env=merged_env, **kwargs # Pass through all the extra arguments. )) # Install just built components if install_dir: f.addStep(NinjaCommand(name="install-all", haltOnFailure=True, targets=["install"], description=[ "Install", "just", "built", "components"], workdir=f.obj_dir, env=merged_env, **kwargs # Pass through all the extra arguments. )) return f
def getToolchainBuildFactory( clean=False, test=True, env=None, # Environmental variables for all steps. extra_configure_args=None): # Prepare environmental variables. Set here all env we want everywhere. merged_env = { "TERM" : "dumb", # Make sure Clang doesn't use color escape sequences. } if env is not None: # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) src_dir = "llvm.src" obj_dir = "llvm.obj" install_dir = "llvm.install" f = LLVMBuildFactory( depends_on_projects=[ "llvm", "clang", "clang-tools-extra", "compiler-rt", "libcxx", "libcxxabi", "libunwind", "lld" ]) # Get Fuchsia SDK. sdk_dir = "fuchsia.sdk" sdk_platform = { "Linux": "linux-amd64", "Darwin": "mac-amd64", }[platform.system()] sdk_version = "latest" sdk_url = WithProperties( "https://chrome-infra-packages.appspot.com/dl/" "fuchsia/sdk/%(sdk_platform)s/+/%(sdk_version)s", sdk_platform=lambda _: sdk_platform, sdk_version=lambda _: sdk_version) f.addStep(RemoveDirectory(name="clean-sdk", dir=sdk_dir, haltOnFailure=True)) f.addStep(ShellCommand(name="fetch-sdk", command=["curl", "-SLf", "-o", "sdk.cipd", sdk_url], description=["download", "fuchsia sdk"], workdir=sdk_dir)) f.addStep(ShellCommand(name="extract-sdk", command=["unzip", "-fo", "sdk.cipd"], description=["extract", "fuchsia sdk"], workdir=sdk_dir)) cleanCheckoutRequested = lambda step: step.build.getProperty("clean", default=False) or clean # Clean up llvm sources. f.addStep(RemoveDirectory(name="clean-llvm.src", dir=src_dir, haltOnFailure=True, doStepIf=cleanCheckoutRequested)) # Get sources. for project in f.depends_on_projects: _, baseURL = svn_repos[project] f.addStep(SVN(name="svn-%s" % project, workdir=src_dir + "/" + project, baseURL=baseURL)) cleanBuildRequested = lambda step: step.build.getProperty("clean", default=step.build.getProperty("clean_obj")) or clean # Clean up llvm build. f.addStep(RemoveDirectory(name="clean-llvm.obj", dir=obj_dir, haltOnFailure=True, doStepIf=cleanBuildRequested)) # Configure. if extra_configure_args is None: cmake_options = [] else: cmake_options = extra_configure_args[:] # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_options, [ ("-G", "Ninja"), ("-DLLVM_ENABLE_PROJECTS=", "clang;clang-tools-extra;lld"), ("-DLLVM_ENABLE_RUNTIMES=", "compiler-rt;libcxx;libcxxabi;libunwind"), ]) # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_options, [ ("-DBOOTSTRAP_LLVM_ENABLE_LTO=", "OFF"), ("-DLLVM_ENABLE_LTO=", "OFF"), ]) cmake_options.append( WithProperties( "-DCMAKE_INSTALL_PREFIX=%(workdir)s/" + install_dir )) cmake_options.append( WithProperties( "-DFUCHSIA_SDK=%(workdir)s/" + sdk_dir )) CmakeCommand.applyRequiredOptions(cmake_options, [ ("-C", "../" + src_dir + "/clang/cmake/caches/Fuchsia.cmake"), ]) f.addStep(CmakeCommand(name="cmake-configure", options=cmake_options, path='../' + src_dir + '/llvm', haltOnFailure=True, description=["configure"], workdir=obj_dir, env=merged_env, doStepIf=FileDoesNotExist("CMakeCache.txt"))) # Build distribution. f.addStep(NinjaCommand(name="ninja-build", targets=["stage2-distribution"], haltOnFailure=True, description=["build"], workdir=obj_dir, env=merged_env)) # Test llvm, clang and lld. f.addStep(NinjaCommand(name="check", targets=["stage2-check-%s" % p for p in ("llvm", "clang", "lld")], haltOnFailure=True, description=["check"], workdir=obj_dir, env=merged_env, doStepIf=test)) # Install distribution. f.addStep(NinjaCommand(name="install", targets=["stage2-install-distribution"], haltOnFailure=True, description=["install"], workdir=obj_dir, env=merged_env)) return f
def _addSteps4SystemCompiler( f, stage_idx = 0, clean = True, jobs = None, extra_configure_args = None, env = None): # Index is zero-based, so we want to use a human friendly number instead. stage_num = stage_idx + 1 # Directories to use on this stage. obj_dir = f.stage_objdirs[stage_idx] src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) install_dir = LLVMBuildFactory.pathRelativeToBuild(f.stage_installdirs[stage_idx], obj_dir) # This stage could use incremental build. # Clean stage1, only if requested. f.addStep(RemoveDirectory(name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=clean )) f.addStep(RemoveDirectory(name='clean-%s-dir' % f.stage_installdirs[stage_idx], dir=f.stage_installdirs[stage_idx], haltOnFailure=False, flunkOnFailure=False, doStepIf=clean )) # Reconcile the cmake options for this stage. # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'OFF'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), # Do not expect warning free build by the system toolchain. ('-DLLVM_ENABLE_WERROR=', 'OFF'), ]) # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ('-DCMAKE_INSTALL_PREFIX=', install_dir), ]) # Note: On this stage we do not care of warnings, as we build with # a system toolchain and cannot control the environment. # Warnings are likely, and we ignore them. # Create configuration files with cmake f.addStep(CmakeCommand(name="cmake-configure-stage%s" % stage_num, description=["stage%s cmake configure" % stage_num], haltOnFailure=True, flunkOnWarnings=False, options=cmake_args, path=src_dir, env=env, workdir=obj_dir, doStepIf=FileDoesNotExist("CMakeCache.txt") )) # Build clang by the system compiler f.addStep(NinjaCommand(name="build-stage%s-compiler" % stage_num, jobs=jobs, haltOnFailure=True, flunkOnWarnings=False, description=["build stage%s compiler" % stage_num], env=env, workdir=obj_dir, )) # Test stage1 compiler f.addStep(NinjaCommand(name="test-stage%s-compiler"% stage_num, targets=["check-all"], # or "check-llvm", "check-clang" jobs=jobs, haltOnFailure=True, flunkOnWarnings=False, description=["test stage%s compiler" % stage_num], env=env, workdir=obj_dir, )) # Install stage1 compiler f.addStep(NinjaCommand(name="install-stage%s-compiler"% stage_num, targets=["install"], jobs=jobs, haltOnFailure=True, description=["install stage%s compiler" % stage_num], env=env, workdir=obj_dir, ))
def _addSteps4StagedCompiler( f, stage_idx = 1, use_stage_idx = -1, withLTOSupport = False, jobs = None, extra_configure_args = None, env = None): if use_stage_idx < 0: use_stage_idx = stage_idx - 1 # Index is zero-based, so we want to use a human friendly number instead. stage_num = stage_idx + 1 # Directories to use on this stage. obj_dir = f.stage_objdirs[stage_idx] src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) install_dir = LLVMBuildFactory.pathRelativeToBuild(f.stage_installdirs[stage_idx], obj_dir) staged_install = f.stage_installdirs[use_stage_idx] # Always do a clean build for the staged compiler. f.addStep(RemoveDirectory(name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, )) f.addStep(RemoveDirectory(name='clean-%s-dir' % f.stage_installdirs[stage_idx], dir=f.stage_installdirs[stage_idx], haltOnFailure=False, flunkOnFailure=False, )) # Reconcile the cmake options for this stage. # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ]) if withLTOSupport: CmakeCommand.applyDefaultOptions(cmake_args, [ # LTO Plugin dependency: ('-DLLVM_BINUTILS_INCDIR=', '/opt/binutils/include'), ]) # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ('-DCMAKE_INSTALL_PREFIX=', install_dir), ]) cmake_args.append( WithProperties( "-DCMAKE_CXX_COMPILER=%(workdir)s/" + staged_install + "/bin/clang++" )) cmake_args.append( WithProperties( "-DCMAKE_C_COMPILER=%(workdir)s/" + staged_install + "/bin/clang" )) # Create configuration files with cmake f.addStep(CmakeCommand(name="cmake-configure-stage%s" % stage_num, description=["stage%s cmake configure" % stage_num], haltOnFailure=True, options=cmake_args, path=src_dir, env=env, workdir=obj_dir, doStepIf=FileDoesNotExist("CMakeCache.txt") )) if withLTOSupport: # Build LTO plugin if requested. f.addStep(NinjaCommand(name="build-stage%s-LLVMgold.so" % stage_num, targets=['lib/LLVMgold.so'], jobs=jobs, haltOnFailure=True, description=["stage%s build LLVMgold.so" % stage_num], env=env, workdir=obj_dir, )) # Build clang by the staged compiler f.addStep(NinjaCommand(name="build-stage%s-compiler" % stage_num, jobs=jobs, haltOnFailure=True, description=["build stage%s compiler" % stage_num], timeout=10800, # LTO could take time. env=env, workdir=obj_dir, )) # Test just built compiler f.addStep(NinjaCommand(name="test-stage%s-compiler"% stage_num, targets=["check-all"], jobs=jobs, haltOnFailure=True, description=["test stage%s compiler" % stage_num], timeout=10800, # LTO could take time. env=env, workdir=obj_dir, )) # Install just built compiler f.addStep(NinjaCommand(name="install-stage%s-compiler"% stage_num, targets=["install"], jobs=jobs, haltOnFailure=True, description=["install stage%s compiler" % stage_num], timeout=10800, # LTO could take time. env=env, workdir=obj_dir, ))
def addCmakeSteps(f, cleanBuildRequested, obj_dir, install_dir=None, extra_configure_args=None, env=None, stage_name=None, **kwargs): # Consume is_legacy_mode if given. # TODO: Remove this once legacy mode gets dropped. kwargs.pop('is_legacy_mode', None) # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() if obj_dir is None: obj_dir = f.obj_dir # This is an incremental build, unless otherwise has been requested. # Remove obj and install dirs for a clean build. # TODO: Some Windows slaves do not handle RemoveDirectory command well. # So, consider running "rmdir /S /Q <dir>" if the build runs on Windows. f.addStep( RemoveDirectory( name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) if not f.is_legacy_mode: CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DLLVM_ENABLE_PROJECTS=', ";".join(f.depends_on_projects)), ]) if install_dir: install_dir_rel = LLVMBuildFactory.pathRelativeToBuild( install_dir, obj_dir) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir_rel), ]) f.addStep( RemoveDirectory( name='clean-%s-dir' % install_dir, dir=install_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) # Reconcile the cmake options for this build. # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_LIT_ARGS=', '-v -vv'), ]) # Create configuration files with cmake, unless this has been already done # for an incremental build. if stage_name: step_name = "cmake-configure-%s" % stage_name else: stage_name = "" step_name = "cmake-configure" src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) f.addStep( CmakeCommand( name=step_name, haltOnFailure=True, description=["Cmake", "configure", stage_name], options=cmake_args, path=src_dir, env=env, workdir=obj_dir, **kwargs # Pass through all the extra arguments. ))
def getCUDATestsuiteBuildFactory( externals, # Directory with CUDA, thrust and gcc versions for testing. always_clean=True, test=False, useTwoStage=False, cmake='cmake', extra_cmake_args=None, # Extra CMake args for all stages. extra_ts_cmake_args=None, # extra cmake args for testsuite. jobs=None, cuda_jobs=1, # number of simultaneous CUDA apps to run env=None, # Environmental variables for all steps. enable_thrust_tests=False, split_thrust_tests=False, # Each thrust test is a separate executable. run_thrust_tests=False, enable_libcxx=True, # checkout/build libcxx to test with. gpu_arch_list=None, gpu_devices=None, # List of devices to make visible to CUDA stage1_config='Release', stage2_config='Release'): if extra_cmake_args is None: extra_cmake_args = [] if extra_ts_cmake_args is None: extra_ts_cmake_args = [] # Prepare environmental variables. Set here all env we want for all steps. merged_env = { 'TERM': 'dumb' # Make sure Clang doesn't use color escape sequences. } if env is not None: # Overwrite pre-set items with the given ones, so user can set # anything. merged_env.update(env) source_dir = 'llvm' # Should match the one used in getClangCMakeBuildFactory. stage1_build_dir = 'stage1' # Should match the one defined in getClangCMakeBuildFactory. stage2_build_dir = 'stage2' # Should match the one defined in getClangCMakeBuildFactory. install_dir = 'clang.install' if useTwoStage: clang_build_dir = stage2_build_dir else: clang_build_dir = stage1_build_dir # Build clang. f = ClangBuilder.getClangCMakeBuildFactory( clean=always_clean, test=test, cmake=cmake, extra_cmake_args=extra_cmake_args, jobs=jobs, env=merged_env, useTwoStage=useTwoStage, stage1_config=stage1_config, stage2_config=stage2_config, checkout_clang_tools_extra=False, checkout_compiler_rt=False, checkout_libcxx=enable_libcxx, checkout_lld=False, checkout_test_suite=True) cuda_test_env = { 'PYTHONPATH': WithProperties("%(workdir)s/" + source_dir + "/utils/lit:${PYTHONPATH}"), 'DESTDIR': WithProperties("%(workdir)s/" + install_dir), 'PATH': WithProperties("%(workdir)s/" + install_dir + "/usr/local/bin:${PATH}"), } merged_env.update(cuda_test_env) ts_build_dir = 'test-suite-build' f.addStep( RemoveDirectory(name="Remove old clang install directory", dir=install_dir)) # Install clang into directory pointed by $DESTDIR f.addStep(NinjaCommand( name='ninja install clang', targets=["install"], jobs=jobs, haltOnFailure=True, description=split("installing clang"), descriptionDone=split("Clang installation is done."), workdir=clang_build_dir, env=merged_env)) # Completely remove test suite build dir. f.addStep( RemoveDirectory(name="Remove old test-suite build directory", dir=ts_build_dir)) if extra_ts_cmake_args: cmake_args = extra_ts_cmake_args[:] else: cmake_args = [] # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ]) # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ]) cmake_args.append( WithProperties( "-DCMAKE_CXX_COMPILER=%(workdir)s/" + clang_build_dir + "/bin/clang++" )) cmake_args.append( WithProperties( "-DCMAKE_C_COMPILER=%(workdir)s/" + clang_build_dir + "/bin/clang" )) cmake_args.append('-DTEST_SUITE_SUBDIRS=External'), # Limit to External tests only. if externals: cmake_args.append('-DTEST_SUITE_EXTERNALS_DIR=' + externals) if split_thrust_tests: cmake_args.append('-DTHRUST_SPLIT_TESTS=1') if gpu_arch_list: cmake_args.append('-DCUDA_GPU_ARCH=' + ';'.join(gpu_arch_list)) if cuda_jobs: cmake_args.append('-DCUDA_JOBS=%s' % cuda_jobs) # Then do fresh cmake configuration. f.addStep(CmakeCommand(name='cmake test-suite', description='cmake test-suite', haltOnFailure=True, options=cmake_args, path="../test/test-suite", workdir=ts_build_dir, env=merged_env)) # Always build simple CUDA tests. They serve as compilation # smoketests and will fail quickly if compiler has obvious issues # compiling CUDA files. f.addStep(NinjaCommand( name='ninja build simple CUDA tests', targets=["cuda-tests-simple"], jobs=jobs, haltOnFailure=True, description=split("building simple CUDA tests"), descriptionDone=split("simple CUDA tests built."), workdir=ts_build_dir, env=merged_env)) # Limit GPUs visible to CUDA. if gpu_devices: for gpu_id in gpu_devices: # make ID a string as it may be either an integer or a UUID string. gpu_id = str(gpu_id) gpu_env = dict(merged_env) gpu_env["CUDA_VISIBLE_DEVICES"] = gpu_id f.addStep(NinjaCommand( name='run simple CUDA tests on gpu %s' % gpu_id, targets=["check-cuda-simple"], jobs=1, # lit will parallelize the jobs haltOnFailure=True, description=split("Running simple CUDA tests on GPU %s" % gpu_id), descriptionDone=split("simple CUDA tests on GPU %s done." % gpu_id), workdir=ts_build_dir, env=gpu_env)) else: f.addStep(NinjaCommand( name='run simple CUDA tests', targets=["check-cuda-simple"], jobs=1, # lit will parallelize the jobs haltOnFailure=True, description=split("Running simple CUDA tests"), descriptionDone=split("simple CUDA tests done."), workdir=ts_build_dir, env=merged_env)) # If we've enabled thrust tests, build them now. # WARNING: This takes a lot of time to build. if (enable_thrust_tests): f.addStep(NinjaCommand( name='ninja build thrust', targets=["cuda-tests-thrust"], jobs=jobs, haltOnFailure=True, description=split("building thrust tests"), descriptionDone=split("thrust tests built."), workdir=ts_build_dir, env=merged_env)) # Run them. That also takes a while. # TODO(tra) we may want to run more than one instance so one # can be compiling tests while another is running them on GPU. if run_thrust_tests: f.addStep(NinjaCommand( name='run all CUDA tests', targets=["check"], jobs=1, # lit will parallelize the jobs. haltOnFailure=True, description=split("running all CUDA tests."), descriptionDone=split("all cuda tests done."), workdir=ts_build_dir, env=merged_env)) return f
def addCmakeSteps(f, cleanBuildRequested, obj_dir, generator=None, install_dir=None, extra_configure_args=None, env=None, stage_name=None, **kwargs): # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() if obj_dir is None: obj_dir = f.obj_dir # This is an incremental build, unless otherwise has been requested. # Remove obj and install dirs for a clean build. # TODO: Some Windows workers do not handle RemoveDirectory command well. # So, consider running "rmdir /S /Q <dir>" if the build runs on Windows. f.addStep( steps.RemoveDirectory( name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DLLVM_ENABLE_PROJECTS=', ";".join(f.depends_on_projects)), ]) if install_dir: install_dir_rel = LLVMBuildFactory.pathRelativeTo(install_dir, obj_dir) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir_rel), ]) f.addStep( steps.RemoveDirectory( name='clean-%s-dir' % install_dir, dir=install_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) # Reconcile the cmake options for this build. # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_LIT_ARGS=', '-v -vv'), ]) # Create configuration files with cmake, unless this has been already done # for an incremental build. if stage_name: step_name = "cmake-configure-%s" % stage_name else: stage_name = "" step_name = "cmake-configure" src_dir = LLVMBuildFactory.pathRelativeTo(f.llvm_srcdir, obj_dir) # Make a local copy of the configure args, as we are going to modify that. definitions = dict() options = list() for d in cmake_args: if isinstance(d, str) and d.startswith("-D"): k, v = d[2:].split('=', 1) definitions[k] = v else: options.append(d) f.addStep( CmakeCommand( name=step_name, haltOnFailure=True, description=["Cmake", "configure", stage_name], generator=generator, definitions=definitions, options=options, path=src_dir, env=env or {}, workdir=obj_dir, **kwargs # Pass through all the extra arguments. ))
def getCmakeWithNinjaMultistageBuildFactory(depends_on_projects=None, llvm_srcdir=None, obj_dir=None, checks=None, install_dir=None, clean=False, extra_configure_args=None, env=None, stages=2, stage_names=None, **kwargs): # Prepare environmental variables. Set here all env we want everywhere. merged_env = { 'TERM': 'dumb' # Be cautious and disable color output from all tools. } if env is not None: # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() assert stages > 1, "It should be at least 2 stages in a multistage build." if stage_names is None: stage_names = list() for i in range(1, stages + 1): stage_names.append("stage%s" % i) else: assert len( stage_names ) == stages, "Please specify names for none or all of the requested stages." if obj_dir is None: obj_dir = "build" if install_dir is None: install_dir = "install" if checks is None: checks = ['check-all'] stage_objdirs = list() stage_installdirs = list() for s in stage_names: stage_objdirs.append("%s/%s" % (obj_dir, s)) stage_installdirs.append("%s/%s" % (install_dir, s)) f = getLLVMBuildFactoryAndSVNSteps( depends_on_projects=depends_on_projects, llvm_srcdir=llvm_srcdir, obj_dir=obj_dir, install_dir=install_dir, env=env, stage_objdirs=stage_objdirs, stage_installdirs=stage_installdirs, stage_names=stage_names, **kwargs) # Pass through all the extra arguments. # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'OFF'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ]) # Some options are required for this build no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ]) # The stage 1 is special, though. We use the system compiler and # do incremental build, unless a clean one has been requested. cmake_args_stage1 = cmake_args[:] CmakeCommand.applyDefaultOptions( cmake_args_stage1, [ # Do not expect warning free build by the system toolchain. ('-DLLVM_ENABLE_WERROR=', 'OFF'), ]) cleanBuildRequested = lambda step: step.build.getProperty( "clean", default=step.build.getProperty("clean_obj")) or clean addCmakeSteps(f, cleanBuildRequested=cleanBuildRequested, obj_dir=stage_objdirs[0], install_dir=stage_installdirs[0], extra_configure_args=cmake_args_stage1, env=env, stage_name=stage_names[0], **kwargs) addNinjaSteps(f, obj_dir=stage_objdirs[0], checks=checks, install_dir=stage_installdirs[0], env=env, stage_name=stage_names[0], **kwargs) # Build the rest stage by stage, using just built compiler to compile # the next stage. CmakeCommand.applyDefaultOptions( cmake_args, [ # We should be warnings free when use just built compiler. ('-DLLVM_ENABLE_WERROR=', 'ON'), ]) # If we build LLD, we would link with LLD. # Otherwise we link with a system linker. if 'lld' in f.depends_on_projects: CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DLLVM_ENABLE_LLD=', 'ON'), ]) for stage_idx in range(1, stages): # Directories to use in this stage. obj_dir = f.stage_objdirs[stage_idx] src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) install_dir = LLVMBuildFactory.pathRelativeToBuild( f.stage_installdirs[stage_idx], obj_dir) staged_install = f.stage_installdirs[stage_idx - 1] # Configure the compiler to use in this stage. cmake_args_stageN = cmake_args[:] CmakeCommand.applyRequiredOptions(cmake_args_stageN, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir), ]) cmake_args_stageN.append( WithProperties("-DCMAKE_CXX_COMPILER=%(workdir)s/" + staged_install + "/bin/clang++")) cmake_args_stageN.append( WithProperties("-DCMAKE_C_COMPILER=%(workdir)s/" + staged_install + "/bin/clang")) addCmakeSteps( f, True, # We always do a clean build for the staged builds. obj_dir=stage_objdirs[stage_idx], install_dir=stage_installdirs[stage_idx], extra_configure_args=cmake_args_stageN, env=env, stage_name=stage_names[stage_idx], **kwargs) addNinjaSteps(f, obj_dir=stage_objdirs[stage_idx], checks=checks, install_dir=stage_installdirs[stage_idx], env=env, stage_name=stage_names[stage_idx], **kwargs) return f
def getCmakeBuildFactory(depends_on_projects=None, llvm_srcdir=None, obj_dir=None, install_dir=None, clean=False, extra_configure_args=None, env=None, **kwargs): # Set defaults if not depends_on_projects: depends_on_projects = ['llvm', 'clang'] if extra_configure_args is None: extra_configure_args = [] # Prepare environmental variables. Set here all env we want everywhere. merged_env = { 'TERM': 'dumb' # Be cautious and disable color output from all tools. } if env is not None: # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) if not obj_dir: obj_dir = "build" if install_dir: install_dir_rel = LLVMBuildFactory.pathRelativeToBuild( install_dir, obj_dir) CmakeCommand.applyRequiredOptions(extra_configure_args, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir_rel), ]) cleanBuildRequested = lambda step: step.build.getProperty("clean") or clean f = LLVMBuildFactory( depends_on_projects=depends_on_projects, llvm_srcdir=llvm_srcdir or "llvm.src", obj_dir=obj_dir, install_dir=install_dir, cleanBuildRequested=cleanBuildRequested, **kwargs # Pass through all the extra arguments. ) # Directories to use on this stage. src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) # Do a clean checkout if requested. f.addStep( RemoveDirectory( name='clean-src-dir', dir=f.llvm_srcdir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) # Get the source code. f.addSVNSteps() # This is an incremental build, unless otherwise has been requested. # Remove obj and install dirs for a clean build. f.addStep( RemoveDirectory( name='clean-%s-dir' % f.obj_dir, dir=f.obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) if f.install_dir: f.addStep( RemoveDirectory( name='clean-%s-dir' % f.install_dir, dir=f.install_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) # Reconcile the cmake options for this build. # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ]) # Create configuration files with cmake, unless this has been already done # for an incremental build. f.addStep( CmakeCommand( name="cmake-configure", description=["cmake configure"], haltOnFailure=True, options=cmake_args, path=src_dir, env=env, workdir=obj_dir, doStepIf=FileDoesNotExist("CMakeCache.txt"), **kwargs # Pass through all the extra arguments. )) return f
def addCmakeSteps(f, cleanBuildRequested, obj_dir, install_dir=None, extra_configure_args=None, env=None, stage_name=None, **kwargs): # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # This is an incremental build, unless otherwise has been requested. # Remove obj and install dirs for a clean build. # TODO: Some Windows slaves do not handle RemoveDirectory command well. # So, consider running "rmdir /S /Q <dir>" if the build runs on Windows. f.addStep( RemoveDirectory( name='clean-%s-dir' % obj_dir, dir=obj_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) if install_dir: install_dir_rel = LLVMBuildFactory.pathRelativeToBuild( install_dir, obj_dir) CmakeCommand.applyRequiredOptions(cmake_args, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir_rel), ]) f.addStep( RemoveDirectory( name='clean-%s-dir' % install_dir, dir=install_dir, haltOnFailure=False, flunkOnFailure=False, doStepIf=cleanBuildRequested, )) # Reconcile the cmake options for this build. # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'ON'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ('-DLLVM_LIT_ARGS=', '"-v"'), ]) # Create configuration files with cmake, unless this has been already done # for an incremental build. if stage_name: step_name = "cmake-configure-%s" % stage_name else: stage_name = "" step_name = "cmake-configure" src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) f.addStep( CmakeCommand( name=step_name, description=["Cmake", "configure", stage_name], options=cmake_args, path=src_dir, haltOnFailure=kwargs.get('haltOnFailure', True), env=env, workdir=obj_dir, **kwargs # Pass through all the extra arguments. ))
def getCmakeWithMakeBuildFactory(depends_on_projects=None, llvm_srcdir=None, obj_dir=None, install_dir=None, clean=False, extra_configure_args=None, env=None, **kwargs): # Reconcile the cmake options for this build. # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_COLOR_MAKEFILE=', 'OFF'), ]) # Some options are required for this build no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Unix Makefiles'), ]) f = getCmakeBuildFactory( depends_on_projects=depends_on_projects, llvm_srcdir=llvm_srcdir, obj_dir=obj_dir, install_dir=install_dir or "install", extra_configure_args=cmake_args, env=env, **kwargs # Pass through all the extra arguments. ) # Directories to use for this build. # obj_dir = f.obj_dir # src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) # install_dir = LLVMBuildFactory.pathRelativeToBuild(f.install_dir, obj_dir) # Build the unified tree. f.addStep( MakeCommand( name="build-unified-tree", options=["-k"], haltOnFailure=True, description=["build unified tree"], env=env, workdir=f.obj_dir, **kwargs # Pass through all the extra arguments. )) # Test just built components f.addStep( MakeCommand( name="check-all", targets=["check-all"], haltOnFailure=True, description=["test just built components"], env=env, workdir=f.obj_dir, **kwargs # Pass through all the extra arguments. )) # Install just built components f.addStep( MakeCommand( name="install-all", targets=["install"], haltOnFailure=True, description=["install just built components"], env=env, workdir=f.obj_dir, **kwargs # Pass through all the extra arguments. )) return f
def getCUDATestsuiteBuildFactory( externals, # Directory with CUDA, thrust and gcc versions for testing. always_clean=True, test=False, useTwoStage=False, cmake='cmake', extra_cmake_args=None, # Extra CMake args for all stages. extra_ts_cmake_args=None, # extra cmake args for testsuite. jobs=None, cuda_jobs=1, # number of simultaneous CUDA apps to run env=None, # Environmental variables for all steps. enable_thrust_tests=False, split_thrust_tests=False, # Each thrust test is a separate executable. run_thrust_tests=False, enable_libcxx=True, # checkout/build libcxx to test with. gpu_arch_list=None, gpu_devices=None, # List of devices to make visible to CUDA stage1_config='Release', stage2_config='Release'): if extra_cmake_args is None: extra_cmake_args = [] if extra_ts_cmake_args is None: extra_ts_cmake_args = [] # Prepare environmental variables. Set here all env we want for all steps. merged_env = { 'TERM': 'dumb' # Make sure Clang doesn't use color escape sequences. } if env is not None: # Overwrite pre-set items with the given ones, so user can set # anything. merged_env.update(env) source_dir = 'llvm' # Should match the one used in getClangCMakeBuildFactory. stage1_build_dir = 'stage1' # Should match the one defined in getClangCMakeBuildFactory. stage2_build_dir = 'stage2' # Should match the one defined in getClangCMakeBuildFactory. install_dir = 'clang.install' if useTwoStage: clang_build_dir = stage2_build_dir else: clang_build_dir = stage1_build_dir # Build clang. f = ClangBuilder.getClangCMakeBuildFactory( clean=always_clean, test=test, cmake=cmake, extra_cmake_args=extra_cmake_args, jobs=jobs, env=merged_env, useTwoStage=useTwoStage, stage1_config=stage1_config, stage2_config=stage2_config, checkout_clang_tools_extra=False, checkout_compiler_rt=False, checkout_libcxx=enable_libcxx, checkout_lld=False, checkout_test_suite=True) cuda_test_env = { 'PYTHONPATH': WithProperties("%(workdir)s/" + source_dir + "/utils/lit:${PYTHONPATH}"), 'DESTDIR': WithProperties("%(workdir)s/" + install_dir), 'PATH': WithProperties("%(workdir)s/" + install_dir + "/usr/local/bin:${PATH}"), } merged_env.update(cuda_test_env) ts_build_dir = 'test-suite-build' f.addStep( RemoveDirectory(name="Remove old clang install directory", dir=install_dir)) # Install clang into directory pointed by $DESTDIR f.addStep( NinjaCommand(name='ninja install clang', targets=["install"], jobs=jobs, haltOnFailure=True, description=split("installing clang"), descriptionDone=split("Clang installation is done."), workdir=clang_build_dir, env=merged_env)) # Completely remove test suite build dir. f.addStep( RemoveDirectory(name="Remove old test-suite build directory", dir=ts_build_dir)) if extra_ts_cmake_args: cmake_args = extra_ts_cmake_args[:] else: cmake_args = [] # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ]) # Some options are required for this stage no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ]) cmake_args.append( WithProperties("-DCMAKE_CXX_COMPILER=%(workdir)s/" + clang_build_dir + "/bin/clang++")) cmake_args.append( WithProperties("-DCMAKE_C_COMPILER=%(workdir)s/" + clang_build_dir + "/bin/clang")) cmake_args.append('-DTEST_SUITE_SUBDIRS=External'), # Limit to External tests only. if externals: cmake_args.append('-DTEST_SUITE_EXTERNALS_DIR=' + externals) if split_thrust_tests: cmake_args.append('-DTHRUST_SPLIT_TESTS=1') if gpu_arch_list: cmake_args.append('-DCUDA_GPU_ARCH=' + ';'.join(gpu_arch_list)) if cuda_jobs: cmake_args.append('-DCUDA_JOBS=%s' % cuda_jobs) # Then do fresh cmake configuration. f.addStep( CmakeCommand(name='cmake test-suite', description='cmake test-suite', haltOnFailure=True, options=cmake_args, path="../test/test-suite", workdir=ts_build_dir, env=merged_env)) # Always build simple CUDA tests. They serve as compilation # smoketests and will fail quickly if compiler has obvious issues # compiling CUDA files. f.addStep( NinjaCommand(name='ninja build simple CUDA tests', targets=["cuda-tests-simple"], jobs=jobs, haltOnFailure=True, description=split("building simple CUDA tests"), descriptionDone=split("simple CUDA tests built."), workdir=ts_build_dir, env=merged_env)) # Limit GPUs visible to CUDA. if gpu_devices: for gpu_id in gpu_devices: # make ID a string as it may be either an integer or a UUID string. gpu_id = str(gpu_id) gpu_env = dict(merged_env) gpu_env["CUDA_VISIBLE_DEVICES"] = gpu_id f.addStep( NinjaCommand( name='run simple CUDA tests on gpu %s' % gpu_id, targets=["check-cuda-simple"], jobs=1, # lit will parallelize the jobs haltOnFailure=True, description=split("Running simple CUDA tests on GPU %s" % gpu_id), descriptionDone=split("simple CUDA tests on GPU %s done." % gpu_id), workdir=ts_build_dir, env=gpu_env)) else: f.addStep( NinjaCommand( name='run simple CUDA tests', targets=["check-cuda-simple"], jobs=1, # lit will parallelize the jobs haltOnFailure=True, description=split("Running simple CUDA tests"), descriptionDone=split("simple CUDA tests done."), workdir=ts_build_dir, env=merged_env)) # If we've enabled thrust tests, build them now. # WARNING: This takes a lot of time to build. if (enable_thrust_tests): f.addStep( NinjaCommand(name='ninja build thrust', targets=["cuda-tests-thrust"], jobs=jobs, haltOnFailure=True, description=split("building thrust tests"), descriptionDone=split("thrust tests built."), workdir=ts_build_dir, env=merged_env)) # Run them. That also takes a while. # TODO(tra) we may want to run more than one instance so one # can be compiling tests while another is running them on GPU. if run_thrust_tests: f.addStep( NinjaCommand( name='run all CUDA tests', targets=["check"], jobs=1, # lit will parallelize the jobs. haltOnFailure=True, description=split("running all CUDA tests."), descriptionDone=split("all cuda tests done."), workdir=ts_build_dir, env=merged_env)) return f
def getCmakeWithNinjaMultistageBuildFactory( depends_on_projects = None, llvm_srcdir = None, obj_dir = None, checks = None, install_dir = None, clean = False, extra_configure_args = None, env = None, stages=2, stage_names=None, **kwargs): # Prepare environmental variables. Set here all env we want everywhere. merged_env = { 'TERM' : 'dumb' # Be cautious and disable color output from all tools. } if env is not None: # Overwrite pre-set items with the given ones, so user can set anything. merged_env.update(env) # Make a local copy of the configure args, as we are going to modify that. if extra_configure_args: cmake_args = extra_configure_args[:] else: cmake_args = list() assert stages > 1, "It should be at least 2 stages in a multistage build." if stage_names is None: stage_names = list() for i in range(1, stages + 1): stage_names.append("stage%s" % i) else: assert len(stage_names) == stages, "Please specify names for none or all of the requested stages." if obj_dir is None: obj_dir = "build" if install_dir is None: install_dir = "install" if checks is None: checks = ['check-all'] stage_objdirs = list() stage_installdirs = list() for s in stage_names: stage_objdirs.append("%s/%s" % (obj_dir, s)) stage_installdirs.append("%s/%s" % (install_dir, s)) f = getLLVMBuildFactoryAndSVNSteps( depends_on_projects=depends_on_projects, llvm_srcdir=llvm_srcdir, obj_dir=obj_dir, install_dir=install_dir, env=env, stage_objdirs=stage_objdirs, stage_installdirs=stage_installdirs, stage_names=stage_names, **kwargs) # Pass through all the extra arguments. # Set proper defaults. CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCMAKE_BUILD_TYPE=', 'Release'), ('-DLLVM_BUILD_TESTS=', 'ON'), ('-DLLVM_ENABLE_ASSERTIONS=', 'OFF'), ('-DLLVM_OPTIMIZED_TABLEGEN=', 'ON'), ]) if 'clang' in depends_on_projects: CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DCLANG_BUILD_EXAMPLES=', 'OFF'), ]) # Some options are required for this build no matter what. CmakeCommand.applyRequiredOptions(cmake_args, [ ('-G', 'Ninja'), ]) # The stage 1 is special, though. We use the system compiler and # do incremental build, unless a clean one has been requested. cmake_args_stage1 = cmake_args[:] CmakeCommand.applyDefaultOptions(cmake_args_stage1, [ # Do not expect warning free build by the system toolchain. ('-DLLVM_ENABLE_WERROR=', 'OFF'), ]) cleanBuildRequested = lambda step: step.build.getProperty("clean", default=step.build.getProperty("clean_obj")) or clean addCmakeSteps( f, cleanBuildRequested=cleanBuildRequested, obj_dir=stage_objdirs[0], install_dir=stage_installdirs[0], extra_configure_args=cmake_args_stage1, env=env, stage_name=stage_names[0], **kwargs) addNinjaSteps( f, obj_dir=stage_objdirs[0], checks=checks, install_dir=stage_installdirs[0], env=env, stage_name=stage_names[0], **kwargs) # Build the rest stage by stage, using just built compiler to compile # the next stage. CmakeCommand.applyDefaultOptions(cmake_args, [ # We should be warnings free when use just built compiler. ('-DLLVM_ENABLE_WERROR=', 'ON'), ]) # If we build LLD, we would link with LLD. # Otherwise we link with a system linker. if 'lld' in f.depends_on_projects: CmakeCommand.applyDefaultOptions(cmake_args, [ ('-DLLVM_ENABLE_LLD=', 'ON'), ]) for stage_idx in range(1, stages): # Directories to use in this stage. obj_dir = f.stage_objdirs[stage_idx] src_dir = LLVMBuildFactory.pathRelativeToBuild(f.llvm_srcdir, obj_dir) install_dir = LLVMBuildFactory.pathRelativeToBuild(f.stage_installdirs[stage_idx], obj_dir) staged_install = f.stage_installdirs[stage_idx - 1] # Configure the compiler to use in this stage. cmake_args_stageN = cmake_args[:] CmakeCommand.applyRequiredOptions(cmake_args_stageN, [ ('-DCMAKE_INSTALL_PREFIX=', install_dir), ]) cmake_args_stageN.append( WithProperties( "-DCMAKE_CXX_COMPILER=%(workdir)s/" + staged_install + "/bin/clang++" )) cmake_args_stageN.append( WithProperties( "-DCMAKE_C_COMPILER=%(workdir)s/" + staged_install + "/bin/clang" )) addCmakeSteps( f, True, # We always do a clean build for the staged builds. obj_dir=stage_objdirs[stage_idx], install_dir=stage_installdirs[stage_idx], extra_configure_args=cmake_args_stageN, env=env, stage_name=stage_names[stage_idx], **kwargs) addNinjaSteps( f, obj_dir=stage_objdirs[stage_idx], checks=checks, install_dir=stage_installdirs[stage_idx], env=env, stage_name=stage_names[stage_idx], **kwargs) return f