Skip to content

Instantly share code, notes, and snippets.

@bdbaddog
Last active September 29, 2019 20:35
Show Gist options
  • Save bdbaddog/c02ca2b07c3a57898ed7e746c9e6a006 to your computer and use it in GitHub Desktop.
Save bdbaddog/c02ca2b07c3a57898ed7e746c9e6a006 to your computer and use it in GitHub Desktop.
Zikare's variantdir issue
$ git clean -xfd
Removing .sconsign.dblite
Removing bin/
Removing build/
Removing downloads/
Williams-MacBook-Pro-4:zikare bdbaddog$ python ~/devel/scons/git/as_scons/src/script/scons.py
scons: Reading SConscript files ...
Extract_archive: ['/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest.cc', '/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest-death-test.cc', '/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest-filepath.cc', '/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest-port.cc', '/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest-printers.cc', '/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest-test-part.cc', '/Users/bdbaddog/devel/scons/tmp/zikare/build/googletest/src/gtest-typed-test.cc']
rebased:['build/googletest/src/gtest.cc', 'build/googletest/src/gtest-death-test.cc', 'build/googletest/src/gtest-filepath.cc', 'build/googletest/src/gtest-port.cc', 'build/googletest/src/gtest-printers.cc', 'build/googletest/src/gtest-test-part.cc', 'build/googletest/src/gtest-typed-test.cc']
scons: done reading SConscript files.
scons: Building targets ...
wget https://github.com/google/googletest/archive/release-1.8.1.tar.gz --output-document=downloads/release-1.8.1.tar.gz
--2019-09-29 16:33:45-- https://github.com/google/googletest/archive/release-1.8.1.tar.gz
Resolving github.com (github.com)... 140.82.114.3
Connecting to github.com (github.com)|140.82.114.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/google/googletest/tar.gz/release-1.8.1 [following]
--2019-09-29 16:33:46-- https://codeload.github.com/google/googletest/tar.gz/release-1.8.1
Resolving codeload.github.com (codeload.github.com)... 192.30.253.121
Connecting to codeload.github.com (codeload.github.com)|192.30.253.121|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 992298 (969K) [application/x-gzip]
Saving to: ‘downloads/release-1.8.1.tar.gz’
downloads/release-1.8.1.tar.gz 100%[=============================================================>] 969.04K 5.68MB/s in 0.2s
2019-09-29 16:33:46 (5.68 MB/s) - ‘downloads/release-1.8.1.tar.gz’ saved [992298/992298]
tar --extract --gzip --strip-components=1 --file=downloads/release-1.8.1.tar.gz --directory=build
g++ -o build/googletest/src/gtest.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest.cc
g++ -o build/googletest/src/gtest-death-test.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest-death-test.cc
g++ -o build/googletest/src/gtest-filepath.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest-filepath.cc
g++ -o build/googletest/src/gtest-port.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest-port.cc
g++ -o build/googletest/src/gtest-printers.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest-printers.cc
g++ -o build/googletest/src/gtest-test-part.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest-test-part.cc
g++ -o build/googletest/src/gtest-typed-test.o -c -Ibuild/googletest/include -Ibuild/googletest build/googletest/src/gtest-typed-test.cc
ar rc bin/libgtest.a build/googletest/src/gtest.o build/googletest/src/gtest-death-test.o build/googletest/src/gtest-filepath.o build/googletest/src/gtest-port.o build/googletest/src/gtest-printers.o build/googletest/src/gtest-test-part.o build/googletest/src/gtest-typed-test.o
ranlib bin/libgtest.a
scons: done building targets.
#!/usr/bin/env python
import sys
import importlib
import os
# ----------------------------------------------------------------------------------------------- #
def rebase(file_list, old_directory, new_directory):
"""Quick and dirty stand-in to alter the path of a set of files"""
rebased_file_list = []
for file in file_list:
rebased_file_list.append(str(file).replace(old_directory, new_directory))
return rebased_file_list
# ----------------------------------------------------------------------------------------------- #
environment = Environment()
environment.AppendENVPath('PATH', '/opt/local/bin')
# ----------------------------------------------------------------------------------------------- #
# Step 1: Download the current release
download_url = 'https://github.com/google/googletest/archive/release-1.8.1.tar.gz'
# Determine the target filename for the download (below 'downloads' folder)
archive_filename = os.path.basename(download_url)
archive_file = environment.File(os.path.join('downloads', archive_filename))
# Tell SCons how to "produce" the downloaded archive (by calling wget)
download_archive = environment.Command(
source = Value(download_url), # The real world script points to a 'download_url' file
action = 'wget ' + download_url + ' --output-document=$TARGET',
target = '#/downloads/%s'%archive_filename
)
# ----------------------------------------------------------------------------------------------- #
# Step 2: Extract the release into the build directory
source_files = [
'build/googletest/src/gtest.cc',
'build/googletest/src/gtest-death-test.cc',
'build/googletest/src/gtest-filepath.cc',
'build/googletest/src/gtest-port.cc',
'build/googletest/src/gtest-printers.cc',
'build/googletest/src/gtest-test-part.cc',
'build/googletest/src/gtest-typed-test.cc'
]
# Tell SCons how to "produce" the sources & headers (by calling tar)
extract_archive = environment.Command(
source = download_archive,
action = 'tar --extract --gzip --strip-components=1 --file=$SOURCE --directory=build',
target = source_files
)
print("Extract_archive: %s"%[type(e) for e in extract_archive])
# ----------------------------------------------------------------------------------------------- #
# Step 3: Compile the library
if False: # Works: waits for the archive to extract, then compiles
gtest_environment = environment.Clone()
gtest_environment.Append(CPPPATH=['build/googletest'])
gtest_environment.StaticLibrary('bin/gtest', source_files)
else: # Fails: attempts to compile before the archive is extracted
gtest_environment = environment.Clone()
gtest_environment.Append(CPPPATH=['build/googletest/include', 'build/googletest'])
gtest_environment.VariantDir('obj/linux-amd64/src', 'build/googletest/src', duplicate = 0)
variantdir_source_files = rebase(
source_files, '#build/googletest/src/', 'obj/linux-amd64/src/'
)
print("rebased:%s"%[str(f) for f in variantdir_source_files])
gtest_environment.StaticLibrary('bin/gtest', variantdir_source_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment