Advertisement
Guest User

SCons build script that downloads and compiles googletest

a guest
Sep 29th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import importlib
  5. import os
  6.  
  7. # ----------------------------------------------------------------------------------------------- #
  8.  
  9. def rebase(file_list, old_directory, new_directory):
  10.     """Quick and dirty stand-in to alter the path of a set of files"""
  11.  
  12.     rebased_file_list = []
  13.  
  14.     for file in file_list:
  15.         rebased_file_list.append(str(file).replace(old_directory, new_directory))
  16.  
  17.     return rebased_file_list
  18.  
  19. # ----------------------------------------------------------------------------------------------- #
  20.  
  21. environment = Environment()
  22.  
  23. # ----------------------------------------------------------------------------------------------- #
  24. # Step 1: Download the current release
  25.  
  26. download_url = 'https://github.com/google/googletest/archive/release-1.8.1.tar.gz'
  27.  
  28. # Determine the target filename for the download (below 'downloads' folder)
  29. archive_filename = os.path.basename(download_url)
  30. archive_file = environment.File(os.path.join('downloads', archive_filename))
  31.  
  32. # Tell SCons how to "produce" the downloaded archive (by calling wget)
  33. download_archive = environment.Command(
  34.     source = None, # The real world script points to a 'download_url' file
  35.     action = 'wget ' + download_url + ' --output-document=$TARGET',
  36.     target = archive_file
  37. )
  38.  
  39. # ----------------------------------------------------------------------------------------------- #
  40. # Step 2: Extract the release into the build directory
  41.  
  42. source_files = [
  43.     'build/googletest/src/gtest.cc',
  44.     'build/googletest/src/gtest-death-test.cc',
  45.     'build/googletest/src/gtest-filepath.cc',
  46.     'build/googletest/src/gtest-port.cc',
  47.     'build/googletest/src/gtest-printers.cc',
  48.     'build/googletest/src/gtest-test-part.cc',
  49.     'build/googletest/src/gtest-typed-test.cc'
  50. ]
  51.  
  52. # Tell SCons how to "produce" the sources & headers (by calling tar)
  53. extract_archive = environment.Command(
  54.     source = archive_file,
  55.     action = 'tar --extract --gzip --strip-components=1 --file=$SOURCE --directory=build',
  56.     target = source_files
  57. )
  58.  
  59. # ----------------------------------------------------------------------------------------------- #
  60. # Step 3: Compile the library
  61.  
  62. if False: # Works: waits for the archive to extract, then compiles
  63.     gtest_environment = environment.Clone()
  64.     gtest_environment.Append(CPPPATH=['build/googletest'])
  65.     gtest_environment.StaticLibrary('bin/gtest', source_files)
  66.  
  67. else: # Fails: attempts to compile before the archive is extracted
  68.     gtest_environment = environment.Clone()
  69.     gtest_environment.Append(CPPPATH=['build/googletest'])
  70.  
  71.     gtest_environment.VariantDir('obj/linux-amd64/src', 'build/googletest/src', duplicate = 0)
  72.     variantdir_source_files = rebase(
  73.         source_files, 'build/googletest/src/', 'obj/linux-amd64/src/'
  74.     )
  75.     gtest_environment.StaticLibrary('bin/gtest', variantdir_source_files)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement