summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-20 23:27:30 +0000
committerbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-20 23:27:30 +0000
commita033a2b45abf2e005ef283430ad70ce038fefe11 (patch)
tree144cd0ad347879a0d9526cbbaea2c77a94d7226c
parent0620d3cb94804865248599f0103ae8c5cc006964 (diff)
downloadchromium_src-a033a2b45abf2e005ef283430ad70ce038fefe11.zip
chromium_src-a033a2b45abf2e005ef283430ad70ce038fefe11.tar.gz
chromium_src-a033a2b45abf2e005ef283430ad70ce038fefe11.tar.bz2
[NaCl SDK] Run ncval on executables as part of build.
Currently this doesn't do anything nice like ncval_annotate, but it is a step in the right direction. BUG=116194 R=sbc@chromium.org Review URL: https://codereview.chromium.org/78713005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236339 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--native_client_sdk/src/build_tools/sdk_files.list1
-rw-r--r--native_client_sdk/src/tools/nacl_gcc.mk7
-rwxr-xr-xnative_client_sdk/src/tools/ncval.py94
3 files changed, 102 insertions, 0 deletions
diff --git a/native_client_sdk/src/build_tools/sdk_files.list b/native_client_sdk/src/build_tools/sdk_files.list
index f585170..a7a7557 100644
--- a/native_client_sdk/src/build_tools/sdk_files.list
+++ b/native_client_sdk/src/build_tools/sdk_files.list
@@ -427,6 +427,7 @@ tools/nacl_gcc.mk
[linux]tools/nacl_helper_bootstrap_x86_64
tools/nacl_llvm.mk
tools/ncval${EXE_EXT}
+tools/ncval.py
tools/oshelpers.py
tools/quote.py
tools/run.py
diff --git a/native_client_sdk/src/tools/nacl_gcc.mk b/native_client_sdk/src/tools/nacl_gcc.mk
index 2727447..e41885f 100644
--- a/native_client_sdk/src/tools/nacl_gcc.mk
+++ b/native_client_sdk/src/tools/nacl_gcc.mk
@@ -46,6 +46,8 @@ ARM_LIB ?= $(ARM_TC_BIN)/arm-nacl-ar
ARM_STRIP ?= $(ARM_TC_BIN)/arm-nacl-strip
ARM_NM ?= $(ARM_TC_BIN)/arm-nacl-nm
+NCVAL ?= python $(NACL_SDK_ROOT)/tools/ncval.py
+
# Architecture-specific flags
X86_32_CFLAGS ?=
X86_64_CFLAGS ?=
@@ -183,6 +185,7 @@ ifneq (,$(findstring x86_32,$(ARCHES)))
all: $(OUTDIR)/lib$(1)_x86_32.so
$(OUTDIR)/lib$(1)_x86_32.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32_pic)) $(4)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter-out $(4),$$^) -shared -m32 $(LD_X86_32) $$(LD_FLAGS) $(foreach lib,$(3),-l$(lib)))
+ $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
@@ -199,6 +202,7 @@ ifneq (,$(findstring x86_64,$(ARCHES)))
all: $(OUTDIR)/lib$(1)_x86_64.so
$(OUTDIR)/lib$(1)_x86_64.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64_pic)) $(4)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter-out $(4),$$^) -shared -m64 $(LD_X86_64) $$(LD_FLAGS) $(foreach lib,$(3),-l$(lib)))
+ $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
@@ -287,18 +291,21 @@ ifneq (,$(findstring x86_32,$(ARCHES)))
all: $(OUTDIR)/$(1)_x86_32.nexe
$(OUTDIR)/$(1)_x86_32.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
$(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
+ $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
endif
ifneq (,$(findstring x86_64,$(ARCHES)))
all: $(OUTDIR)/$(1)_x86_64.nexe
$(OUTDIR)/$(1)_x86_64.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
$(call LOG,LINK,$$@,$(X86_64_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
+ $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
endif
ifneq (,$(findstring arm,$(ARCHES)))
all: $(OUTDIR)/$(1)_arm.nexe
$(OUTDIR)/$(1)_arm.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
$(call LOG,LINK,$$@,$(ARM_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(ARM_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_arm/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
+ $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
endif
endef
diff --git a/native_client_sdk/src/tools/ncval.py b/native_client_sdk/src/tools/ncval.py
new file mode 100755
index 0000000..2066487
--- /dev/null
+++ b/native_client_sdk/src/tools/ncval.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+# Copyright 2013 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.
+
+"""Wrapper script for running ncval.
+"""
+
+import optparse
+import os
+import subprocess
+import sys
+
+import getos
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR)
+
+if sys.version_info < (2, 6, 0):
+ sys.stderr.write("python 2.6 or later is required run this script\n")
+ sys.exit(1)
+
+class Error(Exception):
+ pass
+
+def Log(msg):
+ if Log.verbose:
+ sys.stderr.write(str(msg) + '\n')
+Log.verbose = False
+
+def main(argv):
+ usage = 'Usage: %prog [options] <.nexe | .so>'
+ epilog = 'Example: ncval.py my_nexe.nexe'
+ parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog)
+ parser.add_option('-v', '--verbose', action='store_true',
+ help='Verbose output')
+
+ # To enable bash completion for this command first install optcomplete
+ # and then add this line to your .bashrc:
+ # complete -F _optcomplete ncval.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
+
+ # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the
+ # amount of additional checking done here.
+ 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)
+
+ ncval = os.path.join(SCRIPT_DIR, 'ncval')
+ if osname == 'win':
+ ncval += '.exe'
+
+ cmd = [ncval, nexe]
+ Log('Running %s' % ' '.join(cmd))
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ proc_out, _ = proc.communicate()
+ if proc.returncode:
+ # ncval doesn't print anything to stderr.
+ sys.stderr.write('Validating %s failed:\n' % nexe)
+ sys.stderr.write(proc_out + '\n')
+
+ Log('Changing the modification time of %s to 0.' % nexe)
+ # "untouch" the executable; that is, change the modification time to be so
+ # old that it will be remade when `make` runs.
+ statinfo = os.stat(nexe)
+ mtime = 0
+ os.utime(nexe, (statinfo.st_atime, mtime))
+
+ return proc.returncode
+ elif options.verbose:
+ # By default, don't print anything on success.
+ Log(proc_out)
+
+
+if __name__ == '__main__':
+ try:
+ sys.exit(main(sys.argv[1:]))
+ except Error as e:
+ sys.stderr.write(str(e) + '\n')
+ sys.exit(1)