def ProcessProject(pepperdir, srcroot, dstroot, desc, toolchains, configs=None, first_toolchain=False): if not configs: configs = ['Debug', 'Release'] name = desc['NAME'] out_dir = os.path.join(dstroot, desc['DEST'], name) buildbot_common.MakeDir(out_dir) srcdirs = desc.get('SEARCH', ['.', SDK_RESOURCE_DIR]) # Copy sources to example directory sources = GenerateSourceCopyList(desc) FindAndCopyFiles(sources, srcroot, srcdirs, out_dir) # Copy public headers to the include directory. for headers_set in desc.get('HEADERS', []): headers = headers_set['FILES'] header_out_dir = os.path.join(dstroot, headers_set['DEST']) FindAndCopyFiles(headers, srcroot, srcdirs, header_out_dir) make_path = os.path.join(out_dir, 'Makefile') outdir = os.path.dirname(os.path.abspath(make_path)) if getos.GetPlatform() == 'win': AddMakeBat(pepperdir, outdir) # If this project has no TARGETS, then we don't need to generate anything. if 'TARGETS' not in desc: return (name, desc['DEST']) if IsNexe(desc): template = os.path.join(SDK_RESOURCE_DIR, 'Makefile.example.template') else: template = os.path.join(SDK_RESOURCE_DIR, 'Makefile.library.template') # Ensure the order of |tools| is the same as toolchains; that way if # first_toolchain is set, it will choose based on the order of |toolchains|. tools = [tool for tool in toolchains if tool in desc['TOOLS']] if first_toolchain: tools = [tools[0]] for target in desc['TARGETS']: target.setdefault('CXXFLAGS', []) target['CXXFLAGS'].insert(0, '-Wall') template_dict = { 'desc': desc, 'rel_sdk': '/'.join(['..'] * (len(desc['DEST'].split('/')) + 1)), 'pre': desc.get('PRE', ''), 'post': desc.get('POST', ''), 'tools': tools, 'targets': desc['TARGETS'], } RunTemplateFileIfChanged(template, make_path, template_dict) if IsExample(desc): ProcessHTML(srcroot, dstroot, desc, toolchains, configs, first_toolchain) if not desc.get('NO_PACKAGE_FILES'): GenerateManifest(srcroot, dstroot, desc) return (name, desc['DEST'])
def ConfigName(toolchain): if toolchain == getos.GetPlatform(): return 'host' else: return toolchain
def testGetIrtBinPath(self): """GetIrtBinPath checks that irtbin exists.""" platform = getos.GetPlatform() with mock.patch('os.path.exists') as mock_exists: irt = getos.GetIrtBinPath(platform) mock_exists.assert_called_with(irt)
def GnNinjaInstall(pepperdir, toolchains): tools_files_x86 = [ ['sel_ldr', 'sel_ldr_x86_32'], ] tools_files_x64 = [ ['sel_ldr', 'sel_ldr_x86_64'], ['ncval_new', 'ncval'], ['clang_newlib_arm/elf_loader.nexe', 'elf_loader_arm.nexe'], ['irt_x86/irt_core.nexe', 'irt_core_x86_32.nexe'], ['irt_x64/irt_core.nexe', 'irt_core_x86_64.nexe'], ] tools_files_arm = [] platform = getos.GetPlatform() # TODO(binji): dump_syms doesn't currently build on Windows. See # http://crbug.com/245456 if platform != 'win': tools_files_x64 += [ ['dump_syms', 'dump_syms'], ['minidump_dump', 'minidump_dump'], ['minidump_stackwalk', 'minidump_stackwalk'] ] if platform == 'linux': tools_files_x86 += [['nonsfi_loader', 'nonsfi_loader_x86_32'], ['nacl_helper_bootstrap', 'nacl_helper_bootstrap_x86_32']] tools_files_x64 += [['nacl_helper_bootstrap', 'nacl_helper_bootstrap_x86_64']] # Add ARM trusted binaries (linux only) if not options.no_arm_trusted: tools_files_x64 += [ ['irt_arm/irt_core.nexe', 'irt_core_arm.nexe'], ] tools_files_arm += [ ['nacl_helper_bootstrap', 'nacl_helper_bootstrap_arm'], ['nonsfi_loader', 'nonsfi_loader_arm'], ['sel_ldr', 'sel_ldr_arm'] ] tools_dir = os.path.join(pepperdir, 'tools') buildbot_common.MakeDir(tools_dir) # Add .exe extensions to all windows tools for pair in tools_files_x86 + tools_files_x64: if platform == 'win' and not os.path.splitext(pair[0])[1]: pair[0] += '.exe' pair[1] += '.exe' InstallFiles(GetNinjaOutDir('x64'), tools_dir, tools_files_x64) InstallFiles(GetNinjaOutDir('x86'), tools_dir, tools_files_x86) if platform == 'linux': InstallFiles(GetNinjaOutDir('arm'), tools_dir, tools_files_arm) stub_dir = os.path.join(SRC_DIR, 'ppapi/native_client/src/untrusted/irt_stub') for tc in toolchains: if tc in ('host', 'clang-newlib'): continue elif tc == 'pnacl': xarches = ('pnacl', 'x86', 'x64', 'arm') elif tc in ('x86_glibc'): xarches = ('x86', 'x64') elif tc == 'arm_glibc': xarches = ('arm',) else: raise AssertionError('unexpected toolchain value: %s' % tc) for xarch in xarches: src_dir = GetGnBuiltLib(tc, xarch) src_dir = os.path.join(src_dir, 'obj', 'ppapi', 'native_client', 'src', 'untrusted', 'irt_stub') dst_dir = GetOutputToolchainLib(pepperdir, tc, xarch) InstallFiles(src_dir, dst_dir, ['libppapi_stub.a']) InstallFiles(stub_dir, dst_dir, ['libppapi.a']) if 'glibc' in tc: InstallFiles(stub_dir, dst_dir, ['libppapi.so'])
def main(args): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--qemu', help='Add qemu for ARM.', action='store_true') parser.add_argument('--tar', help='Force the tar step.', action='store_true') parser.add_argument('--archive', help='Force the archive step.', action='store_true') parser.add_argument('--release', help='PPAPI release version.', dest='release', default=None) parser.add_argument('--build-app-engine', help='Build AppEngine demos.', action='store_true') parser.add_argument('--experimental', help='build experimental examples and libraries', action='store_true', dest='build_experimental') parser.add_argument('--skip-toolchain', help='Skip toolchain untar', action='store_true') parser.add_argument('--no-clean', dest='clean', action='store_false', help="Don't clean gn build directories") parser.add_argument('--mac-sdk', help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.') parser.add_argument('--no-arm-trusted', action='store_true', help='Disable building of ARM trusted components (sel_ldr, etc).') parser.add_argument('--no-use-sysroot', action='store_true', help='Disable building against sysroot.') # To setup bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete build_sdk.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass global options options = parser.parse_args(args) buildbot_common.BuildStep('build_sdk') if buildbot_common.IsSDKBuilder(): options.archive = True # TODO(binji): re-enable app_engine build when the linux builder stops # breaking when trying to git clone from github. # See http://crbug.com/412969. options.build_app_engine = False options.tar = True # NOTE: order matters here. This will be the order that is specified in the # Makefiles; the first toolchain will be the default. toolchains = ['pnacl', 'x86_glibc', 'arm_glibc', 'clang-newlib', 'host'] print 'Building: ' + ' '.join(toolchains) platform = getos.GetPlatform() if options.archive and not options.tar: parser.error('Incompatible arguments with archive.') chrome_version = int(build_version.ChromeMajorVersion()) chrome_revision = build_version.ChromeRevision() nacl_revision = build_version.NaClRevision() pepper_ver = str(chrome_version) pepper_old = str(chrome_version - 1) pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old) tarname = 'naclsdk_%s.tar.bz2' % platform tarfile = os.path.join(OUT_DIR, tarname) if options.release: pepper_ver = options.release print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision) if 'NACL_SDK_ROOT' in os.environ: # We don't want the currently configured NACL_SDK_ROOT to have any effect # of the build. del os.environ['NACL_SDK_ROOT'] if platform == 'linux': # Linux-only: make sure the debian/stable sysroot image is installed install_script = os.path.join(SRC_DIR, 'build', 'linux', 'sysroot_scripts', 'install-sysroot.py') buildbot_common.Run([sys.executable, install_script, '--arch=arm']) buildbot_common.Run([sys.executable, install_script, '--arch=i386']) buildbot_common.Run([sys.executable, install_script, '--arch=amd64']) if not options.skip_toolchain: BuildStepCleanPepperDirs(pepperdir, pepperdir_old) BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools']) BuildStepDownloadToolchains(toolchains) BuildStepUntarToolchains(pepperdir, toolchains) if platform == 'linux': buildbot_common.Move(os.path.join(pepperdir, 'toolchain', 'arm_trusted'), os.path.join(OUT_DIR, 'arm_trusted')) if platform == 'linux': # Linux-only: Copy arm libraries from the arm_trusted package. These are # needed to be able to run sel_ldr_arm under qemu. arm_libs = [ 'lib/arm-linux-gnueabihf/librt.so.1', 'lib/arm-linux-gnueabihf/libdl.so.2', 'lib/arm-linux-gnueabihf/libpthread.so.0', 'lib/arm-linux-gnueabihf/libgcc_s.so.1', 'lib/arm-linux-gnueabihf/libc.so.6', 'lib/arm-linux-gnueabihf/ld-linux-armhf.so.3', 'lib/arm-linux-gnueabihf/libm.so.6', ] arm_lib_dir = os.path.join(pepperdir, 'tools', 'lib', 'arm_trusted', 'lib') buildbot_common.MakeDir(arm_lib_dir) for arm_lib in arm_libs: arm_lib = os.path.join(OUT_DIR, 'arm_trusted', arm_lib) buildbot_common.CopyFile(arm_lib, arm_lib_dir) buildbot_common.CopyFile(os.path.join(OUT_DIR, 'arm_trusted', 'qemu-arm'), os.path.join(pepperdir, 'tools')) BuildStepBuildToolchains(pepperdir, toolchains, not options.skip_toolchain, options.clean) BuildStepUpdateHelpers(pepperdir, True) BuildStepUpdateUserProjects(pepperdir, toolchains, options.build_experimental, True) BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, nacl_revision) # Ship with libraries prebuilt, so run that first. BuildStepBuildLibraries(pepperdir) GenerateNotice(pepperdir) # Verify the SDK contains what we expect. BuildStepVerifyFilelist(pepperdir) if options.tar: BuildStepTarBundle(pepper_ver, tarfile) if platform == 'linux': BuildStepBuildPNaClComponent(pepper_ver, chrome_revision) if options.build_app_engine and platform == 'linux': BuildStepBuildAppEngine(pepperdir, chrome_revision) if options.qemu: qemudir = os.path.join(NACL_DIR, 'toolchain', 'linux_arm-trusted') oshelpers.Copy(['-r', qemudir, pepperdir]) # Archive the results on Google Cloud Storage. if options.archive: BuildStepArchiveBundle('build', pepper_ver, chrome_revision, nacl_revision, tarfile) # Only archive sdk_tools/naclport/pnacl_component on linux. if platform == 'linux': BuildStepArchiveSDKTools() BuildStepArchivePNaClComponent(chrome_revision) return 0
def main(args): usage = '%prog [<options>] [<phase...>]' parser = optparse.OptionParser(description=__doc__, usage=usage) parser.add_option('--experimental', help='build experimental tests', action='store_true') parser.add_option('--sanitizer', help='Run sanitizer (asan/tsan/valgrind) tests', action='store_true') parser.add_option('--verbose', '-v', help='Verbose output', action='store_true') if 'NACL_SDK_ROOT' in os.environ: # We don't want the currently configured NACL_SDK_ROOT to have any effect # of the build. del os.environ['NACL_SDK_ROOT'] # To setup bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete test_sdk.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass options, args = parser.parse_args(args[1:]) pepper_ver = str(int(build_version.ChromeMajorVersion())) pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) toolchains = ['newlib', 'glibc', 'pnacl'] toolchains.append(getos.GetPlatform()) if options.verbose: build_projects.verbose = True phases = [ ('build_examples', StepBuildExamples, pepperdir), ('copy_tests', StepCopyTests, pepperdir, toolchains, options.experimental), ('build_tests', StepBuildTests, pepperdir), ('sel_ldr_tests', StepRunSelLdrTests, pepperdir, None), ('browser_tests', StepRunBrowserTests, toolchains, options.experimental), ] if options.sanitizer: if getos.GetPlatform() != 'linux': buildbot_common.ErrorExit('sanitizer tests only run on linux.') phases += [ ('sel_ldr_tests_asan', StepRunSelLdrTests, pepperdir, 'address'), ('sel_ldr_tests_tsan', StepRunSelLdrTests, pepperdir, 'thread'), ('sel_ldr_tests_valgrind', StepRunSelLdrTests, pepperdir, 'valgrind') ] if args: phase_names = [p[0] for p in phases] for arg in args: if arg not in phase_names: msg = 'Invalid argument: %s\n' % arg msg += 'Possible arguments:\n' for name in phase_names: msg += ' %s\n' % name parser.error(msg.strip()) for phase in phases: phase_name = phase[0] if args and phase_name not in args: continue phase_func = phase[1] phase_args = phase[2:] phase_func(*phase_args) return 0
def main(argv): epilog = 'Example: sel_ldr.py my_nexe.nexe' parser = argparse.ArgumentParser(description=__doc__, epilog=epilog) parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output') parser.add_argument('-d', '--debug', action='store_true', help='Enable debug stub') parser.add_argument('-e', '--exceptions', action='store_true', help='Enable exception handling interface') parser.add_argument('-p', '--passthrough-environment', action='store_true', help='Pass environment of host through to nexe') parser.add_argument('--debug-libs', action='store_true', help='For dynamic executables, reference debug ' 'libraries rather then release') parser.add_argument('executable', help='executable (.nexe) to run') parser.add_argument('args', nargs='*', help='argument to pass to exectuable') parser.add_argument('--library-path', help='Pass extra library paths') # To enable bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete sel_ldr.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass options = parser.parse_args(argv) if options.verbose: Log.verbose = True osname = getos.GetPlatform() if not os.path.exists(options.executable): raise Error('executable not found: %s' % options.executable) if not os.path.isfile(options.executable): raise Error('not a file: %s' % options.executable) arch, dynamic = create_nmf.ParseElfHeader(options.executable) if arch == 'arm' and osname != 'linux': raise Error('Cannot run ARM executables under sel_ldr on ' + osname) arch_suffix = arch.replace('-', '_') sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) if osname == 'win': sel_ldr += '.exe' Log('ROOT = %s' % NACL_SDK_ROOT) Log('SEL_LDR = %s' % sel_ldr) Log('IRT = %s' % irt) cmd = [sel_ldr] if osname == 'linux': # Run sel_ldr under nacl_helper_bootstrap helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix) Log('HELPER = %s' % helper) cmd.insert(0, helper) cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX') cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX') cmd += ['-a', '-B', irt] if options.debug: cmd.append('-g') if options.exceptions: cmd.append('-e') if options.passthrough_environment: cmd.append('-p') if not options.verbose: cmd += ['-l', os.devnull] if arch == 'arm': # Use the QEMU arm emulator if available. qemu_bin = FindQemu() if not qemu_bin: raise Error('Cannot run ARM executables under sel_ldr without an emulator' '. Try installing QEMU (http://wiki.qemu.org/).') arm_libpath = os.path.join(NACL_SDK_ROOT, 'tools', 'lib', 'arm_trusted') if not os.path.isdir(arm_libpath): raise Error('Could not find ARM library path: %s' % arm_libpath) qemu = [qemu_bin, '-cpu', 'cortex-a8', '-L', arm_libpath] # '-Q' disables platform qualification, allowing arm binaries to run. cmd = qemu + cmd + ['-Q'] if dynamic: if options.debug_libs: sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix, 'Debug') else: sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix, 'Release') toolchain = '%s_x86_glibc' % osname toolchain_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', toolchain) sdk_lib_dir = os.path.join(toolchain_dir, 'x86_64-nacl') if arch == 'x86-64': lib_dir = os.path.join(sdk_lib_dir, 'lib') usr_lib_dir = os.path.join(toolchain_dir, 'x86_64-nacl', 'usr', 'lib') else: lib_dir = os.path.join(sdk_lib_dir, 'lib32') usr_lib_dir = os.path.join(toolchain_dir, 'i686-nacl', 'usr', 'lib') ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so') cmd.append(ldso) Log('LD.SO = %s' % ldso) libpath = [usr_lib_dir, sdk_lib_dir, lib_dir] if options.library_path: libpath.extend([os.path.abspath(p) for p in options.library_path.split(':')]) cmd.append('--library-path') cmd.append(':'.join(libpath)) # Append arguments for the executable itself. cmd.append(options.executable) cmd += options.args Log(cmd) return subprocess.call(cmd)
def main(args): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( '-c', '--clobber', help='Clobber project directories before copying new files', action='store_true', default=False) parser.add_argument( '-b', '--build', help='Build the projects. Otherwise the projects are only copied.', action='store_true') parser.add_argument( '--config', help='Choose configuration to build (Debug or Release). Builds both ' 'by default') parser.add_argument('-x', '--experimental', help='Build experimental projects', action='store_true') parser.add_argument( '-t', '--toolchain', help='Build using toolchain. Can be passed more than once.', action='append', default=[]) parser.add_argument( '-d', '--dest', help='Select which build destinations (project types) are valid.', action='append') parser.add_argument('projects', nargs='*', help='Select which projects to build.') parser.add_argument('-v', '--verbose', action='store_true') # To setup bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete build_projects.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass options = parser.parse_args(args) global verbose if options.verbose: verbose = True buildbot_common.verbose = verbose if 'NACL_SDK_ROOT' in os.environ: # We don't want the currently configured NACL_SDK_ROOT to have any effect # on the build. del os.environ['NACL_SDK_ROOT'] pepper_ver = str(int(build_version.ChromeMajorVersion())) pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) if not options.toolchain: # Order matters here: the default toolchain for an example's Makefile will # be the first toolchain in this list that is available in the example. # e.g. If an example supports newlib and glibc, then the default will be # newlib. options.toolchain = [ 'pnacl', 'newlib', 'glibc', 'host', 'clang-newlib' ] if 'host' in options.toolchain: options.toolchain.remove('host') options.toolchain.append(getos.GetPlatform()) Trace('Adding platform: ' + getos.GetPlatform()) ValidateToolchains(options.toolchain) filters = {} if options.toolchain: filters['TOOLS'] = options.toolchain Trace('Filter by toolchain: ' + str(options.toolchain)) if not options.experimental: filters['EXPERIMENTAL'] = False if options.dest: filters['DEST'] = options.dest Trace('Filter by type: ' + str(options.dest)) if options.projects: filters['NAME'] = options.projects Trace('Filter by name: ' + str(options.projects)) try: project_tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) except parse_dsc.ValidationError as e: buildbot_common.ErrorExit(str(e)) if verbose: parse_dsc.PrintProjectTree(project_tree) UpdateHelpers(pepperdir, clobber=options.clobber) UpdateProjects(pepperdir, project_tree, options.toolchain, clobber=options.clobber) if options.build: if options.config: configs = [options.config] else: configs = ['Debug', 'Release'] for config in configs: BuildProjects(pepperdir, project_tree, config=config, deps=False) return 0
def main(args): parser = optparse.OptionParser() parser.add_option('--pnacl', help='Enable pnacl build.', action='store_true', dest='pnacl', default=False) parser.add_option('--examples', help='Only build the examples.', action='store_true', dest='only_examples', default=False) parser.add_option('--update', help='Only build the updater.', action='store_true', dest='only_updater', default=False) parser.add_option('--skip-tar', help='Skip generating a tarball.', action='store_true', dest='skip_tar', default=False) parser.add_option('--archive', help='Force the archive step.', action='store_true', dest='archive', default=False) parser.add_option('--release', help='PPAPI release version.', dest='release', default=None) options, args = parser.parse_args(args[1:]) platform = getos.GetPlatform() arch = 'x86' builder_name = os.getenv('BUILDBOT_BUILDERNAME', '') if builder_name.find('pnacl') >= 0 and builder_name.find('sdk') >= 0: options.pnacl = True if options.pnacl: toolchains = ['pnacl'] else: toolchains = ['newlib', 'glibc'] print 'Building: ' + ' '.join(toolchains) skip = options.only_examples or options.only_updater skip_examples = skip and not options.only_examples skip_update = skip and not options.only_updater skip_untar = skip skip_build = skip skip_test_updater = skip skip_tar = skip or options.skip_tar if options.archive and (options.only_examples or options.skip_tar): parser.error('Incompatible arguments with archive.') pepper_ver = str(int(build_utils.ChromeMajorVersion())) pepper_old = str(int(build_utils.ChromeMajorVersion()) - 1) clnumber = build_utils.ChromeRevision() if options.release: pepper_ver = options.release print 'Building PEPPER %s at %s' % (pepper_ver, clnumber) if not skip_build: buildbot_common.BuildStep('Rerun hooks to get toolchains') buildbot_common.Run(['gclient', 'runhooks'], cwd=SRC_DIR, shell=(platform == 'win')) buildbot_common.BuildStep('Clean Pepper Dirs') pepperdir = os.path.join(SRC_DIR, 'out', 'pepper_' + pepper_ver) pepperold = os.path.join(SRC_DIR, 'out', 'pepper_' + pepper_old) buildbot_common.RemoveDir(pepperold) if not skip_untar: buildbot_common.RemoveDir(pepperdir) buildbot_common.MakeDir(os.path.join(pepperdir, 'libraries')) buildbot_common.MakeDir(os.path.join(pepperdir, 'toolchain')) buildbot_common.MakeDir(os.path.join(pepperdir, 'tools')) else: buildbot_common.MakeDir(pepperdir) if not skip_build: buildbot_common.BuildStep('Add Text Files') files = ['AUTHORS', 'COPYING', 'LICENSE', 'NOTICE', 'README'] files = [os.path.join(SDK_SRC_DIR, filename) for filename in files] oshelpers.Copy(['-v'] + files + [pepperdir]) # Clean out the temporary toolchain untar directory if not skip_untar: UntarToolchains(pepperdir, platform, arch, toolchains) if not skip_build: BuildToolchains(pepperdir, platform, arch, pepper_ver, toolchains) InstallHeaders(os.path.join(pepperdir, 'libraries'), pepper_ver, 'libs') if not skip_build: buildbot_common.BuildStep('Copy make OS helpers') buildbot_common.CopyDir(os.path.join(SDK_SRC_DIR, 'tools', '*.py'), os.path.join(pepperdir, 'tools')) if platform == 'win': buildbot_common.BuildStep('Add MAKE') http_download.HttpDownload( GSTORE + MAKE, os.path.join(pepperdir, 'tools', 'make.exe')) rename_list = [ 'ncval_x86_32', 'ncval_x86_64', 'sel_ldr_x86_32', 'sel_ldr_x86_64' ] tools = os.path.join(pepperdir, 'tools') for name in rename_list: src = os.path.join(pepperdir, 'tools', name) dst = os.path.join(pepperdir, 'tools', name + '.exe') buildbot_common.Move(src, dst) if not skip_examples: CopyExamples(pepperdir, toolchains) tarname = 'naclsdk_' + platform + '.bz2' if 'pnacl' in toolchains: tarname = 'p' + tarname tarfile = os.path.join(OUT_DIR, tarname) if not skip_tar: buildbot_common.BuildStep('Tar Pepper Bundle') buildbot_common.Run([ sys.executable, CYGTAR, '-C', OUT_DIR, '-cjf', tarfile, 'pepper_' + pepper_ver ], cwd=NACL_DIR) # Run build tests buildbot_common.BuildStep('Run build_tools tests') buildbot_common.Run([ sys.executable, os.path.join(SDK_SRC_DIR, 'build_tools', 'tests', 'test_all.py') ]) # build sdk update if not skip_update: build_updater.BuildUpdater(OUT_DIR) # start local server sharing a manifest + the new bundle if not skip_test_updater and not skip_tar: buildbot_common.BuildStep('Move bundle to localserver dir') buildbot_common.MakeDir(SERVER_DIR) buildbot_common.Move(tarfile, SERVER_DIR) tarfile = os.path.join(SERVER_DIR, tarname) server = None try: buildbot_common.BuildStep('Run local server') server = test_server.LocalHTTPServer(SERVER_DIR) buildbot_common.BuildStep('Generate manifest') with open(tarfile, 'rb') as tarfile_stream: archive_sha1, archive_size = manifest_util.DownloadAndComputeHash( tarfile_stream) archive = manifest_util.Archive(manifest_util.GetHostOS()) archive.CopyFrom({ 'url': server.GetURL(tarname), 'size': archive_size, 'checksum': { 'sha1': archive_sha1 } }) bundle = manifest_util.Bundle('pepper_' + pepper_ver) bundle.CopyFrom({ 'revision': int(clnumber), 'repath': 'pepper_' + pepper_ver, 'version': int(pepper_ver), 'description': 'Chrome %s bundle, revision %s' % (pepper_ver, clnumber), 'stability': 'dev', 'recommended': 'no', 'archives': [archive] }) manifest = manifest_util.SDKManifest() manifest.SetBundle(bundle) manifest_name = 'naclsdk_manifest2.json' with open(os.path.join(SERVER_DIR, manifest_name), 'wb') as \ manifest_stream: manifest_stream.write(manifest.GetDataAsString()) # use newly built sdk updater to pull this bundle buildbot_common.BuildStep('Update from local server') naclsdk_sh = os.path.join(OUT_DIR, 'nacl_sdk', 'naclsdk') if platform == 'win': naclsdk_sh += '.bat' buildbot_common.Run([ naclsdk_sh, '-U', server.GetURL(manifest_name), 'update', 'pepper_' + pepper_ver ]) # If we are testing examples, do it in the newly pulled directory. pepperdir = os.path.join(OUT_DIR, 'nacl_sdk', 'pepper_' + pepper_ver) # kill server finally: if server: server.Shutdown() # build examples. if not skip_examples: buildbot_common.BuildStep('Test Build Examples') example_dir = os.path.join(pepperdir, 'examples') makefile = os.path.join(example_dir, 'Makefile') if os.path.isfile(makefile): print "\n\nMake: " + example_dir buildbot_common.Run(['make', '-j8'], cwd=os.path.abspath(example_dir), shell=True) # Archive on non-trybots. buildername = os.environ.get('BUILDBOT_BUILDERNAME', '') if options.archive or '-sdk' in buildername: buildbot_common.BuildStep('Archive build') bucket_path = 'nativeclient-mirror/nacl/nacl_sdk/%s' % \ build_utils.ChromeVersion() buildbot_common.Archive(tarname, bucket_path, os.path.dirname(tarfile)) if not skip_update: # Only push up sdk_tools.tgz on the linux buildbot. if buildername == 'linux-sdk-multi': sdk_tools = os.path.join(OUT_DIR, 'sdk_tools.tgz') buildbot_common.Archive('sdk_tools.tgz', bucket_path, OUT_DIR, step_link=False) # generate "manifest snippet" for this archive. if not skip_test_updater: archive = bundle.GetArchive(manifest_util.GetHostOS()) archive.url = 'https://commondatastorage.googleapis.com/' \ 'nativeclient-mirror/nacl/nacl_sdk/%s/%s' % ( build_utils.ChromeVersion(), tarname) manifest_snippet_file = os.path.join(OUT_DIR, tarname + '.json') with open(manifest_snippet_file, 'wb') as manifest_snippet_stream: manifest_snippet_stream.write(bundle.GetDataAsString()) buildbot_common.Archive(tarname + '.json', bucket_path, OUT_DIR, step_link=False) return 0
from build_paths import BUILD_ARCHIVE_DIR sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) import getos import oshelpers BUILD_DIR = os.path.join(NACL_DIR, 'build') NACL_TOOLCHAIN_DIR = os.path.join(NACL_DIR, 'toolchain') NACL_TOOLCHAINTARS_DIR = os.path.join(NACL_TOOLCHAIN_DIR, '.tars') CYGTAR = os.path.join(BUILD_DIR, 'cygtar.py') PKGVER = os.path.join(BUILD_DIR, 'package_version', 'package_version.py') VERSION_JSON = os.path.join(BUILD_ARCHIVE_DIR, 'version.json') PLATFORM = getos.GetPlatform() TAR = oshelpers.FindExeInPath('tar') options = None all_archives = [] # Mapping from toolchain name to the equivalent package_version.py directory # name. TOOLCHAIN_PACKAGE_MAP = { 'newlib': 'nacl_x86_newlib', 'bionic': 'nacl_arm_bionic', 'arm': 'nacl_arm_newlib', 'glibc': 'nacl_x86_glibc', 'pnacl': 'pnacl_newlib' }
def UpdateProjects(pepperdir, project_tree, toolchains, clobber=False, configs=None, first_toolchain=False): if configs is None: configs = ['Debug', 'Release'] if not os.path.exists(os.path.join(pepperdir, 'tools')): buildbot_common.ErrorExit('Examples depend on missing tools.') if not os.path.exists(os.path.join(pepperdir, 'toolchain')): buildbot_common.ErrorExit('Examples depend on missing toolchains.') ValidateToolchains(toolchains) # Create the library output directories libdir = os.path.join(pepperdir, 'lib') platform = getos.GetPlatform() for config in configs: for arch in LIB_DICT[platform]: dirpath = os.path.join(libdir, '%s_%s_host' % (platform, arch), config) if clobber: buildbot_common.RemoveDir(dirpath) buildbot_common.MakeDir(dirpath) landing_page = None for branch, projects in project_tree.iteritems(): dirpath = os.path.join(pepperdir, branch) if clobber: buildbot_common.RemoveDir(dirpath) buildbot_common.MakeDir(dirpath) targets = [desc['NAME'] for desc in projects if 'TARGETS' in desc] deps = GetDeps(projects) # Generate master make for this branch of projects generate_make.GenerateMasterMakefile(pepperdir, os.path.join(pepperdir, branch), targets, deps) if branch.startswith('examples') and not landing_page: landing_page = LandingPage() # Generate individual projects for desc in projects: srcroot = os.path.dirname(desc['FILEPATH']) generate_make.ProcessProject(pepperdir, srcroot, pepperdir, desc, toolchains, configs=configs, first_toolchain=first_toolchain) if branch.startswith('examples'): landing_page.AddDesc(desc) if landing_page: # Generate the landing page text file. index_html = os.path.join(pepperdir, 'examples', 'index.html') index_template = os.path.join(SDK_RESOURCE_DIR, 'index.html.template') with open(index_html, 'w') as fh: out = landing_page.GeneratePage(index_template) fh.write(out) # Generate top Make for examples targets = ['api', 'demo', 'getting_started', 'tutorial'] targets = [x for x in targets if 'examples/' + x in project_tree] branch_name = 'examples' generate_make.GenerateMasterMakefile(pepperdir, os.path.join(pepperdir, branch_name), targets, {})
def GetBionicToolchain(): tcdir = os.path.join(NACL_DIR, 'toolchain', '.tars') tcname = 'naclsdk_%s_arm_bionic.tgz' % getos.GetPlatform() return os.path.join(tcdir, tcname)
def GetPosixSDKPath(): sdk_path = getos.GetSDKPath() if getos.GetPlatform() == 'win': return sdk_path.replace('\\', '/') else: return sdk_path
def CanonicalizeToolchain(toolchain): if toolchain == 'host': return getos.GetPlatform() return toolchain
def main(argv): usage = 'Usage: %prog [options] <.nexe>' description = __doc__ epilog = 'Example: sel_ldr.py my_nexe.nexe' parser = optparse.OptionParser(usage, description=description, epilog=epilog) parser.add_option('-v', '--verbose', action='store_true', help='Verbose output') parser.add_option('-d', '--debug', action='store_true', help='Enable debug stub') parser.add_option('--debug-libs', action='store_true', help='For dynamic executables, reference debug ' 'libraries rather then release') options, args = parser.parse_args(argv) if not args: parser.error('No executable file specified') nexe = args[0] if options.verbose: Log.verbose = True osname = getos.GetPlatform() if not os.path.exists(nexe): raise Error('executable not found: %s' % nexe) if not os.path.isfile(nexe): raise Error('not a file: %s' % nexe) arch, dynamic = create_nmf.ParseElfHeader(nexe) if osname == 'mac' and arch == 'x86-64': raise Error('Running of x86-64 executables is not supported on mac') if arch == 'arm': raise Error('Cannot run ARM executables under sel_ldr') arch_suffix = arch.replace('-', '_') sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) if osname == 'win': sel_ldr += '.exe' Log('ROOT = %s' % NACL_SDK_ROOT) Log('SEL_LDR = %s' % sel_ldr) Log('IRT = %s' % irt) cmd = [sel_ldr, '-a', '-B', irt, '-l', os.devnull] if options.debug: cmd.append('-g') if osname == 'linux': helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix) Log('HELPER = %s' % helper) cmd.insert(0, helper) if dynamic: if options.debug_libs: libpath = os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix, 'Debug') else: libpath = os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix, 'Release') toolchain = '%s_x86_glibc' % osname sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', toolchain, 'x86_64-nacl') if arch == 'x86-64': sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib') else: sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32') ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so') cmd.append(ldso) Log('LD.SO = %s' % ldso) libpath += ':' + sdk_lib_dir cmd.append('--library-path') cmd.append(libpath) cmd += args Log(cmd) rtn = subprocess.call(cmd) return rtn
def BuildStepUntarToolchains(pepperdir, toolchains): buildbot_common.BuildStep('Untar Toolchains') platform = getos.GetPlatform() tmpdir = os.path.join(OUT_DIR, 'tc_temp') buildbot_common.RemoveDir(tmpdir) buildbot_common.MakeDir(tmpdir) if 'newlib' in toolchains: # Untar the newlib toolchains tarfile = GetNewlibToolchain() buildbot_common.Run( [sys.executable, CYGTAR, '-C', tmpdir, '-xf', tarfile], cwd=NACL_DIR) # Then rename/move it to the pepper toolchain directory srcdir = os.path.join(tmpdir, 'sdk', 'nacl-sdk') tcname = platform + '_x86_newlib' newlibdir = os.path.join(pepperdir, 'toolchain', tcname) buildbot_common.Move(srcdir, newlibdir) if 'arm' in toolchains: # Copy the existing arm toolchain from native_client tree tcname = platform + '_arm_newlib' arm_toolchain = os.path.join(NACL_DIR, 'toolchain', tcname) arm_toolchain_sdk = os.path.join(pepperdir, 'toolchain', os.path.basename(arm_toolchain)) buildbot_common.CopyDir(arm_toolchain, arm_toolchain_sdk) if 'glibc' in toolchains: # Untar the glibc toolchains tarfile = GetGlibcToolchain() tcname = platform + '_x86_glibc' buildbot_common.Run( [sys.executable, CYGTAR, '-C', tmpdir, '-xf', tarfile], cwd=NACL_DIR) # Then rename/move it to the pepper toolchain directory srcdir = os.path.join(tmpdir, 'toolchain', platform + '_x86') glibcdir = os.path.join(pepperdir, 'toolchain', tcname) buildbot_common.Move(srcdir, glibcdir) # Untar the pnacl toolchains if 'pnacl' in toolchains: tmpdir = os.path.join(tmpdir, 'pnacl') buildbot_common.RemoveDir(tmpdir) buildbot_common.MakeDir(tmpdir) tarfile = GetPNaClToolchain() tcname = platform + '_pnacl' buildbot_common.Run( [sys.executable, CYGTAR, '-C', tmpdir, '-xf', tarfile], cwd=NACL_DIR) # Then rename/move it to the pepper toolchain directory pnacldir = os.path.join(pepperdir, 'toolchain', tcname) buildbot_common.Move(tmpdir, pnacldir) PrunePNaClToolchain(pnacldir) buildbot_common.RemoveDir(tmpdir) if options.gyp and platform != 'win': # If the gyp options is specified we install a toolchain # wrapper so that gyp can switch toolchains via a commandline # option. bindir = os.path.join(pepperdir, 'toolchain', tcname, 'bin') wrapper = os.path.join(SDK_SRC_DIR, 'tools', 'compiler-wrapper.py') buildbot_common.MakeDir(bindir) buildbot_common.CopyFile(wrapper, bindir) # Module 'os' has no 'symlink' member (on Windows). # pylint: disable=E1101 os.symlink('compiler-wrapper.py', os.path.join(bindir, 'i686-nacl-g++')) os.symlink('compiler-wrapper.py', os.path.join(bindir, 'i686-nacl-gcc')) os.symlink('compiler-wrapper.py', os.path.join(bindir, 'i686-nacl-ar'))
def main(argv): parser = optparse.OptionParser() parser.add_option('--dstroot', help='Set root for destination.', dest='dstroot', default=os.path.join(OUT_DIR, 'pepper_canary')) parser.add_option('--master', help='Create master Makefile.', action='store_true', dest='master', default=False) parser.add_option('--newlib', help='Create newlib examples.', action='store_true', dest='newlib', default=False) parser.add_option('--glibc', help='Create glibc examples.', action='store_true', dest='glibc', default=False) parser.add_option('--pnacl', help='Create pnacl examples.', action='store_true', dest='pnacl', default=False) parser.add_option('--host', help='Create host examples.', action='store_true', dest='host', default=False) toolchains = [] platform = getos.GetPlatform() options, args = parser.parse_args(argv) if options.newlib: toolchains.append('newlib') if options.glibc: toolchains.append('glibc') if options.pnacl: toolchains.append('pnacl') if options.host: toolchains.append(platform) # By default support newlib and glibc if not toolchains: toolchains = ['newlib', 'glibc'] print 'Using default toolchains: ' + ' '.join(toolchains) examples = [] libs = [] for filename in args: desc = LoadProject(filename, toolchains) if not desc: print 'Skipping %s, not in [%s].' % (filename, ', '.join(toolchains)) continue srcroot = os.path.dirname(os.path.abspath(filename)) if not ProcessProject(srcroot, options.dstroot, desc, toolchains): ErrorExit('\n*** Failed to process project: %s ***' % filename) # if this is an example add it to the master make and update the html if desc['DEST'] == 'examples': examples.append(desc['NAME']) ProcessHTML(srcroot, options.dstroot, desc, toolchains) # if this is a library add it to the master make if desc['DEST'] == 'src': libs.append(desc['NAME']) if options.master: master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile') master_out = os.path.join(options.dstroot, 'examples', 'Makefile') GenerateMasterMakefile(master_in, master_out, examples) master_out = os.path.join(options.dstroot, 'src', 'Makefile') GenerateMasterMakefile(master_in, master_out, libs) return 0
def GetGlibcToolchain(): tcdir = os.path.join(NACL_DIR, 'toolchain', '.tars') tcname = 'toolchain_%s_x86.tar.bz2' % getos.GetPlatform() return os.path.join(tcdir, tcname)
def StepRunSelLdrTests(pepperdir, sanitizer): filters = { 'SEL_LDR': True } tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) def RunTest(test, toolchain, config, arch=None): args = ['STANDALONE=1', 'TOOLCHAIN=%s' % toolchain] if arch is not None: args.append('NACL_ARCH=%s' % arch) deps = False if sanitizer is not None: # For sanitizer builds we pass extra argument for make, and do # full clean build to make sure everything is rebuilt with the # correct flags deps = True if sanitizer == 'valgrind': args += ['RUN_UNDER=valgrind'] else: args += ['CC=clang', 'CXX=clang++', 'LDFLAGS=-pie -fsanitize=' + sanitizer, 'CFLAGS=-fPIC -fsanitize=' + sanitizer] build_projects.BuildProjectsBranch(pepperdir, 'src', clean=False, deps=deps, config=config, args=args + ['clean']) build_projects.BuildProjectsBranch(pepperdir, 'tests', clean=False, deps=deps, config=config, args=args + ['clean']) build_projects.BuildProjectsBranch(pepperdir, test, clean=False, deps=deps, config=config, args=args + ['run']) if getos.GetPlatform() == 'win': # On win32 we only support running on the system # arch archs = (getos.GetSystemArch('win'),) elif getos.GetPlatform() == 'mac': # We only ship 32-bit version of sel_ldr on mac. archs = ('x86_32',) else: # On linux we can run both 32 and 64-bit archs = ('x86_64', 'x86_32') for root, projects in tree.iteritems(): for project in projects: if sanitizer: sanitizer_name = '[sanitizer=%s]' % sanitizer else: sanitizer_name = '' title = 'standalone test%s: %s' % (sanitizer_name, os.path.basename(project['NAME'])) location = os.path.join(root, project['NAME']) buildbot_common.BuildStep(title) configs = ('Debug', 'Release') # On linux we can run the standalone tests natively using the host # compiler. if getos.GetPlatform() == 'linux': if sanitizer: configs = ('Debug',) for config in configs: RunTest(location, 'linux', config) if sanitizer: continue for toolchain in ('newlib', 'glibc'): for arch in archs: for config in configs: RunTest(location, toolchain, config, arch)
def GetPNaClToolchain(): tcdir = os.path.join(NACL_DIR, 'toolchain', '.tars') tcname = 'naclsdk_pnacl_%s_x86.tgz' % getos.GetPlatform() return os.path.join(tcdir, tcname)
def main(args): usage = """usage: %prog [options] -- executable args... This command creates a local server on an ephemeral port, then runs: <executable> <args..> http://localhost:<port>/<page>. Where <page> can be set by -P, or uses index.html by default.""" parser = optparse.OptionParser(usage) parser.add_option('-C', '--serve-dir', help='Serve files out of this directory.', dest='serve_dir', default=os.path.abspath('.')) parser.add_option('-P', '--path', help='Path to load from local server.', dest='path', default='index.html') parser.add_option( '-D', help='Add debug command-line when launching the chrome debug.', dest='debug', action='append', default=[]) parser.add_option( '-E', help='Add environment variables when launching the executable.', dest='environ', action='append', default=[]) parser.add_option( '--test-mode', help='Listen for posts to /ok or /fail and shut down the server with ' ' errorcodes 0 and 1 respectively.', dest='test_mode', action='store_true') parser.add_option( '-p', '--port', help='Port to run server on. Default is 5103, ephemeral is 0.', type='int', default=5103) options, args = parser.parse_args(args) if not args: parser.error('No executable given.') # 0 means use an ephemeral port. server = httpd.LocalHTTPServer(options.serve_dir, options.port, options.test_mode) print 'Serving %s on %s...' % (options.serve_dir, server.GetURL('')) env = copy.copy(os.environ) for e in options.environ: key, value = map(str.strip, e.split('=')) env[key] = value cmd = args + [server.GetURL(options.path)] print 'Running: %s...' % (' '.join(cmd), ) process = subprocess.Popen(cmd, env=env) # If any debug args are passed in, assume we want to debug if options.debug: if getos.GetPlatform() != 'win': cmd = ['xterm', '-title', 'NaCl Debugger', '-e'] else: cmd = [] cmd += options.debug print 'Starting debugger: ' + ' '.join(cmd) debug_process = subprocess.Popen(cmd, env=env) else: debug_process = False try: return server.ServeUntilSubprocessDies(process) finally: if process.returncode is None: process.kill() if debug_process and debug_process.returncode is None: debug_process.kill()
def main(args): parser = optparse.OptionParser() parser.add_option('--tar', help='Force the tar step.', action='store_true') parser.add_option('--archive', help='Force the archive step.', action='store_true') parser.add_option('--gyp', help='Use gyp to build examples/libraries/Makefiles.', action='store_true') parser.add_option('--release', help='PPAPI release version.', dest='release', default=None) parser.add_option('--build-ports', help='Build naclport bundle.', action='store_true') parser.add_option('--build-app-engine', help='Build AppEngine demos.', action='store_true') parser.add_option('--experimental', help='build experimental examples and libraries', action='store_true', dest='build_experimental') parser.add_option('--skip-toolchain', help='Skip toolchain untar', action='store_true') parser.add_option( '--mac-sdk', help='Set the mac-sdk (e.g. 10.6) to use when building with ninja.') # To setup bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete build_sdk.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass global options options, args = parser.parse_args(args[1:]) if args: parser.error("Unexpected arguments: %s" % str(args)) generate_make.use_gyp = options.gyp if buildbot_common.IsSDKBuilder(): options.archive = True options.build_ports = True options.build_app_engine = True options.tar = True toolchains = ['newlib', 'glibc', 'arm', 'pnacl', 'host'] print 'Building: ' + ' '.join(toolchains) if options.archive and not options.tar: parser.error('Incompatible arguments with archive.') chrome_version = int(build_version.ChromeMajorVersion()) chrome_revision = build_version.ChromeRevision() nacl_revision = build_version.NaClRevision() pepper_ver = str(chrome_version) pepper_old = str(chrome_version - 1) pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) pepperdir_old = os.path.join(OUT_DIR, 'pepper_' + pepper_old) tarname = 'naclsdk_' + getos.GetPlatform() + '.tar.bz2' tarfile = os.path.join(OUT_DIR, tarname) if options.release: pepper_ver = options.release print 'Building PEPPER %s at %s' % (pepper_ver, chrome_revision) if 'NACL_SDK_ROOT' in os.environ: # We don't want the currently configured NACL_SDK_ROOT to have any effect # of the build. del os.environ['NACL_SDK_ROOT'] if not options.skip_toolchain: BuildStepCleanPepperDirs(pepperdir, pepperdir_old) BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools']) BuildStepDownloadToolchains() BuildStepUntarToolchains(pepperdir, toolchains) BuildStepBuildToolchains(pepperdir, toolchains) BuildStepUpdateHelpers(pepperdir, True) BuildStepUpdateUserProjects(pepperdir, toolchains, options.build_experimental, True) BuildStepCopyTextFiles(pepperdir, pepper_ver, chrome_revision, nacl_revision) # Ship with libraries prebuilt, so run that first. BuildStepBuildLibraries(pepperdir, 'src') GenerateNotice(pepperdir) # Verify the SDK contains what we expect. BuildStepVerifyFilelist(pepperdir) if options.tar: BuildStepTarBundle(pepper_ver, tarfile) if options.build_ports and getos.GetPlatform() == 'linux': ports_tarfile = os.path.join(OUT_DIR, 'naclports.tar.bz2') BuildStepSyncNaClPorts() BuildStepBuildNaClPorts(pepper_ver, pepperdir) if options.tar: BuildStepTarNaClPorts(pepper_ver, ports_tarfile) if options.build_app_engine and getos.GetPlatform() == 'linux': BuildStepBuildAppEngine(pepperdir, chrome_revision) # Archive on non-trybots. if options.archive: BuildStepArchiveBundle('build', pepper_ver, chrome_revision, nacl_revision, tarfile) if options.build_ports and getos.GetPlatform() == 'linux': BuildStepArchiveBundle('naclports', pepper_ver, chrome_revision, nacl_revision, ports_tarfile) BuildStepArchiveSDKTools() return 0
def GetToolchainDirName(tcname): """Return the directory name for a given toolchain""" return TOOLCHAIN_PACKAGE_MAP[tcname][1] % {'platform': getos.GetPlatform()}
def main(argv): usage = 'Usage: %prog [options] <.nexe>' epilog = 'Example: sel_ldr.py my_nexe.nexe' parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog) parser.add_option('-v', '--verbose', action='store_true', help='Verbose output') parser.add_option('-d', '--debug', action='store_true', help='Enable debug stub') parser.add_option('--debug-libs', action='store_true', help='For dynamic executables, reference debug ' 'libraries rather then release') # To enable bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete sel_ldr.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass options, args = parser.parse_args(argv) if not args: parser.error('No executable file specified') nexe = args[0] if options.verbose: Log.verbose = True osname = getos.GetPlatform() if not os.path.exists(nexe): raise Error('executable not found: %s' % nexe) if not os.path.isfile(nexe): raise Error('not a file: %s' % nexe) arch, dynamic = create_nmf.ParseElfHeader(nexe) if arch == 'arm': raise Error('Cannot run ARM executables under sel_ldr') arch_suffix = arch.replace('-', '_') sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) if osname == 'win': sel_ldr += '.exe' Log('ROOT = %s' % NACL_SDK_ROOT) Log('SEL_LDR = %s' % sel_ldr) Log('IRT = %s' % irt) cmd = [sel_ldr] if osname == 'linux': # Run sel_ldr under nacl_helper_bootstrap helper = os.path.join(SCRIPT_DIR, 'nacl_helper_bootstrap_%s' % arch_suffix) Log('HELPER = %s' % helper) cmd.insert(0, helper) cmd.append('--r_debug=0xXXXXXXXXXXXXXXXX') cmd.append('--reserved_at_zero=0xXXXXXXXXXXXXXXXX') cmd += ['-a', '-B', irt] if options.debug: cmd.append('-g') if not options.verbose: cmd += ['-l', os.devnull] if dynamic: if options.debug_libs: libpath = os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix, 'Debug') else: libpath = os.path.join(NACL_SDK_ROOT, 'lib', 'glibc_%s' % arch_suffix, 'Release') toolchain = '%s_x86_glibc' % osname sdk_lib_dir = os.path.join(NACL_SDK_ROOT, 'toolchain', toolchain, 'x86_64-nacl') if arch == 'x86-64': sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib') else: sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32') ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so') cmd.append(ldso) Log('LD.SO = %s' % ldso) libpath += ':' + sdk_lib_dir cmd.append('--library-path') cmd.append(libpath) if args: # Append arguments for the executable itself. cmd += args Log(cmd) rtn = subprocess.call(cmd) return rtn
#!/usr/bin/env python # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import StringIO import sys import os import optparse SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(os.path.dirname(SCRIPT_DIR), 'tools')) import getos valid_tools = ['newlib', 'glibc', getos.GetPlatform()] def Error(msg): print(msg) sys.exit(1) PREAMBLE = """\ { 'includes': ['%s/build_tools/nacl.gypi'], """ NEXE_TARGET = """\ { 'target_name': '%(NAME)s_x86_32%(EXT)s', 'product_name': '%(NAME)s_x86_32%(EXT)s',
def main(args): parser = optparse.OptionParser() parser.add_option('-c', '--channel', help='Channel to display in the name of the package.') # To setup bash completion for this command first install optcomplete # and then add this line to your .bashrc: # complete -F _optcomplete build_app.py try: import optcomplete optcomplete.autocomplete(parser) except ImportError: pass options, args = parser.parse_args(args[1:]) if options.channel: if options.channel not in ('Dev', 'Beta'): parser.error('Unknown channel: %s' % options.channel) toolchains = ['newlib', 'glibc'] pepper_ver = str(int(build_version.ChromeMajorVersion())) pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) app_dir = os.path.join(OUT_DIR, 'naclsdk_app') app_examples_dir = os.path.join(app_dir, 'examples') sdk_resources_dir = SDK_RESOURCE_DIR platform = getos.GetPlatform() buildbot_common.RemoveDir(app_dir) buildbot_common.MakeDir(app_dir) # Add some dummy directories so build_projects doesn't complain... buildbot_common.MakeDir(os.path.join(app_dir, 'tools')) buildbot_common.MakeDir(os.path.join(app_dir, 'toolchain')) config = 'Release' filters = {} filters['DISABLE_PACKAGE'] = False filters['EXPERIMENTAL'] = False filters['TOOLS'] = toolchains filters['DEST'] = [ 'examples/api', 'examples/getting_started', 'examples/demo', 'examples/tutorial' ] tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) build_projects.UpdateHelpers(app_dir, clobber=True) build_projects.UpdateProjects(app_dir, tree, clobber=False, toolchains=toolchains, configs=[config], first_toolchain=True) # Collect permissions from each example, and aggregate them. def MergeLists(list1, list2): return list1 + [x for x in list2 if x not in list1] all_permissions = [] all_socket_permissions = [] for _, project in parse_dsc.GenerateProjects(tree): permissions = project.get('PERMISSIONS', []) all_permissions = MergeLists(all_permissions, permissions) socket_permissions = project.get('SOCKET_PERMISSIONS', []) all_socket_permissions = MergeLists(all_socket_permissions, socket_permissions) if all_socket_permissions: all_permissions.append({'socket': all_socket_permissions}) pretty_permissions = json.dumps(all_permissions, sort_keys=True, indent=4) for filename in ['background.js', 'icon128.png']: buildbot_common.CopyFile(os.path.join(sdk_resources_dir, filename), os.path.join(app_examples_dir, filename)) os.environ['NACL_SDK_ROOT'] = pepperdir build_projects.BuildProjects(app_dir, tree, deps=False, clean=False, config=config) RemoveBuildCruft(app_dir) StripNexes(app_dir, platform, pepperdir) # Add manifest.json after RemoveBuildCruft... that function removes the # manifest.json files for the individual examples. name = 'Native Client SDK' if options.channel: name += ' (%s)' % options.channel template_dict = { 'name': name, 'channel': options.channel, 'description': 'Native Client SDK examples, showing API use and key concepts.', 'key': False, # manifests with "key" are rejected when uploading to CWS. 'permissions': pretty_permissions, 'version': build_version.ChromeVersionNoTrunk() } easy_template.RunTemplateFile( os.path.join(sdk_resources_dir, 'manifest.json.template'), os.path.join(app_examples_dir, 'manifest.json'), template_dict) app_zip = os.path.join(app_dir, 'examples.zip') os.chdir(app_examples_dir) oshelpers.Zip([app_zip, '-r', '*']) return 0
def ProcessDSC(filename, outfile=None): if not os.path.exists(filename): Error("file not found: %s" % filename) desc = open(filename).read() desc = eval(desc, {}, {}) if not desc.get('TARGETS'): Error("no TARGETS found in dsc") if not outfile: outfile = desc['NAME'] + '.gyp' outfile = os.path.join(os.path.dirname(filename), outfile) output = StringIO.StringIO() srcdir = os.path.dirname(SCRIPT_DIR) output.write(PREAMBLE % srcdir.replace("\\", '/')) win32 = sys.platform in ('win32', 'cygwin') if win32: output.write(WIN32_CONFIGS) else: for tc in desc['TOOLS']: if tc in valid_tools: default = '%s-debug' % ConfigName(tc) break output.write("""\ 'target_defaults': { 'default_configuration': '%s', 'configurations' : {\n""" % default) for tc in desc['TOOLS']: if tc not in valid_tools: continue output.write(TOOLCHAIN_CONFIG % {'toolchain': ConfigName(tc)}) output.write(" }\n },\n") output.write("\n 'targets': [\n") # make a list of all the so target names so that the nmf rules # can depend on them all sofiles = [] soremap = [] for target in desc['TARGETS']: if target['TYPE'] == 'so': name = target['NAME'] sofiles.append('<(PRODUCT_DIR)/%s_x86_64.so' % name) sofiles.append('<(PRODUCT_DIR)/%s_x86_32.so' % name) soremap += ['-n', '%s_x86_64.so,%s.so' % (name, name)] soremap += ['-n', '%s_x86_32.so,%s.so' % (name, name)] # iterate through dsc targets generating gyp targets for target in desc['TARGETS']: target.setdefault('INCLUDES', []) target['INCLUDES'] = [ x.replace("$(NACL_SDK_ROOT)", "../..") for x in target['INCLUDES'] ] libs = target.get('LIBS', []) if win32: libs = [l for l in libs if l not in ('ppapi', 'ppapi_cpp')] target['LIBS'] = ['-l' + l + '.lib' for l in libs] else: target['LIBS'] = ['-l' + l for l in libs] if target['TYPE'] == 'so': if win32: target['EXT'] = '' else: target['EXT'] = '.so' target['GYP_TYPE'] = 'shared_library' elif target['TYPE'] == 'lib': if win32: target['EXT'] = '' else: target['EXT'] = '.a' target['GYP_TYPE'] = 'static_library' elif target['TYPE'] == 'main': target['EXT'] = '.nexe' target['GYP_TYPE'] = 'executable' else: Error("unknown type: %s" % target['TYPE']) target['CFLAGS'] = target.get('CXXFLAGS', []) if not win32 and ('newlib' in desc['TOOLS'] or 'glibc' in desc['TOOLS']): WriteNaClTargets(output, target, desc['TOOLS']) if target['TYPE'] == 'main': target['SODEPS'] = sofiles target['NMFACTION'] = [ '-o', '<@(_outputs)', '-L<(NMF_PATH1)', '-L<(NMF_PATH2)', '-D', '<(OBJDUMP)', '<@(_inputs)' ] target['NMFACTION'] += soremap if 'newlib' in desc['TOOLS']: target['TOOLCHAIN'] = 'newlib' output.write(NMF_TARGET % target) if 'glibc' in desc['TOOLS']: target['TOOLCHAIN'] = 'glibc' output.write(NMF_TARGET % target) if win32 or getos.GetPlatform() in desc['TOOLS']: target['ARCH'] = 'x86_32' target['INCLUDES'].append('../../include') if win32: target['HOST'] = 'win' target['CONFIGS'] = '' target['CFLAGS'] = [] else: target['CONFIGS'] = '' target['HOST'] = 'linux' target['CFLAGS'].append('-fPIC') if target['TYPE'] == 'main': target['GYP_TYPE'] = 'shared_library' if win32: target['EXT'] = '' else: target['EXT'] = '.so' output.write(HOST_EXE_TARGET % target) else: output.write(HOST_LIB_TARGET % target) output.write(' ],\n}\n') print('Writing: ' + outfile) open(outfile, 'w').write(output.getvalue())
def main(args): parser = optparse.OptionParser() parser.add_option('--run-tests', help='Run tests. This includes building examples.', action='store_true') parser.add_option('--run-pyauto-tests', help='Run the pyauto tests for examples.', action='store_true') parser.add_option('--skip-tar', help='Skip generating a tarball.', action='store_true') parser.add_option('--archive', help='Force the archive step.', action='store_true') parser.add_option('--gyp', help='Use gyp to build examples/libraries/Makefiles.', action='store_true') parser.add_option('--release', help='PPAPI release version.', dest='release', default=None) parser.add_option('--experimental', help='build experimental examples and libraries', action='store_true', dest='build_experimental') parser.add_option('--skip-toolchain', help='Skip toolchain untar', action='store_true') parser.add_option( '--mac_sdk', help='Set the mac_sdk (e.g. 10.6) to use when building with ninja.', dest='mac_sdk') global options options, args = parser.parse_args(args[1:]) platform = getos.GetPlatform() arch = 'x86' generate_make.use_gyp = options.gyp # TODO(binji) for now, only test examples on non-trybots. Trybots don't build # pyauto Chrome. if buildbot_common.IsSDKBuilder(): options.run_tests = True options.run_pyauto_tests = True options.archive = True if buildbot_common.IsSDKTrybot(): options.run_tests = True toolchains = ['newlib', 'glibc', 'arm', 'pnacl', 'host'] print 'Building: ' + ' '.join(toolchains) if options.archive and options.skip_tar: parser.error('Incompatible arguments with archive.') pepper_ver = str(int(build_utils.ChromeMajorVersion())) pepper_old = str(int(build_utils.ChromeMajorVersion()) - 1) pepperdir = os.path.join(SRC_DIR, 'out', 'pepper_' + pepper_ver) pepperdir_old = os.path.join(SRC_DIR, 'out', 'pepper_' + pepper_old) clnumber = build_utils.ChromeRevision() tarname = 'naclsdk_' + platform + '.tar.bz2' tarfile = os.path.join(OUT_DIR, tarname) if options.release: pepper_ver = options.release print 'Building PEPPER %s at %s' % (pepper_ver, clnumber) if 'NACL_SDK_ROOT' in os.environ: # We don't want the currently configured NACL_SDK_ROOT to have any effect # of the build. del os.environ['NACL_SDK_ROOT'] BuildStepCleanPepperDirs(pepperdir, pepperdir_old) BuildStepMakePepperDirs(pepperdir, ['include', 'toolchain', 'tools']) if not options.skip_toolchain: BuildStepDownloadToolchains(platform) BuildStepUntarToolchains(pepperdir, platform, arch, toolchains) BuildStepCopyTextFiles(pepperdir, pepper_ver, clnumber) BuildStepBuildToolchains(pepperdir, platform, pepper_ver, toolchains) InstallHeaders(os.path.join(pepperdir, 'include'), None, 'libs') BuildStepCopyBuildHelpers(pepperdir, platform) BuildStepCopyExamples(pepperdir, toolchains, options.build_experimental, True) # Ship with libraries prebuilt, so run that first. BuildStepBuildLibraries(pepperdir, platform, 'src') BuildStepGenerateNotice(pepperdir) if not options.skip_tar: BuildStepTarBundle(pepper_ver, tarfile) if options.run_tests: BuildStepRunTests() # Archive on non-trybots. if options.archive: BuildStepArchiveBundle(pepper_ver, clnumber, tarfile) BuildStepArchiveSDKTools() return 0
def testGetLoaderPath(self): """checks that loader exists.""" platform = getos.GetPlatform() with mock.patch('os.path.exists') as mock_exists: loader = getos.GetLoaderPath(platform) mock_exists.assert_called_with(loader)
def testGetSystemArch(self): """returns a valid architecture.""" arch = getos.GetSystemArch(getos.GetPlatform()) self.assertIn(arch, ('x86_64', 'x86_32', 'arm'))