diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-11 18:53:43 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-11 18:53:43 +0000 |
commit | 1b68872730c5100b17ec2c0c45b633b90590b277 (patch) | |
tree | f111f2fee5e27e3e8eccfd4566fc61fa31ede884 /native_client_sdk | |
parent | 24bba3a084b054d9b527c5c354caeabf4492fcaa (diff) | |
download | chromium_src-1b68872730c5100b17ec2c0c45b633b90590b277.zip chromium_src-1b68872730c5100b17ec2c0c45b633b90590b277.tar.gz chromium_src-1b68872730c5100b17ec2c0c45b633b90590b277.tar.bz2 |
[NaCl SDK] Print nice error if host build can't find gcc or cl.exe
Previously, the build would fail with when at compile time.
BUG=none
R=noelallen@chromium.org
NOTRY=true
Review URL: https://codereview.chromium.org/12220085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r-- | native_client_sdk/src/tools/common.mk | 8 | ||||
-rw-r--r-- | native_client_sdk/src/tools/host_gcc.mk | 6 | ||||
-rw-r--r-- | native_client_sdk/src/tools/host_vc.mk | 6 | ||||
-rwxr-xr-x | native_client_sdk/src/tools/oshelpers.py | 38 | ||||
-rwxr-xr-x | native_client_sdk/src/tools/tests/oshelpers_test.py | 104 |
5 files changed, 143 insertions, 19 deletions
diff --git a/native_client_sdk/src/tools/common.mk b/native_client_sdk/src/tools/common.mk index 82651a9..25a6e08 100644 --- a/native_client_sdk/src/tools/common.mk +++ b/native_client_sdk/src/tools/common.mk @@ -69,6 +69,7 @@ CP:=python $(NACL_SDK_ROOT)/tools/oshelpers.py cp MKDIR:=python $(NACL_SDK_ROOT)/tools/oshelpers.py mkdir MV:=python $(NACL_SDK_ROOT)/tools/oshelpers.py mv RM:=python $(NACL_SDK_ROOT)/tools/oshelpers.py rm +WHICH:=python $(NACL_SDK_ROOT)/tools/oshelpers.py which # @@ -107,7 +108,14 @@ endef # The target for all versions # USABLE_TOOLCHAINS=$(filter $(OSNAME) newlib glibc pnacl,$(VALID_TOOLCHAINS)) + +ifeq (1,$(NO_HOST_BUILDS)) +USABLE_TOOLCHAINS:=$(filter-out $(OSNAME),$(USABLE_TOOLCHAINS)) +endif + $(foreach tool,$(USABLE_TOOLCHAINS),$(eval $(call TOOLCHAIN_RULE,$(tool),$(dep)))) + +.PHONY: all_versions all_versions: $(TOOLCHAIN_LIST) # diff --git a/native_client_sdk/src/tools/host_gcc.mk b/native_client_sdk/src/tools/host_gcc.mk index b2e6a82..05967e8 100644 --- a/native_client_sdk/src/tools/host_gcc.mk +++ b/native_client_sdk/src/tools/host_gcc.mk @@ -20,6 +20,12 @@ HOST_CXX?=g++ HOST_LINK?=g++ HOST_LIB?=ar r +ifeq (,$(findstring gcc,$(shell $(WHICH) gcc))) +$(warning To skip the host build use:) +$(warning "make all_versions NO_HOST_BUILDS=1") +$(error Unable to find gcc in PATH while building Host build) +endif + LINUX_WARNINGS?=-Wno-long-long LINUX_CCFLAGS=-fPIC -pthread $(LINUX_WARNINGS) -I$(NACL_SDK_ROOT)/include -I$(NACL_SDK_ROOT)/include/linux diff --git a/native_client_sdk/src/tools/host_vc.mk b/native_client_sdk/src/tools/host_vc.mk index 2ed32d3..be2d7d2 100644 --- a/native_client_sdk/src/tools/host_vc.mk +++ b/native_client_sdk/src/tools/host_vc.mk @@ -20,6 +20,12 @@ HOST_CXX?=cl.exe /nologo /EHsc HOST_LINK?=link.exe /nologo HOST_LIB?=lib.exe /nologo +ifeq (,$(findstring cl.exe,$(shell $(WHICH) cl.exe))) +$(warning To skip the host build use:) +$(warning "make NO_HOST_BUILDS=1") +$(error Unable to find cl.exe in PATH while building Windows host build) +endif + ifeq ('Debug','$(CONFIG)') WIN_OPT_FLAGS?=/Od /MTd /Z7 diff --git a/native_client_sdk/src/tools/oshelpers.py b/native_client_sdk/src/tools/oshelpers.py index e9655a2..70a1368 100755 --- a/native_client_sdk/src/tools/oshelpers.py +++ b/native_client_sdk/src/tools/oshelpers.py @@ -469,12 +469,50 @@ def Zip(args): return 0 +def Which(args): + """A Unix style which. + + Looks for all arguments in the PATH environment variable, and prints their + path if they are executable files. + + Note: If you pass an argument with a path to which, it will just test if it + is executable, not if it is in the path. + """ + parser = optparse.OptionParser(usage='usage: which args...') + _, files = parser.parse_args(args) + if not files: + return 0 + + env_path = os.environ.get('PATH', '') + paths = env_path.split(os.pathsep) + + def IsExecutableFile(path): + return os.path.isfile(path) and os.access(path, os.X_OK) + + retval = 0 + for filename in files: + if os.path.sep in filename: + if IsExecutableFile(filename): + print filename + continue + + for path in paths: + filepath = os.path.join(path, filename) + if IsExecutableFile(filepath): + print os.path.abspath(os.path.join(path, filename)) + break + else: + retval = 1 + return retval + + FuncMap = { 'cp': Copy, 'mkdir': Mkdir, 'mv': Move, 'rm': Remove, 'zip': Zip, + 'which': Which, } diff --git a/native_client_sdk/src/tools/tests/oshelpers_test.py b/native_client_sdk/src/tools/tests/oshelpers_test.py index e73f978..cb826c8 100755 --- a/native_client_sdk/src/tools/tests/oshelpers_test.py +++ b/native_client_sdk/src/tools/tests/oshelpers_test.py @@ -18,7 +18,7 @@ sys.path.append(PARENT_DIR) import oshelpers -class RunZipError(subprocess.CalledProcessError): +class RunError(subprocess.CalledProcessError): def __init__(self, retcode, command, output, error_output): subprocess.CalledProcessError.__init__(self, retcode, command) self.output = output @@ -31,17 +31,19 @@ class RunZipError(subprocess.CalledProcessError): return msg -def RunZip(args, cwd): - command = [sys.executable, 'oshelpers.py', 'zip'] + args +def RunCmd(cmd, args, cwd, env=None): + env = env or os.environ + command = [sys.executable, 'oshelpers.py', cmd] + args process = subprocess.Popen(stdout=subprocess.PIPE, stderr=subprocess.PIPE, args=command, - cwd=cwd) + cwd=cwd, + env=env) output, error_output = process.communicate() retcode = process.returncode if retcode: - raise RunZipError(retcode, command, output, error_output) + raise RunError(retcode, command, output, error_output) return output, error_output @@ -68,7 +70,7 @@ class TestZip(unittest.TestCase): return rel_path def RunZip(self, *args): - return RunZip(*args, cwd=self.tempdir) + return RunCmd('zip', list(args), cwd=self.tempdir) def OpenZipFile(self): self.zipfile = zipfile.ZipFile(self.GetTempPath(self.zipname), 'r') @@ -83,13 +85,13 @@ class TestZip(unittest.TestCase): def testNothingToDo(self): self.assertRaises(subprocess.CalledProcessError, self.RunZip, - [self.zipname, 'nonexistent_file']) + self.zipname, 'nonexistent_file') self.assertFalse(os.path.exists(self.zipname)) def testAddSomeFiles(self): file1 = self.MakeFile('file1', 1024) file2 = self.MakeFile('file2', 3354) - self.RunZip([self.zipname, file1, file2]) + self.RunZip(self.zipname, file1, file2) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 2) self.assertEqual(self.GetZipInfo(file1).file_size, 1024) @@ -100,13 +102,13 @@ class TestZip(unittest.TestCase): def testAddFilesWithGlob(self): self.MakeFile('file1', 1024) self.MakeFile('file2', 3354) - self.RunZip([self.zipname, 'file*']) + self.RunZip(self.zipname, 'file*') self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 2) def testAddDir(self): os.mkdir(self.GetTempPath('dir1')) - self.RunZip([self.zipname, 'dir1']) + self.RunZip(self.zipname, 'dir1') self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 1) self.assertRaises(KeyError, self.zipfile.getinfo, 'dir1') @@ -117,18 +119,18 @@ class TestZip(unittest.TestCase): self.MakeFile(os.path.join('dir1', 'file1'), 256) os.mkdir(self.GetTempPath(os.path.join('dir1', 'dir2'))) self.MakeFile(os.path.join('dir1', 'dir2', 'file2'), 1234) - self.RunZip([self.zipname, '-r', 'dir1']) + self.RunZip(self.zipname, '-r', 'dir1') self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 4) def testUpdate(self): file1 = self.MakeFile('file1', 1223) - self.RunZip([self.zipname, file1]) + self.RunZip(self.zipname, file1) self.OpenZipFile() self.assertEqual(self.GetZipInfo(file1).file_size, 1223) file1 = self.MakeFile('file1', 2334) - self.RunZip([self.zipname, file1]) + self.RunZip(self.zipname, file1) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 1) self.assertEqual(self.GetZipInfo(file1).file_size, 2334) @@ -138,13 +140,13 @@ class TestZip(unittest.TestCase): file2 = self.MakeFile('file2', 256) file3 = self.MakeFile('file3', 512) file4 = self.MakeFile('file4', 1024) - self.RunZip([self.zipname, file1, file2, file3, file4]) + self.RunZip(self.zipname, file1, file2, file3, file4) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 4) self.CloseZipFile() file3 = self.MakeFile('file3', 768) - self.RunZip([self.zipname, file3]) + self.RunZip(self.zipname, file3) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 4) self.assertEqual(self.zipfile.namelist()[0], file1) @@ -161,14 +163,14 @@ class TestZip(unittest.TestCase): file1 = self.MakeFile(os.path.join('dir1', 'file1'), 256) os.mkdir(self.GetTempPath(os.path.join('dir1', 'dir2'))) self.MakeFile(os.path.join('dir1', 'dir2', 'file2'), 1234) - self.RunZip([self.zipname, '-r', 'dir1']) + self.RunZip(self.zipname, '-r', 'dir1') self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 4) self.assertEqual(self.GetZipInfo(file1).file_size, 256) self.CloseZipFile() self.MakeFile(file1, 2560) - self.RunZip([self.zipname, file1]) + self.RunZip(self.zipname, file1) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 4) self.assertEqual(self.GetZipInfo(file1).file_size, 2560) @@ -176,16 +178,80 @@ class TestZip(unittest.TestCase): def testAppend(self): file1 = self.MakeFile('file1', 128) file2 = self.MakeFile('file2', 256) - self.RunZip([self.zipname, file1, file2]) + self.RunZip(self.zipname, file1, file2) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 2) self.CloseZipFile() file3 = self.MakeFile('file3', 768) - self.RunZip([self.zipname, file3]) + self.RunZip(self.zipname, file3) self.OpenZipFile() self.assertEqual(len(self.zipfile.namelist()), 3) +class TestWhich(unittest.TestCase): + def setUp(self): + self.path_list = [] + self.tempdir = tempfile.mkdtemp() + shutil.copy(os.path.join(PARENT_DIR, 'oshelpers.py'), + self.tempdir) + + def tearDown(self): + shutil.rmtree(self.tempdir) + + def Mkdir(self, path): + os.mkdir(os.path.join(self.tempdir, path)) + + def MakeExecutableFile(self, *path_components): + path = os.path.join(self.tempdir, *path_components) + if sys.platform == 'win32': + path += '.exe' + + with open(path, 'w') as f: + f.write('') + os.chmod(path, 0755) + + return path + + def RunWhich(self, *args): + paths = os.pathsep.join(os.path.join(self.tempdir, p) + for p in self.path_list) + env = {'PATH': paths} + return RunCmd('which', list(args), cwd=self.tempdir, env=env) + + def testNothing(self): + self.assertRaises(RunError, self.RunWhich, 'foo') + + def testBasic(self): + self.Mkdir('bin') + bin_cp = self.MakeExecutableFile('bin', 'cp') + cp = os.path.basename(bin_cp) + + self.path_list.append('bin') + output, _ = self.RunWhich(cp) + self.assertTrue(os.path.join(self.tempdir, 'bin', cp) in output) + + def testMulti(self): + self.Mkdir('bin') + bin_cp = self.MakeExecutableFile('bin', 'cp') + bin_ls = self.MakeExecutableFile('bin', 'ls') + cp = os.path.basename(bin_cp) + ls = os.path.basename(bin_ls) + + self.path_list.append('bin') + output, _ = self.RunWhich(cp, ls) + self.assertTrue(os.path.join(self.tempdir, 'bin', cp) in output) + self.assertTrue(os.path.join(self.tempdir, 'bin', ls) in output) + + def testNonPath(self): + self.Mkdir('bin') + bin_cp = self.MakeExecutableFile('bin', 'cp') + cp = os.path.basename(bin_cp) + + # Note, "bin" not added to PATH. + output, _ = self.RunWhich(bin_cp) + self.assertTrue(os.path.join('bin', cp) in output) + + if __name__ == '__main__': unittest.main() |