summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authorsbc <sbc@chromium.org>2015-01-30 11:11:26 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-30 19:13:57 +0000
commit088561ac99314a79866a39f79bb32bd5e1196217 (patch)
tree49b69e8487346cdd5393ed30b996b04c2b8a3d72 /native_client_sdk
parentde870139c90af7fc5957d42c8c2b0fbb09f95591 (diff)
downloadchromium_src-088561ac99314a79866a39f79bb32bd5e1196217.zip
chromium_src-088561ac99314a79866a39f79bb32bd5e1196217.tar.gz
chromium_src-088561ac99314a79866a39f79bb32bd5e1196217.tar.bz2
[NaCl SDK] Remove create_nmf dependency on NACL_SDK_ROOT env var
create_nmf should determine the root of the SDK relative to its own location. The exception to this is when its run as part of the chrome build, when it is not yet installed. In this case we pass --no-default-libpath and --objdump to create_nmf to remove any use of the SDK root. Review URL: https://codereview.chromium.org/737653003 Cr-Commit-Position: refs/heads/master@{#313957}
Diffstat (limited to 'native_client_sdk')
-rwxr-xr-xnative_client_sdk/src/tools/create_nmf.py33
-rwxr-xr-xnative_client_sdk/src/tools/tests/create_nmf_test.py26
2 files changed, 24 insertions, 35 deletions
diff --git a/native_client_sdk/src/tools/create_nmf.py b/native_client_sdk/src/tools/create_nmf.py
index de72408..dc7e552 100755
--- a/native_client_sdk/src/tools/create_nmf.py
+++ b/native_client_sdk/src/tools/create_nmf.py
@@ -466,15 +466,16 @@ def ParseExtraFiles(encoded_list, err):
def GetSDKRoot():
- """Determine current NACL_SDK_ROOT, either via the environment variable
- itself, or by attempting to derive it from the location of this script.
+ """Returns the root directory of the NaCl SDK.
"""
- sdk_root = os.environ.get('NACL_SDK_ROOT')
- if not sdk_root:
- sdk_root = os.path.dirname(SCRIPT_DIR)
- if not os.path.exists(os.path.join(sdk_root, 'toolchain')):
- return None
-
+ # This script should be installed in NACL_SDK_ROOT/tools. Assert that
+ # the 'toolchain' folder exists within this directory in case, for
+ # example, this script is moved to a different location.
+ # During the Chrome build this script is sometimes run outside of
+ # of an SDK but in these cases it should always be run with --objdump=
+ # and --no-default-libpath which avoids the need to call this function.
+ sdk_root = os.path.dirname(SCRIPT_DIR)
+ assert(os.path.exists(os.path.join(sdk_root, 'toolchain')))
return sdk_root
@@ -482,12 +483,8 @@ def FindObjdumpExecutable():
"""Derive path to objdump executable to use for determining shared
object dependencies.
"""
- sdk_root = GetSDKRoot()
- if not sdk_root:
- return None
-
osname = getos.GetPlatform()
- toolchain = os.path.join(sdk_root, 'toolchain', '%s_x86_glibc' % osname)
+ toolchain = os.path.join(GetSDKRoot(), 'toolchain', '%s_x86_glibc' % osname)
objdump = os.path.join(toolchain, 'bin', 'x86_64-nacl-objdump')
if osname == 'win':
objdump += '.exe'
@@ -508,10 +505,6 @@ def GetDefaultLibPath(config):
"""
assert(config in ('Debug', 'Release'))
sdk_root = GetSDKRoot()
- if not sdk_root:
- # TOOD(sbc): output a warning here? We would also need to suppress
- # the warning when run from the chromium build.
- return []
osname = getos.GetPlatform()
libpath = [
@@ -580,8 +573,8 @@ def main(args):
help='Rename FOO as BAR',
action='append', default=[], metavar='FOO,BAR')
parser.add_argument('-x', '--extra-files',
- help=('Add extra key:file tuple to the "files"' +
- ' section of the .nmf'),
+ help='Add extra key:file tuple to the "files"'
+ ' section of the .nmf',
action='append', default=[], metavar='FILE')
parser.add_argument('-O', '--pnacl-optlevel',
help='Set the optimization level to N in PNaCl manifests',
@@ -669,7 +662,7 @@ def main(args):
pnacl_debug_optlevel=pnacl_debug_optlevel,
nmf_root=nmf_root)
- if not options.output:
+ if options.output is None:
sys.stdout.write(nmf.GetJson())
else:
with open(options.output, 'w') as output:
diff --git a/native_client_sdk/src/tools/tests/create_nmf_test.py b/native_client_sdk/src/tools/tests/create_nmf_test.py
index 86a89a2..d71bee9 100755
--- a/native_client_sdk/src/tools/tests/create_nmf_test.py
+++ b/native_client_sdk/src/tools/tests/create_nmf_test.py
@@ -14,17 +14,19 @@ import unittest
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
DATA_DIR = os.path.join(TOOLS_DIR, 'lib', 'tests', 'data')
+BUILD_TOOLS_DIR = os.path.join(os.path.dirname(TOOLS_DIR), 'build_tools')
CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
# For the mock library
sys.path.append(MOCK_DIR)
sys.path.append(TOOLS_DIR)
+sys.path.append(BUILD_TOOLS_DIR)
import build_paths
import create_nmf
import getos
-import mock
+from mock import patch, Mock
TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain')
NACL_X86_GLIBC_TOOLCHAIN = os.path.join(TOOLCHAIN_OUT,
@@ -61,24 +63,18 @@ class TestPosixRelPath(unittest.TestCase):
class TestDefaultLibpath(unittest.TestCase):
- def testWithoutNaClSDKRoot(self):
- """GetDefaultLibPath wihtout NACL_SDK_ROOT set
-
- In the absence of NACL_SDK_ROOT GetDefaultLibPath should
- return the empty list."""
- with mock.patch.dict('os.environ', clear=True):
- paths = create_nmf.GetDefaultLibPath('Debug')
- self.assertEqual(paths, [])
-
- def testHonorNaClSDKRoot(self):
- with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}):
- paths = create_nmf.GetDefaultLibPath('Debug')
+ def setUp(self):
+ patcher = patch('create_nmf.GetSDKRoot', Mock(return_value='/dummy/path'))
+ patcher.start()
+ self.addCleanup(patcher.stop)
+
+ def testUsesSDKRoot(self):
+ paths = create_nmf.GetDefaultLibPath('Debug')
for path in paths:
self.assertTrue(path.startswith('/dummy/path'))
def testIncludesNaClPorts(self):
- with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}):
- paths = create_nmf.GetDefaultLibPath('Debug')
+ paths = create_nmf.GetDefaultLibPath('Debug')
self.assertTrue(any(os.path.join('ports', 'lib') in p for p in paths),
"naclports libpath missing: %s" % str(paths))