diff options
Diffstat (limited to 'BuildTools')
-rw-r--r-- | BuildTools/CLang/.gitignore | 4 | ||||
-rw-r--r-- | BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp | 228 | ||||
-rw-r--r-- | BuildTools/CLang/SConscript | 15 | ||||
-rwxr-xr-x | BuildTools/CheckHeaders.py | 43 | ||||
-rwxr-xr-x | BuildTools/Copyright/find-contribs.py | 57 | ||||
-rwxr-xr-x | BuildTools/FilterScanBuildResults.py | 28 | ||||
-rwxr-xr-x | BuildTools/Git/Hooks/pre-commit | 4 | ||||
-rw-r--r-- | BuildTools/MSVS/.gitignore | 4 | ||||
-rw-r--r-- | BuildTools/MSVS/GenerateProjects.py | 100 | ||||
-rw-r--r-- | BuildTools/MSVS/Swift.sln | 26 | ||||
-rw-r--r-- | BuildTools/SCons/SConscript.boot | 165 | ||||
-rw-r--r-- | BuildTools/SCons/SConstruct | 208 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/Flags.py | 5 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/Test.py | 21 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/WindowsBundle.py | 8 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/qt4.py | 36 | ||||
-rwxr-xr-x | BuildTools/scons2ninja.py | 615 |
17 files changed, 1045 insertions, 522 deletions
diff --git a/BuildTools/CLang/.gitignore b/BuildTools/CLang/.gitignore deleted file mode 100644 index df682c0..0000000 --- a/BuildTools/CLang/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -CLangDiagnosticsFlags -CLangDiagnosticsFlagsTool.sh -CLangDiagnosticsFlagsTool -clang-diagnostics-overview.* diff --git a/BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp b/BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp deleted file mode 100644 index ccd5925..0000000 --- a/BuildTools/CLang/CLangDiagnosticsFlagsTool.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <iostream> -#include <set> -#include <vector> -#include <cassert> -#include <boost/algorithm/string/predicate.hpp> -#include <boost/graph/graph_traits.hpp> -#include <boost/graph/adjacency_list.hpp> -#include <boost/graph/topological_sort.hpp> -#include <boost/graph/topological_sort.hpp> -#include <boost/graph/graphviz.hpp> - -// ----------------------------------------------------------------------------- -// Include diagnostics data from CLang -// ----------------------------------------------------------------------------- - -#define DIAG(name, a, b, c, d, e, f, g) name, - -namespace diag { - enum LexKinds { -#include <clang/Basic/DiagnosticLexKinds.inc> -#include <clang/Basic/DiagnosticParseKinds.inc> -#include <clang/Basic/DiagnosticCommonKinds.inc> -#include <clang/Basic/DiagnosticDriverKinds.inc> -#include <clang/Basic/DiagnosticFrontendKinds.inc> -#include <clang/Basic/DiagnosticSemaKinds.inc> - }; -} - -#define GET_DIAG_ARRAYS -#include <clang/Basic/DiagnosticGroups.inc> -#undef GET_DIAG_ARRAYS - -struct DiagTableEntry { - const char* name; - const short* array; - const short* group; -}; - -static const DiagTableEntry diagnostics[] = { -#define GET_DIAG_TABLE -#include <clang/Basic/DiagnosticGroups.inc> -#undef GET_DIAG_TABLE -}; -static const size_t diagnostics_count = sizeof(diagnostics) / sizeof(diagnostics[0]); - -// ----------------------------------------------------------------------------- - -using namespace boost; - -struct Properties { - Properties() : have(false), implicitHave(false), dontWant(false), implicitDontWant(false), ignored(false), available(false), missing(false), redundant(false), alreadyCovered(false) { - } - - std::string name; - bool have; - bool implicitHave; - bool dontWant; - bool implicitDontWant; - bool ignored; - bool available; - bool missing; - bool redundant; - bool alreadyCovered; -}; - -class GraphVizLabelWriter { - public: - GraphVizLabelWriter(const std::vector<Properties>& properties) : properties(properties) { - } - - template <class VertexOrEdge> - void operator()(std::ostream& out, const VertexOrEdge& v) const { - std::string color; - if (properties[v].missing) { - color = "orange"; - } - else if (properties[v].redundant) { - color = "lightblue"; - } - else if (properties[v].have) { - color = "darkgreen"; - } - else if (properties[v].implicitHave) { - color = "green"; - } - else if (properties[v].dontWant) { - color = "red"; - } - else if (properties[v].implicitDontWant) { - color = "pink"; - } - else if (properties[v].ignored) { - color = "white"; - } - else if (properties[v].available) { - color = "yellow"; - } - else { - assert(false); - } - out << "[label=" << escape_dot_string(properties[v].name) << " fillcolor=\"" << color << "\" style=filled]"; - } - - private: - const std::vector<Properties> properties; -}; - -int main(int argc, char* argv[]) { - // Parse command-line arguments - std::set<std::string> have; - std::set<std::string> dontWant; - std::string outputDir; - for (int i = 1; i < argc; ++i) { - std::string arg(argv[i]); - if (starts_with(arg, "-W")) { - have.insert(arg.substr(2, arg.npos)); - } - else if (starts_with(arg, "-w")) { - dontWant.insert(arg.substr(2, arg.npos)); - } - else if (starts_with(arg, "-O")) { - outputDir = arg.substr(2, arg.npos) + "/"; - } - } - - // Build the graph and initialize properties - typedef adjacency_list<vecS, vecS, bidirectionalS> Graph; - typedef graph_traits<Graph>::vertex_descriptor Vertex; - Graph g(diagnostics_count); - std::vector<Properties> properties(num_vertices(g)); - for (size_t i = 0; i < diagnostics_count; ++i) { - std::string name(diagnostics[i].name); - properties[i].name = name; - properties[i].implicitHave = properties[i].have = have.find(name) != have.end(); - properties[i].implicitDontWant = properties[i].dontWant = dontWant.find(name) != dontWant.end(); - properties[i].ignored = diagnostics[i].group == 0 && diagnostics[i].array == 0; - properties[i].alreadyCovered = false; - properties[i].available = true; - for (const short* j = diagnostics[i].group; j && *j != -1; ++j) { - add_edge(i, *j, g); - } - } - - // Sort the diagnostics - std::list<Vertex> sortedDiagnostics; - boost::topological_sort(g, std::front_inserter(sortedDiagnostics)); - - // Propagate dontWant and have properties down - for(std::list<Vertex>::const_iterator i = sortedDiagnostics.begin(); i != sortedDiagnostics.end(); ++i) { - graph_traits<Graph>::adjacency_iterator adjacentIt, adjacentEnd; - for (tie(adjacentIt, adjacentEnd) = adjacent_vertices(*i, g); adjacentIt != adjacentEnd; ++adjacentIt) { - properties[*adjacentIt].implicitDontWant = properties[*i].implicitDontWant || properties[*adjacentIt].implicitDontWant; - properties[*adjacentIt].implicitHave = properties[*i].implicitHave || properties[*adjacentIt].implicitHave; - } - } - - // Propagate 'available' property upwards - for(std::list<Vertex>::const_reverse_iterator i = sortedDiagnostics.rbegin(); i != sortedDiagnostics.rend(); ++i) { - properties[*i].available = properties[*i].available && !properties[*i].implicitDontWant; - graph_traits<Graph>::in_edge_iterator edgesIt, edgesEnd; - graph_traits<Graph>::edge_descriptor edge; - for (tie(edgesIt, edgesEnd) = in_edges(*i, g); edgesIt != edgesEnd; ++edgesIt) { - properties[source(*edgesIt, g)].available = properties[source(*edgesIt, g)].available && properties[*i].available; - } - } - - // Collect missing & redundant flags - std::set<std::string> missing; - std::set<std::string> redundant; - for(std::list<Vertex>::const_iterator i = sortedDiagnostics.begin(); i != sortedDiagnostics.end(); ++i) { - bool markChildrenCovered = true; - if (properties[*i].alreadyCovered) { - if (properties[*i].have) { - properties[*i].redundant = true; - redundant.insert(properties[*i].name); - } - } - else { - if (properties[*i].available) { - if (!properties[*i].implicitHave && !properties[*i].ignored) { - properties[*i].missing = true; - missing.insert(properties[*i].name); - } - } - else { - markChildrenCovered = false; - } - } - if (markChildrenCovered) { - graph_traits<Graph>::adjacency_iterator adjacentIt, adjacentEnd; - for (tie(adjacentIt, adjacentEnd) = adjacent_vertices(*i, g); adjacentIt != adjacentEnd; ++adjacentIt) { - properties[*adjacentIt].alreadyCovered = true; - } - } - } - - // Write information - if (!missing.empty()) { - std::cout << "Missing diagnostic flags: "; - for(std::set<std::string>::const_iterator i = missing.begin(); i != missing.end(); ++i) { - std::cout << "-W" << *i << " "; - } - std::cout<< std::endl; - } - - if (!redundant.empty()) { - std::cout << "Redundant diagnostic flags: "; - for(std::set<std::string>::const_iterator i = redundant.begin(); i != redundant.end(); ++i) { - std::cout << "-W" << *i << " "; - } - std::cout<< std::endl; - } - - // Write graphviz file - if (!outputDir.empty()) { - std::ofstream f((outputDir + "clang-diagnostics-overview.dot").c_str()); - write_graphviz(f, g, GraphVizLabelWriter(properties)); - f.close(); - } - - return 0; -} diff --git a/BuildTools/CLang/SConscript b/BuildTools/CLang/SConscript deleted file mode 100644 index 850c35c..0000000 --- a/BuildTools/CLang/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -Import("env") - -#myenv = Environment() -#myenv.Append(CPPPATH = ["."]) -#myenv.Program("CLangDiagnosticsFlagsTool", ["CLangDiagnosticsFlagsTool.cpp"]) -# -#disabledDiagnostics = ["-wunreachable-code", "-wunused-macros", "-wmissing-noreturn", "-wlong-long", "-wcast-align", "-wglobal-constructors", "-wmissing-prototypes", "-wpadded", "-wshadow"] -#clangDiagnosticsFlagsToolCommand = "BuildTools/CLang/CLangDiagnosticsFlagsTool -O" + env.Dir(".").abspath + " " + " ".join(disabledDiagnostics) + " " -#clangDiagnosticsFlagsToolCommand += " ".join([flag for flag in env["CXXFLAGS"] if flag.startswith("-W")]) -#clangDiagnosticsFlagsToolCommand += "\n" -#clangDiagnosticsFlagsToolCommand += "dot -Tpng " + env.Dir(".").abspath + "/clang-diagnostics-overview.dot > " + env.Dir(".").abspath + "/clang-diagnostics-overview.png\n" -#v = env.WriteVal("#/BuildTools/CLang/CLangDiagnosticsFlagsTool.sh", env.Value(clangDiagnosticsFlagsToolCommand)) -#env.AddPostAction(v, Chmod(v[0], 0755)) -# -# diff --git a/BuildTools/CheckHeaders.py b/BuildTools/CheckHeaders.py index 73f49db..274a760 100755 --- a/BuildTools/CheckHeaders.py +++ b/BuildTools/CheckHeaders.py @@ -2,20 +2,41 @@ import os, sys +FORBIDDEN_INCLUDES = [ + ("iostream", ["Swiften/Base/format.h"]), + ("Base/Log.h", []), + ("Base/format.h", []), + ("algorithm", ["Swiften/Base/Algorithm.h", "Swiften/Base/SafeAllocator.h", "Swiften/Base/Listenable.h"]), + ("boost/bind.hpp", ["Swiften/Base/Listenable.h"]), + ("boost/filesystem.hpp", []), + ("Base/foreach.h", []), + ("boost/date_time/date_time.hpp", []), + ("boost/filesystem/filesystem.hpp", []), + + # To avoid + ("Base/Algorithm.h", ["Swiften/StringCodecs/HMAC.h"]), +] + foundBadHeaders = False -for (path, dirs, files) in os.walk(".") : - if "3rdParty" in path or ".sconf" in path or ".framework" in path : +filename = sys.argv[1] + +if "3rdParty" in filename or ".sconf" in filename or ".framework" in filename or not filename.endswith(".h") : + sys.exit(0) +if not "Swiften" in filename : + sys.exit(0) +if filename.endswith("Swiften.h") : + sys.exit(0) + +file = open(filename, "r") +for line in file.readlines() : + if not "#include" in line : continue - if not "Swiften" in path : + if "Base/Log.h" in filename : continue - - for filename in [os.path.join(path, file) for file in files if file.endswith(".h")] : - file = open(filename, "r") - for line in file.readlines() : - for include in ["iostream", "algorithm", "cassert", "boost/bind.hpp", "boost/filesystem.hpp", "Base/foreach.h", "Base/Log.h", "boost/date_time/date_time.hpp", "boost/filesystem/filesystem.hpp"] : - if "#include" in line and include in line and not "Base/Log" in filename : - print "Found " + include + " include in " + filename - foundBadHeaders = True + for forbiddenInclude, ignores in FORBIDDEN_INCLUDES : + if forbiddenInclude in line and len([x for x in ignores if x in filename]) == 0 : + print "Found " + forbiddenInclude + " include in " + filename + foundBadHeaders = True sys.exit(foundBadHeaders) diff --git a/BuildTools/Copyright/find-contribs.py b/BuildTools/Copyright/find-contribs.py new file mode 100755 index 0000000..63c454e --- /dev/null +++ b/BuildTools/Copyright/find-contribs.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import subprocess + +def print_log(full_log): + full_log_lines = full_log.split("\n") + + commits = [] + + commit_bit = "commit " + author_bit = "Author: " + date_bit = "Date: " + + commit = None + for line in full_log_lines: + + if line[0:len(commit_bit)] == commit_bit: + if commit: + commits.append(commit) + commit = {'text':''} + handled = False + for bit in [commit_bit, author_bit, date_bit]: + if line[0:len(bit)] == bit: + commit[bit] = line + handled = True + if not handled: + commit['text'] += line + + commits.append(commit) + + contributions = [] + + for commit in commits: + if not "git@kismith.co.uk" in commit[author_bit] and not "git@el-tramo.be" in commit[author_bit]: + contributions.append(commit) + + #print contributions + contributors = {} + for commit in contributions: + if not commit[author_bit] in contributors: + contributors[commit[author_bit]] = [] + contributors[commit[author_bit]].append(commit[commit_bit]) + + for contributor in contributors: + print contributor + " has contributed patches " + ", ".join([commit[len(commit_bit):] for commit in contributors[contributor]]) + +full_swiften_log = subprocess.check_output(["git", "log", "--", "Swiften"]) + +print "Contributors for Swiften/ subtree:\n" +print_log(full_swiften_log) + +full_all_log = subprocess.check_output(["git", "log"]) + +print "\n\n\n\n" + +print "Contributors for full tree:\n" +print_log(full_all_log) diff --git a/BuildTools/FilterScanBuildResults.py b/BuildTools/FilterScanBuildResults.py new file mode 100755 index 0000000..53a345f --- /dev/null +++ b/BuildTools/FilterScanBuildResults.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import os, os.path, sys, re + +resultsDir = sys.argv[1] +resultDirs = [ d for d in os.listdir(resultsDir) if os.path.isdir(os.path.join(resultsDir, d)) ] +resultDirs.sort() +if len(resultDirs) > 0 : + resultDir = os.path.join(resultsDir, resultDirs[-1]) + resultFileName = os.path.join(resultDir, "index.html") + resultData = [] + f = open(resultFileName, "r") + skipLines = 0 + for line in f.readlines() : + if skipLines > 0 : + skipLines -= 1 + else : + if ("3rdParty" in line or "SHA1.cpp" in line or "lua.c" in line) : + m = re.match(".*(report-.*\.html)", line) + os.remove(os.path.join(resultDir, m.group(1))) + skipLines = 2 + else : + resultData.append(line) + f.close() + + f = open(resultFileName, "w") + f.writelines(resultData) + f.close() diff --git a/BuildTools/Git/Hooks/pre-commit b/BuildTools/Git/Hooks/pre-commit index 11f0c2d..ad0945e 100755 --- a/BuildTools/Git/Hooks/pre-commit +++ b/BuildTools/Git/Hooks/pre-commit @@ -16,4 +16,8 @@ for file in $(git diff --cached --name-only); do echo "ERROR: '$file' has a copyright error. Aborting commit." exit -1 fi + if ! BuildTools/CheckHeaders.py $file; then + echo "ERROR: '$file' failed header sanity test. Aborting commit." + exit -1 + fi done diff --git a/BuildTools/MSVS/.gitignore b/BuildTools/MSVS/.gitignore deleted file mode 100644 index 95a4834..0000000 --- a/BuildTools/MSVS/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.suo -*.ncp -Slimber -Swift diff --git a/BuildTools/MSVS/GenerateProjects.py b/BuildTools/MSVS/GenerateProjects.py deleted file mode 100644 index d13df08..0000000 --- a/BuildTools/MSVS/GenerateProjects.py +++ /dev/null @@ -1,100 +0,0 @@ -import os, os.path - -projects = [("Swift", "Swift\QtUI\Swift.exe"), ("Slimber", "Slimber\Qt\Slimber.exe")] - -for (project, outputbin) in projects : - if not os.path.exists(project) : - os.mkdir(project) - output = open(os.path.join(project, project + ".vcproj"), "w") - - headers = [] - sources = [] - for root, dirs, files in os.walk(os.path.join("..", "..", project)) : - for file in files : - if file.endswith(".h") : - headers.append('<File RelativePath="' + os.path.join("..", root, file) + '" />') - elif file.endswith(".cpp") : - sources.append('<File RelativePath="' + os.path.join("..", root, file) + '" />') - - output.write("""<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="9.00" - Name="%(project)s" - Keyword="MakeFileProj" - TargetFrameworkVersion="196613" - > - <Platforms> - <Platform - Name="Win32" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="0" - > - <Tool - Name="VCNMakeTool" - BuildCommandLine="cd ..\..\..\ && scons debug=1 %(project)s" - ReBuildCommandLine="" - CleanCommandLine="cd ..\..\..\ && scons -c debug=1 %(project)s" - Output="..\..\..\%(output)s" - PreprocessorDefinitions="WIN32;_DEBUG" - IncludeSearchPath="" - ForcedIncludes="" - AssemblySearchPath="" - ForcedUsingAssemblies="" - CompileAsManaged="" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="0" - > - <Tool - Name="VCNMakeTool" - BuildCommandLine="cd ..\..\..\ && scons %(project)s" - ReBuildCommandLine="" - CleanCommandLine="cd ..\..\..\ && scons -c %(project)s" - Output="..\..\..\%(output)s" - PreprocessorDefinitions="WIN32;NDEBUG" - IncludeSearchPath="" - ForcedIncludes="" - AssemblySearchPath="" - ForcedUsingAssemblies="" - CompileAsManaged="" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <Filter - Name="Source Files" - Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" - > - %(sources)s - </Filter> - <Filter - Name="Header Files" - Filter="h;hpp;hxx;hm;inl;inc;xsd" - > - %(headers)s - </Filter> - <Filter - Name="Resource Files" - Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" - > - </Filter> - </Files> - <Globals> - </Globals> -</VisualStudioProject>""" % { "project": project, "output" : outputbin, "headers" : '\n'.join(headers), "sources": '\n'.join(sources) }) - output.close() diff --git a/BuildTools/MSVS/Swift.sln b/BuildTools/MSVS/Swift.sln deleted file mode 100644 index 2724f81..0000000 --- a/BuildTools/MSVS/Swift.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual C++ Express 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Swift", "Swift\Swift.vcproj", "{C67C3A5B-1382-4B4A-88F7-3BFC98DA43A2}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Slimber", "Slimber\Slimber.vcproj", "{597242B2-A667-47A1-B69E-D2C4281183D0}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C67C3A5B-1382-4B4A-88F7-3BFC98DA43A2}.Debug|Win32.ActiveCfg = Debug|Win32 - {C67C3A5B-1382-4B4A-88F7-3BFC98DA43A2}.Debug|Win32.Build.0 = Debug|Win32 - {C67C3A5B-1382-4B4A-88F7-3BFC98DA43A2}.Release|Win32.ActiveCfg = Release|Win32 - {C67C3A5B-1382-4B4A-88F7-3BFC98DA43A2}.Release|Win32.Build.0 = Release|Win32 - {597242B2-A667-47A1-B69E-D2C4281183D0}.Debug|Win32.ActiveCfg = Debug|Win32 - {597242B2-A667-47A1-B69E-D2C4281183D0}.Debug|Win32.Build.0 = Debug|Win32 - {597242B2-A667-47A1-B69E-D2C4281183D0}.Release|Win32.ActiveCfg = Release|Win32 - {597242B2-A667-47A1-B69E-D2C4281183D0}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/BuildTools/SCons/SConscript.boot b/BuildTools/SCons/SConscript.boot index 361004f..4e7e037 100644 --- a/BuildTools/SCons/SConscript.boot +++ b/BuildTools/SCons/SConscript.boot @@ -8,19 +8,20 @@ sys.path.append(Dir("#/BuildTools/SCons").abspath) vars = Variables(os.path.join(Dir("#").abspath, "config.py")) vars.Add('cc', "C compiler") vars.Add('cxx', "C++ compiler") -vars.Add('ccflags', "Extra C(++) compiler flags") +vars.Add('ccflags', "Extra C/C++/ObjC compiler flags") +vars.Add('cxxflags', "Extra C++ compiler flags") vars.Add('link', "Linker") vars.Add('linkflags', "Extra linker flags") vars.Add(BoolVariable("ccache", "Use CCache", "no")) -vars.Add(BoolVariable("distcc", "Use DistCC", "no")) -vars.Add('distcc_hosts', "DistCC hosts (overrides DISTCC_HOSTS)") vars.Add(EnumVariable("test", "Compile and run tests", "none", ["none", "all", "unit", "system"])) vars.Add(BoolVariable("optimize", "Compile with optimizations turned on", "no")) vars.Add(BoolVariable("debug", "Compile with debug information", "yes")) vars.Add(BoolVariable("allow_warnings", "Allow compilation warnings during compilation", "yes")) vars.Add(BoolVariable("assertions", "Compile with assertions", "yes")) vars.Add(BoolVariable("max_jobs", "Build with maximum number of parallel jobs", "no")) -vars.Add(EnumVariable("target", "Choose a target platform for compilation", "native", ["native", "iphone-simulator", "iphone-device", "xcode"])) +vars.Add(EnumVariable("target", "Choose a target platform for compilation", "native", ["native", "iphone-simulator", "iphone-device", "xcode", "android"])) +vars.Add('android_toolchain', "Path to Android toolchain") +vars.Add('android_sdk_bin', "Path to Android SDK's tools directory") vars.Add(BoolVariable("swift_mobile", "Build mobile Swift", "no")) vars.Add(BoolVariable("swiften_dll", "Build Swiften as dynamically linked library", "no")) if os.name != "nt" : @@ -38,6 +39,8 @@ if os.name == "nt" : if os.name == "nt" : vars.Add(PackageVariable("bonjour", "Bonjour SDK location", "yes")) vars.Add(PackageVariable("openssl", "OpenSSL location", "yes")) +vars.Add(BoolVariable("openssl_force_bundled", "Force use of the bundled OpenSSL", "no")) +vars.Add(PackageVariable("hunspell", "Hunspell location", False)) vars.Add(PathVariable("boost_includedir", "Boost headers location", None, PathVariable.PathAccept)) vars.Add(PathVariable("boost_libdir", "Boost library location", None, PathVariable.PathAccept)) vars.Add(PathVariable("expat_includedir", "Expat headers location", None, PathVariable.PathAccept)) @@ -47,27 +50,41 @@ vars.Add(PackageVariable("icu", "ICU library location", "no")) vars.Add(PathVariable("libidn_includedir", "LibIDN headers location", None, PathVariable.PathAccept)) vars.Add(PathVariable("libidn_libdir", "LibIDN library location", None, PathVariable.PathAccept)) vars.Add("libidn_libname", "LibIDN library name", "libidn" if os.name == "nt" else "idn") +vars.Add(PathVariable("libminiupnpc_includedir", "LibMiniUPNPC headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("libminiupnpc_libdir", "LibMiniUPNPC library location", None, PathVariable.PathAccept)) +vars.Add("libminiupnpc_libname", "LibMiniUPNPC library name", "libminiupnpc" if os.name == "nt" else "miniupnpc") +vars.Add(PathVariable("libnatpmp_includedir", "LibNATPMP headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("libnatpmp_libdir", "LibNATPMP library location", None, PathVariable.PathAccept)) +vars.Add("libnatpmp_libname", "LibNATPMP library name", "libnatpmp" if os.name == "nt" else "natpmp") vars.Add(PathVariable("sqlite_includedir", "SQLite headers location", None, PathVariable.PathAccept)) vars.Add(PathVariable("sqlite_libdir", "SQLite library location", None, PathVariable.PathAccept)) vars.Add("sqlite_libname", "SQLite library name", "libsqlite3" if os.name == "nt" else "sqlite3") vars.Add("sqlite_force_bundled", "Force use of the bundled SQLite", None) +vars.Add(PathVariable("lua_includedir", "Lua headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("lua_libdir", "Lua library location", None, PathVariable.PathAccept)) +vars.Add("lua_libname", "Lua library name", "liblua" if os.name == "nt" else "lua") +vars.Add("lua_force_bundled", "Force use of the bundled Lua", None) vars.Add(PathVariable("avahi_includedir", "Avahi headers location", None, PathVariable.PathAccept)) vars.Add(PathVariable("avahi_libdir", "Avahi library location", None, PathVariable.PathAccept)) vars.Add(PathVariable("qt", "Qt location", "", PathVariable.PathAccept)) +vars.Add(BoolVariable("qt5", "Compile in Qt5 mode", "no")) # TODO: auto-detect this vars.Add(PathVariable("docbook_xml", "DocBook XML", None, PathVariable.PathAccept)) vars.Add(PathVariable("docbook_xsl", "DocBook XSL", None, PathVariable.PathAccept)) vars.Add(BoolVariable("build_examples", "Build example programs", "yes")) vars.Add(BoolVariable("enable_variants", "Build in a separate dir under build/, depending on compile flags", "no")) -vars.Add(BoolVariable("experimental", "Build experimental features", "no")) +vars.Add(BoolVariable("experimental", "Build experimental features", "yes")) vars.Add(BoolVariable("set_iterator_debug_level", "Set _ITERATOR_DEBUG_LEVEL=0", "yes")) +vars.Add(BoolVariable("unbound", "Build bundled ldns and unbound. Use them for DNS lookup.", "no")) ################################################################################ # Set up default build & configure environment ################################################################################ + env_ENV = { 'PATH' : os.environ['PATH'], 'LD_LIBRARY_PATH' : os.environ.get("LD_LIBRARY_PATH", ""), + 'TERM' : os.environ.get("TERM", ""), } if "MSVC_VERSION" in ARGUMENTS : env = Environment(ENV = env_ENV, variables = vars, MSVC_VERSION = ARGUMENTS["MSVC_VERSION"]) @@ -76,8 +93,18 @@ else : Help(vars.GenerateHelpText(env)) +# Workaround for missing Visual Studio 2012 support in SCons +# Requires scons to be run from a VS2012 console +if env.get("MSVC_VERSION", "").startswith("11.0") : + env["ENV"]["LIB"] = os.environ["LIB"] + env["ENV"]["INCLUDE"] = os.environ["INCLUDE"] + # Default environment variables -env["PLATFORM_FLAGS"] = {} +env["PLATFORM_FLAGS"] = { + "LIBPATH": [], + "LIBS": [], + "FRAMEWORKS": [], +} # Default custom tools env.Tool("Test", toolpath = ["#/BuildTools/SCons/Tools"]) @@ -104,33 +131,50 @@ if env["max_jobs"] : except ImportError : pass -# Default compiler flags -if env.get("distcc", False) : - env["ENV"]["HOME"] = os.environ["HOME"] - env["ENV"]["DISTCC_HOSTS"] = os.environ.get("DISTCC_HOSTS", "") - if "distcc_hosts" in env : - env["ENV"]["DISTCC_HOSTS"] = env["distcc_hosts"] - env["CC"] = "distcc gcc" - env["CXX"] = "distcc g++" +# Set speed options +env.Decider("MD5-timestamp") +env.SetOption("max_drift", 1) +env.SetOption("implicit_cache", True) + +# Set the default compiler to CLang on OS X, and set the necessary flags +if env["PLATFORM"] == "darwin" and env["target"] == "native" : + if "cc" not in env : + env["CC"] = "clang" + if platform.machine() == "x86_64" : + env["CCFLAGS"] = ["-arch", "x86_64"] + if "cxx" not in env : + env["CXX"] = "clang++" + # Compiling Qt5 in C++0x mode includes headers that we don't have + if not env["qt5"] : + env["CXXFLAGS"] = ["-std=c++11"] + if "link" not in env : + env["LINK"] = "clang" + if platform.machine() == "x86_64" : + env.Append(LINKFLAGS = ["-arch", "x86_64"]) + +# Check whether we are running inside scan-build, and override compiler if so +if "CCC_ANALYZER_HTML" in os.environ : + for key, value in os.environ.items() : + if key.startswith("CCC_") or key.startswith("CLANG") : + env["ENV"][key] = value + env["CC"] = os.environ["CC"] + env["CXX"] = os.environ["CXX"] + +# Override the compiler with custom variables set at config time if "cc" in env : env["CC"] = env["cc"] if "cxx" in env : env["CXX"] = env["cxx"] -ccflags = env.get("ccflags", []) -if isinstance(ccflags, str) : - # FIXME: Make the splitting more robust - env["CCFLAGS"] = ccflags.split(" ") -else : - env["CCFLAGS"] = ccflags if "link" in env : env["SHLINK"] = env["link"] env["LINK"] = env["link"] -linkflags = env.get("linkflags", []) -if isinstance(linkflags, str) : - # FIXME: Make the splitting more robust - env["LINKFLAGS"] = linkflags.split(" ") -else : - env["LINKFLAGS"] = linkflags +for flags_type in ["ccflags", "cxxflags", "linkflags"] : + if flags_type in env : + if isinstance(env[flags_type], str) : + # FIXME: Make the splitting more robust + env[flags_type.upper()] = env[flags_type].split(" ") + else : + env[flags_type.upper()] = env[flags_type] # This isn't a real flag (yet) AFAIK. Be sure to append it to the CXXFLAGS # where you need it env["OBJCCFLAGS"] = [] @@ -146,7 +190,7 @@ if env["target"] == "xcode" and os.environ["CONFIGURATION"] == "Release" : if env["debug"] : if env["PLATFORM"] == "win32" : - env.Append(CCFLAGS = ["/Z7"]) + env.Append(CCFLAGS = ["/Zi"]) env.Append(LINKFLAGS = ["/DEBUG"]) if env["set_iterator_debug_level"] : env.Append(CPPDEFINES = ["_ITERATOR_DEBUG_LEVEL=0"]) @@ -184,7 +228,6 @@ if env.get("mac105", 0) : "-mmacosx-version-min=10.5", "-isysroot", "/Developer/SDKs/MacOSX10.5.sdk", "-arch", "i386"]) - env.Append(FRAMEWORKS = ["Security"]) if env.get("mac106", 0) : assert(env["PLATFORM"] == "darwin") env.Append(CCFLAGS = [ @@ -194,7 +237,6 @@ if env.get("mac106", 0) : "-mmacosx-version-min=10.6", "-isysroot", "/Developer/SDKs/MacOSX10.6.sdk", "-arch", "i386"]) - env.Append(FRAMEWORKS = ["Security"]) if not env["assertions"] : env.Append(CPPDEFINES = ["NDEBUG"]) @@ -209,24 +251,33 @@ if env["PLATFORM"] == "posix" and platform.machine() == "x86_64" : # Warnings if env["PLATFORM"] == "win32" : - # TODO: Find the ideal set of warnings - #env.Append(CCFLAGS = ["/Wall"]) - pass + env.Append(CXXFLAGS = ["/wd4068"]) else : - env.Append(CXXFLAGS = ["-Wextra", "-Wall", "-Wnon-virtual-dtor", "-Wundef", "-Wold-style-cast", "-Wno-long-long", "-Woverloaded-virtual", "-Wfloat-equal", "-Wredundant-decls"]) + if "clang" in env["CXX"] : + env.Append(CXXFLAGS = [ + "-Weverything", + "-Wno-unknown-warning-option", # To stay compatible between CLang versions + "-Wno-unknown-pragmas", # To stay compatible between CLang versions + "-Wno-weak-vtables", # Virtually none of our elements have outlined methods. This also seems to affect classes in .cpp files, which in turn affects all our tests, which may need fixing in CLang + "-Wno-shadow", # Also warns for shadowing on constructor arguments, which we do a lot + "-Wno-documentation", # We don't care about documentation warnings + "-Wno-exit-time-destructors", # Used a lot in e.g. CPPUnit + "-Wno-c++98-compat-pedantic", # We do different things that violate this, but they could be fixed + "-Wno-global-constructors", # We depend on this for e.g. string constants + "-Wno-disabled-macro-expansion", # Caused due to system headers + "-Wno-c++11-extensions", # We use C++11; turn this off when we use -std=c++11 + "-Wno-long-long", # We use long long + "-Wno-padded", + "-Wno-missing-variable-declarations", # Getting rid of CPPUnit warnings + "-Wno-direct-ivar-access", # Obj-C code warning + ]) + else : + env.Append(CXXFLAGS = ["-Wextra", "-Wall", "-Wnon-virtual-dtor", "-Wundef", "-Wold-style-cast", "-Wno-long-long", "-Woverloaded-virtual", "-Wfloat-equal", "-Wredundant-decls", "-Wno-unknown-pragmas"]) + gccVersion = env.get("CCVERSION", "0.0.0").split(".") + if gccVersion >= ["4", "5", "0"] and not "clang" in env["CC"] : + env.Append(CXXFLAGS = ["-Wlogical-op"]) if not env.get("allow_warnings", False) : env.Append(CXXFLAGS = ["-Werror"]) - gccVersion = env.get("CCVERSION", "0.0.0").split(".") - if gccVersion >= ["4", "5", "0"] and not "clang" in env["CC"] : - env.Append(CXXFLAGS = ["-Wlogical-op"]) - if "clang" in env["CC"] : - env.Append(CXXFLAGS = ["-W#warnings", "-Wc++0x-compat", "-Waddress-of-temporary", "-Wambiguous-member-template", "-Warray-bounds", "-Watomic-properties", "-Wbind-to-temporary-copy", "-Wbuiltin-macro-redefined", "-Wc++-compat", "-Wc++0x-extensions", "-Wcomments", "-Wconditional-uninitialized", "-Wconstant-logical-operand", "-Wdeclaration-after-statement", "-Wdeprecated", "-Wdeprecated-implementations", "-Wdeprecated-writable-strings", "-Wduplicate-method-arg", "-Wempty-body", "-Wendif-labels", "-Wenum-compare", "-Wformat=2", "-Wfour-char-constants", "-Wgnu", "-Wincomplete-implementation", "-Winvalid-noreturn", "-Winvalid-offsetof", "-Winvalid-token-paste", "-Wlocal-type-template-args", "-Wmethod-signatures", "-Wmicrosoft", "-Wmissing-declarations", "-Wnon-pod-varargs", "-Wnull-dereference", "-Wout-of-line-declaration", "-Woverlength-strings", "-Wpacked", "-Wpointer-arith", "-Wpointer-sign", "-Wprotocol", "-Wreadonly-setter-attrs", "-Wselector", "-Wshift-overflow", "-Wshift-sign-overflow", "-Wstrict-selector-match", "-Wsuper-class-method-mismatch", "-Wtautological-compare", "-Wtypedef-redefinition", "-Wundeclared-selector", "-Wunknown-warning-option", "-Wunnamed-type-template-args", "-Wunused-exception-parameter", "-Wunused-member-function", "-Wused-but-marked-unused", "-Wvariadic-macros", "-Wno-c++11-extensions"]) -# To enable: -# "-Wnonfragile-abi2" -> deprecated, is now -Warc-abi i think -# "-Wheader-hygiene" -# "-Wnon-gcc", -# "-Wweak-vtables", -# "-Wlarge-by-value-copy", if env.get("coverage", 0) : assert(env["PLATFORM"] != "win32") @@ -235,14 +286,14 @@ if env.get("coverage", 0) : if env["PLATFORM"] == "win32" : env.Append(LIBS = ["user32", "crypt32", "dnsapi", "iphlpapi", "ws2_32", "wsock32", "Advapi32"]) - env.Append(CCFLAGS = ["/EHsc", "/nologo"]) + env.Append(CCFLAGS = ["/EHsc", "/nologo", "/Zm256"]) env.Append(LINKFLAGS = ["/INCREMENTAL:no", "/NOLOGO"]) if int(env["MSVS_VERSION"].split(".")[0]) < 10 : env["LINKCOM"] = [env["LINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1'] env["SHLINKCOM"] = [env["SHLINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'] -if env["PLATFORM"] == "darwin" and not env["target"] in ["iphone-device", "iphone-simulator", "xcode"] : - env.Append(FRAMEWORKS = ["IOKit", "AppKit", "SystemConfiguration", "Security", "SecurityInterface"]) +if env["PLATFORM"] == "darwin" and not env["target"] in ["iphone-device", "iphone-simulator", "xcode", "android"] : + env["PLATFORM_FLAGS"]["FRAMEWORKS"] += ["IOKit", "AppKit", "SystemConfiguration", "Security", "SecurityInterface"] # Testing env["TEST_TYPE"] = env["test"] @@ -257,13 +308,14 @@ env["TEST_CREATE_LIBRARIES"] = "create_test_libraries" in ARGUMENTS # Packaging env["DIST"] = "dist" in ARGUMENTS or env.GetOption("clean") -for path in ["SWIFT_INSTALLDIR", "SWIFTEN_INSTALLDIR"] : +for path in ["SWIFT_INSTALLDIR", "SWIFTEN_INSTALLDIR", "SLUIFT_INSTALLDIR"] : if ARGUMENTS.get(path, "") : if os.path.isabs(ARGUMENTS[path]) : env[path] = Dir(ARGUMENTS[path]).abspath else : env[path] = Dir("#/" + ARGUMENTS[path]).abspath + ################################################################################ # XCode / iPhone / ... ################################################################################ @@ -281,15 +333,15 @@ if target in ["iphone-device", "iphone-simulator", "xcode"] : env['CXXCOM'] = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM ${SOURCES.abspath}' else : # Hard code values - env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin" + env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin" if target == "iphone-device": env["XCODE_ARCH_FLAGS"] = ["-arch", "armv6", "-arch", "armv7"] sdkPart = "iPhoneOS" else : env["XCODE_ARCH_FLAGS"] = ["-arch", "i386"] sdkPart = "iPhoneSimulator" - sdkVer = "4.3" - env["XCODE_SDKROOT"] = "/Developer/Platforms/" + sdkPart + ".platform/Developer/SDKs/" + sdkPart + sdkVer + ".sdk" + sdkVer = "6.0" + env["XCODE_SDKROOT"] = "/Applications/Xcode.app/Contents/Developer/Platforms/" + sdkPart + ".platform/Developer/SDKs/" + sdkPart + sdkVer + ".sdk" env["IPHONEOS_DEPLOYMENT_TARGET"] = "4.1" # Set the build flags @@ -307,6 +359,17 @@ if target in ["iphone-device", "iphone-simulator", "xcode"] : # Bit of a hack, because BOOST doesn't know the endianness for ARM env.Append(CPPDEFINES = ["_LITTLE_ENDIAN"]) +################################################################################ +# Android +################################################################################ +if target in ["android"] : + env["ENV"]["PATH"] = env["android_toolchain"] + "/bin:" + env["ENV"]["PATH"] + env["CC"] = "arm-linux-androideabi-gcc" + env["CXX"] = "arm-linux-androideabi-g++" + env["RANLIB"] = "arm-linux-androideabi-ranlib" + env.Append(CPPDEFINES = ["ANDROID"]) + env.Append(CPPDEFINES = ["_REENTRANT", "_GLIBCXX__PTHREADS"]) + # CCache if env.get("ccache", False) : env["ENV"]["HOME"] = os.environ["HOME"] diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index a0a6e8d..ce78d03 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -33,7 +33,7 @@ def colorize(command, target, color) : suffix = "\033[0m" return " " + prefix + command + suffix + " " + target -if int(ARGUMENTS.get("V", 0)) == 0: +if int(ARGUMENTS.get("V", 0)) == 0 and not ARGUMENTS.get("dump_trace", False) : env["CCCOMSTR"] = colorize("CC", "$TARGET", "green") env["SHCCCOMSTR"] = colorize("CC", "$TARGET", "green") env["CXXCOMSTR"] = colorize("CXX", "$TARGET", "green") @@ -42,6 +42,7 @@ if int(ARGUMENTS.get("V", 0)) == 0: env["SHLINKCOMSTR"] = colorize("LINK", "$TARGET", "red") env["ARCOMSTR"] = colorize("AR", "$TARGET", "red") env["RANLIBCOMSTR"] = colorize("RANLIB", "$TARGET", "red") + env["PCHCOMSTR"] = colorize("PCH", "$TARGET", "blue") env["QT4_RCCCOMSTR"] = colorize("RCC", "$TARGET", "blue") env["QT4_UICCOMSTR"] = colorize("UIC", "$TARGET", "blue") env["QT4_MOCFROMHCOMSTR"] = colorize("MOC", "$TARGET", "blue") @@ -82,6 +83,12 @@ def CheckPKG(context, name): def CheckVersion(context, library, version, define, header, value) : context.Message("Checking " + library + " version (>= " + version + ") ...") + version = GetVersion(context, define, header) + ok = version >= value + context.Result(ok) + return ok + +def GetVersion(context, define, header, extension = ".c") : ret = context.TryRun(""" #include <%(header)s> #include <stdio.h> @@ -90,10 +97,12 @@ int main(int argc, char* argv[]) { printf("%%d\\n", %(define)s); return 0; } -""" % { "header" : header, "define": define }, ".c") - ok = ret[0] and int(ret[1]) >= value - context.Result(ok) - return ok +""" % { "header" : header, "define": define }, extension) + if ret[0] : + return int(ret[1]) + else : + return -1 + conf = Configure(conf_env) @@ -142,7 +151,7 @@ if env.get("boost_includedir", None) : boost_flags["CPPFLAGS"] = [("-isystem", env["boost_includedir"])] boost_conf_env.MergeFlags(boost_flags) conf = Configure(boost_conf_env) -boostLibs = [("signals", None), ("thread", None), ("regex", None), ("program_options", None), ("filesystem", None), ("system", "system/system_error.hpp"), ("date_time", "date_time/date.hpp")] +boostLibs = [("signals", None), ("thread", None), ("regex", None), ("program_options", None), ("filesystem", None), ("serialization", "archive/text_oarchive.hpp"), ("system", "system/system_error.hpp"), ("date_time", "date_time/date.hpp")] allLibsPresent = True libNames = [] for (lib, header) in boostLibs : @@ -168,6 +177,7 @@ if allLibsPresent : if not conf.CheckCXXHeader("boost/uuid/uuid.hpp") : # FIXME: Remove this workaround when UUID is available in most distros env["BOOST_BUNDLED_UUID_ONLY"] = True + env["BOOST_FLAGS"]["CPPDEFINES"] = ["BOOST_SIGNALS_NO_DEPRECATION_WARNING"] else : env["BOOST_BUNDLED"] = True conf.Finish() @@ -332,27 +342,53 @@ if not env.get("HAVE_ICU", False) and not env.get("HAVE_LIBIDN", False) : env["HAVE_LIBIDN"] = 1 env["LIBIDN_BUNDLED"] = 1 +# Unbound +if env["unbound"] : + env["LDNS_BUNDLED"] = 1 + env["UNBOUND_BUNDLED"] = 1 +else : + env["LDNS_FLAGS"] = {} + env["UNBOUND_FLAGS"] = {} + # LibMiniUPnPc if env["experimental"] : - #libminiupnpc_conf_env = conf_env.Clone() - #conf = Configure(libminiupnpc_conf_env) - #if conf.CheckCHeader("miniupnpc.h") and conf.CheckLib(env["libminiupnpc_libname"]) : - # print "NOT IMPLEMENTED YET" - #else : - env["LIBMINIUPNPC_BUNDLED"] = 1 - #conf.Finish() + libminiupnpc_flags = {"CPPPATH": ["/usr/include/miniupnpc/"]} + libminiupnpc_conf_env = conf_env.Clone() + if env.get("libminiupnpc_libdir", None) : + libminiupnpc_flags["LIBPATH"] = [env["libminiupnpc_libdir"]] + if env.get("libminiupnpc_includedir", None) : + libminiupnpc_flags["CPPPATH"] = [env["libminiupnpc_includedir"]] + libminiupnpc_conf_env.MergeFlags(libminiupnpc_flags) + conf = Configure(libminiupnpc_conf_env) + if conf.CheckCHeader("miniupnpc.h") and conf.CheckLib(env["libminiupnpc_libname"]) and False : + # ^ False because APIs aren't stable + env["HAVE_LIBMINIUPNPC"] = 1 + env["LIBMINIUPNPC_FLAGS"] = { "LIBS": ["miniupnpc"] } + env["LIBMINIUPNPC_FLAGS"].update(libminiupnpc_flags) + else : + env["LIBMINIUPNPC_BUNDLED"] = 1 + conf.Finish() else : env["LIBMINIUPNPC_FLAGS"] = {} # LibNATPMP if env["experimental"] : - #libnatpmp_conf_env = conf_env.Clone() - #conf = Configure(libnatpmp_conf_env) - #if conf.CheckCHeader("natpmp.h") and conf.CheckLib(env["libnatpmp_libname"]) : - # print "NOT IMPLEMENTED YET" - #else : - env["LIBNATPMP_BUNDLED"] = 1 - #conf.Finish() + libnatpmp_flags = {} + libnatpmp_conf_env = conf_env.Clone() + if env.get("libnatpmp_libdir", None) : + libnatpmp_flags["LIBPATH"] = [env["libnatpmp_libdir"]] + if env.get("libnatpmp_includedir", None) : + libnatpmp_flags["CPPPATH"] = [env["libnatpmp_includedir"]] + libnatpmp_conf_env.MergeFlags(libnatpmp_flags) + conf = Configure(libnatpmp_conf_env) + if conf.CheckCHeader("natpmp.h") and conf.CheckLib(env["libnatpmp_libname"]) and False: + # ^ False because APIs aren't stable + env["HAVE_LIBNATPMP"] = 1 + env["LIBNATPMP_FLAGS"] = { "LIBS": ["natpmp"] } + env["LIBNATPMP_FLAGS"].update(libnatpmp_flags) + else : + env["LIBNATPMP_BUNDLED"] = 1 + conf.Finish() else : env["LIBNATPMP_FLAGS"] = {} @@ -372,14 +408,32 @@ if env["experimental"] : env["SQLITE_FLAGS"].update(sqlite_flags) else : env["SQLITE_BUNDLED"] = 1 - env["SQLITE_ASYNC_BUNDLED"] = 1 conf.Finish() else : env["SQLITE_FLAGS"] = {} # Lua -env["LUA_BUNDLED"] = 1 +lua_conf_env = conf_env.Clone() +lua_flags = {} +if env.get("lua_libdir", None) : + lua_flags["LIBPATH"] = [env["lua_libdir"]] +if env.get("lua_includedir", None) : + lua_flags["CPPPATH"] = [env["lua_includedir"]] +lua_conf_env.MergeFlags(lua_flags) +conf = Configure(lua_conf_env) +if not env.get("lua_force_bundled", False) and conf.CheckCXXHeader("lua.hpp") and conf.CheckLib(env["lua_libname"]) : + env["HAVE_LUA"] = 1 + env["LUA_FLAGS"] = { "LIBS": [env["lua_libname"]] } + lua_version = GetVersion(conf, "LUA_VERSION_NUM", "lua.h") + if lua_version > 0 : + env["LUA_FLAGS"]["LUA_VERSION"] = str(lua_version // 100) + "." + str(lua_version % 100) + else : + print "Warning: Unable to determine Lua version. Not installing Lua libraries." + env["LUA_FLAGS"].update(lua_flags) +else : + env["LUA_BUNDLED"] = 1 +conf.Finish() # Readline conf = Configure(conf_env) @@ -409,43 +463,60 @@ if env["qt"] : # OpenSSL openssl_env = conf_env.Clone() -use_openssl = bool(env["openssl"]) -openssl_prefix = env["openssl"] if isinstance(env["openssl"], str) else "" -openssl_flags = {} -if openssl_prefix : - openssl_flags = { "CPPPATH": [os.path.join(openssl_prefix, "include")] } - if env["PLATFORM"] == "win32" : - openssl_flags["LIBPATH"] = [os.path.join(openssl_prefix, "lib", "VC")] - env["OPENSSL_DIR"] = openssl_prefix - else : - openssl_flags["LIBPATH"] = [os.path.join(openssl_prefix, "lib")] - openssl_env.MergeFlags(openssl_flags) - -openssl_conf = Configure(openssl_env) -if use_openssl and openssl_conf.CheckCHeader("openssl/ssl.h") : - env["HAVE_OPENSSL"] = 1 - env["OPENSSL_FLAGS"] = openssl_flags - if env["PLATFORM"] == "win32" : - env["OPENSSL_FLAGS"]["LIBS"] = ["libeay32MD", "ssleay32MD"] - else: - env["OPENSSL_FLAGS"]["LIBS"] = ["ssl", "crypto"] - if env["PLATFORM"] == "darwin" : - if platform.mac_ver()[0].startswith("10.5") : - env["OPENSSL_FLAGS"]["FRAMEWORKS"] = ["Security"] -elif env["target"] in ("iphone-device", "iphone-simulator", "xcode") : +if env.get("openssl_force_bundled", False) or env["target"] in ("iphone-device", "iphone-simulator", "xcode", "android") : env["OPENSSL_BUNDLED"] = True env["HAVE_OPENSSL"] = True else : - env["OPENSSL_FLAGS"] = {} - if env["PLATFORM"] == "win32" : - env["HAVE_SCHANNEL"] = True - # If we're compiling for Windows and OpenSSL isn't being used, use Schannel - env.Append(LIBS = ["secur32"]) - -openssl_conf.Finish() + use_openssl = bool(env["openssl"]) + openssl_prefix = env["openssl"] if isinstance(env["openssl"], str) else "" + openssl_flags = {} + if openssl_prefix : + openssl_flags = { "CPPPATH": [os.path.join(openssl_prefix, "include")] } + if env["PLATFORM"] == "win32" : + openssl_flags["LIBPATH"] = [os.path.join(openssl_prefix, "lib", "VC")] + env["OPENSSL_DIR"] = openssl_prefix + else : + openssl_flags["LIBPATH"] = [os.path.join(openssl_prefix, "lib")] + openssl_env.MergeFlags(openssl_flags) + + openssl_conf = Configure(openssl_env) + if use_openssl and openssl_conf.CheckCHeader("openssl/ssl.h") : + env["HAVE_OPENSSL"] = 1 + env["OPENSSL_FLAGS"] = openssl_flags + if env["PLATFORM"] == "win32" : + env["OPENSSL_FLAGS"]["LIBS"] = ["libeay32MD", "ssleay32MD"] + else: + env["OPENSSL_FLAGS"]["LIBS"] = ["ssl", "crypto"] + if env["PLATFORM"] == "darwin" : + if platform.mac_ver()[0].startswith("10.5") : + env["OPENSSL_FLAGS"]["FRAMEWORKS"] = ["Security"] + else : + env["OPENSSL_FLAGS"] = {} + if env["PLATFORM"] == "win32" : + env["HAVE_SCHANNEL"] = True + # If we're compiling for Windows and OpenSSL isn't being used, use Schannel + env.Append(LIBS = ["secur32"]) + + openssl_conf.Finish() + +#Hunspell +hunspell_env = conf_env.Clone() +hunspell_prefix = env["hunspell"] if isinstance(env.get("hunspell", False), str) else "" +hunspell_flags = {} +if hunspell_prefix : + hunspell_flags = {"CPPPATH":[os.path.join(hunspell_prefix, "include")], "LIBPATH":[os.path.join(hunspell_prefix, "lib")]} +hunspell_env.MergeFlags(hunspell_flags) + +env["HAVE_HUNSPELL"] = 0; +hunspell_conf = Configure(hunspell_env) +if hunspell_conf.CheckCXXHeader("hunspell/hunspell.hxx") and hunspell_conf.CheckLib("hunspell") : + env["HAVE_HUNSPELL"] = 1 + hunspell_flags["LIBS"] = ["hunspell"] + env["HUNSPELL_FLAGS"] = hunspell_flags +hunspell_conf.Finish() # Bonjour -if env["PLATFORM"] == "darwin" : +if env["PLATFORM"] == "darwin" and env["target"] == "native" : env["HAVE_BONJOUR"] = 1 elif env.get("bonjour", False) : bonjour_env = conf_env.Clone() @@ -524,18 +595,23 @@ else : # Project files ################################################################################ -# Build tools -env.SConscript(dirs = ["#/BuildTools/CLang"]) +if ARGUMENTS.get("dump_trace", False) : + env.SetOption("no_exec", True) + env["TEST"] = True + env["BOOST_BUILD_BCP"] = True + env.Decider(lambda x, y, z : True) + SCons.Node.Python.Value.changed_since_last_build = (lambda x, y, z: True) # Modules modules = [] -for dir in os.listdir(Dir("#/3rdParty").abspath) : - full_dir = os.path.join(Dir("#/3rdParty").abspath, dir) - if not os.path.isdir(full_dir) : - continue - sconscript = os.path.join(full_dir, "SConscript") - if os.path.isfile(sconscript) : - modules.append("3rdParty/" + dir) +if os.path.isdir(Dir("#/3rdParty").abspath) : + for dir in os.listdir(Dir("#/3rdParty").abspath) : + full_dir = os.path.join(Dir("#/3rdParty").abspath, dir) + if not os.path.isdir(full_dir) : + continue + sconscript = os.path.join(full_dir, "SConscript") + if os.path.isfile(sconscript) : + modules.append("3rdParty/" + dir) for dir in os.listdir(Dir("#").abspath) : full_dir = os.path.join(Dir("#").abspath, dir) if not os.path.isdir(full_dir) : @@ -544,9 +620,13 @@ for dir in os.listdir(Dir("#").abspath) : if os.path.isfile(sconscript) : modules.append(dir) +# QA comes last +modules.remove("QA") +modules.append("QA") + # Flags env["PROJECTS"] = [m for m in modules if m not in ["Documentation", "QA", "SwifTools"] and not m.startswith("3rdParty")] -for stage in ["flags", "build", "test"] : +for stage in ["flags", "build"] : env["SCONS_STAGE"] = stage SConscript(dirs = map(lambda x : root + "/" + x, modules)) diff --git a/BuildTools/SCons/Tools/Flags.py b/BuildTools/SCons/Tools/Flags.py index 13fbb32..c130faf 100644 --- a/BuildTools/SCons/Tools/Flags.py +++ b/BuildTools/SCons/Tools/Flags.py @@ -3,7 +3,10 @@ import SCons.Util def generate(env) : def useFlags(env, flags) : for flag in flags : - env[flag] = env.get(flag, []) + flags[flag] + if flag in env : + env[flag] = env[flag] + flags[flag] + else : + env[flag] = flags[flag] env.AddMethod(useFlags, "UseFlags") def exists(env) : diff --git a/BuildTools/SCons/Tools/Test.py b/BuildTools/SCons/Tools/Test.py index c52f448..95fcce9 100644 --- a/BuildTools/SCons/Tools/Test.py +++ b/BuildTools/SCons/Tools/Test.py @@ -19,13 +19,24 @@ def generate(env) : for i in ["HOME", "USERPROFILE", "APPDATA"]: if os.environ.get(i, "") : test_env["ENV"][i] = os.environ[i] - if test_env["PLATFORM"] == "darwin" : - test_env["ENV"]["DYLD_FALLBACK_LIBRARY_PATH"] = ":".join(map(lambda x : str(x), test_env.get("LIBPATH", []))) - elif test_env["PLATFORM"] == "win32" : - test_env["ENV"]["PATH"] = ";".join(map(lambda x : str(x), test_env.get("LIBRUNPATH", []))) + ";" + test_env["ENV"]["PATH"] + if env["target"] == "android" : + test_env["ENV"]["PATH"] = env["android_sdk_bin"] + ";" + test_env["ENV"]["PATH"] + else : + if test_env["PLATFORM"] == "darwin" : + test_env["ENV"]["DYLD_FALLBACK_LIBRARY_PATH"] = ":".join(map(lambda x : str(x), test_env.get("LIBPATH", []))) + elif test_env["PLATFORM"] == "win32" : + test_env["ENV"]["PATH"] = ";".join(map(lambda x : str(x), test_env.get("LIBRUNPATH", []))) + ";" + test_env["ENV"]["PATH"] + # Run the test - test_env.Command("**dummy**", target, + if env["target"] == "android": + exec_name = os.path.basename(cmd) + test_env.Command("**dummy**", target, SCons.Action.Action( + ["adb shell mount -o rw,remount /system", + "adb push " + cmd + " /system/bin/" + exec_name, + "adb shell SWIFT_CLIENTTEST_JID=\"" + os.getenv("SWIFT_CLIENTTEST_JID") + "\" SWIFT_CLIENTTEST_PASS=\"" + os.getenv("SWIFT_CLIENTTEST_PASS") + "\" " + env.get("TEST_RUNNER", "") + "/system/bin/" + exec_name], cmdstr = "$TESTCOMSTR")) + else : + test_env.Command("**dummy**", target, SCons.Action.Action(ignore_prefix + env.get("TEST_RUNNER", "") + cmd + " " + params, cmdstr = "$TESTCOMSTR")) def registerScriptTests(env, scripts, name, type) : diff --git a/BuildTools/SCons/Tools/WindowsBundle.py b/BuildTools/SCons/Tools/WindowsBundle.py index c3c77aa..2915141 100644 --- a/BuildTools/SCons/Tools/WindowsBundle.py +++ b/BuildTools/SCons/Tools/WindowsBundle.py @@ -1,12 +1,16 @@ import SCons.Util, os def generate(env) : - def createWindowsBundle(env, bundle, resources = {}, qtimageformats = [], qtlibs = []) : + def createWindowsBundle(env, bundle, resources = {}, qtplugins = {}, qtlibs = [], qtversion = '4') : all_files = [] all_files += env.Install(bundle, bundle + ".exe") for lib in qtlibs : all_files += env.Install(bundle, os.path.join(env["QTDIR"], "bin", lib + ".dll")) - all_files += env.Install(os.path.join(bundle, "imageformats"), [os.path.join(env["QTDIR"], "plugins", "imageformats", "q" + codec + "4.dll") for codec in qtimageformats]) + plugins_suffix = '4' + if qtversion == '5' : + plugins_suffix = '' + for plugin_type in qtplugins: + all_files += env.Install(os.path.join(bundle, plugin_type), [os.path.join(env["QTDIR"], "plugins", plugin_type, "q" + plugin + plugins_suffix + ".dll") for plugin in qtplugins[plugin_type]]) for dir, resourceFiles in resources.items() : for resource in resourceFiles : diff --git a/BuildTools/SCons/Tools/qt4.py b/BuildTools/SCons/Tools/qt4.py index 671fd08..02701e7 100644 --- a/BuildTools/SCons/Tools/qt4.py +++ b/BuildTools/SCons/Tools/qt4.py @@ -286,9 +286,9 @@ def generate(env): # Commands for the qt support ... QT4_UICCOM = '$QT4_UIC $QT4_UICFLAGS -o $TARGET $SOURCE', - # FIXME: The -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED flag is a hack to work - # around an issue in Qt - # See https://bugreports.qt-project.org/browse/QTBUG-22829 + # FIXME: The -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED flag is a hack to work + # around an issue in Qt + # See https://bugreports.qt-project.org/browse/QTBUG-22829 QT4_MOCFROMHCOM = '$QT4_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED $QT4_MOCFROMHFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE', QT4_MOCFROMCXXCOM = [ '$QT4_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED $QT4_MOCFROMCXXFLAGS $QT4_MOCINCFLAGS -o $TARGET $SOURCE', @@ -395,7 +395,7 @@ def generate(env): # TODO: Does dbusxml2cpp need an adapter env.AddMethod(enable_modules, "EnableQt4Modules") -def enable_modules(self, modules, debug=False, crosscompiling=False) : +def enable_modules(self, modules, debug=False, crosscompiling=False, version='4') : import sys validModules = [ @@ -420,6 +420,11 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) : 'QtWebKit', 'QtHelp', 'QtScript', + + # Qt5 modules + 'QtWidgets', + 'QtMultimedia', + 'QtWebKitWidgets', ] staticModules = [ 'QtUiTools', @@ -440,6 +445,8 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) : 'QtXml' : ['QT_XML_LIB'], 'QtOpenGL' : ['QT_OPENGL_LIB'], 'QtGui' : ['QT_GUI_LIB'], + 'QtWidgets' : ['QT_WIDGETS_LIB'], + 'QtWebKitWidgets' : [], 'QtNetwork' : ['QT_NETWORK_LIB'], 'QtCore' : ['QT_CORE_LIB'], } @@ -450,7 +457,8 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) : if sys.platform.startswith("linux") and not crosscompiling : if debug : debugSuffix = '_debug' - self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include", "phonon")]) + if version == '4' : + self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include", "phonon")]) for module in modules : self.AppendUnique(LIBS=[module+debugSuffix]) self.AppendUnique(LIBPATH=[os.path.join("$QTDIR","lib")]) @@ -471,12 +479,17 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) : self.AppendUnique(CPPPATH=[os.path.join("$QTDIR","include","QtAssistant")]) modules.remove("QtAssistant") modules.append("QtAssistantClient") - # FIXME: Phonon Hack - self.AppendUnique(LIBS=['phonon'+debugSuffix+'4']) - self.AppendUnique(LIBS=[lib+debugSuffix+'4' for lib in modules if lib not in staticModules]) + if version == '4' : + # FIXME: Phonon Hack + self.AppendUnique(LIBS=['phonon'+debugSuffix+version]) + self.AppendUnique(LIBS=[lib+debugSuffix+version for lib in modules if lib not in staticModules]) + else : + self.AppendUnique(LIBS=[lib.replace('Qt', 'Qt5') + debugSuffix for lib in modules if lib not in staticModules]) self.PrependUnique(LIBS=[lib+debugSuffix for lib in modules if lib in staticModules]) if 'QtOpenGL' in modules: self.AppendUnique(LIBS=['opengl32']) + elif version == '5' : + self.Append(CPPDEFINES = ["QT_NO_OPENGL"]) self.AppendUnique(CPPPATH=[ '$QTDIR/include/']) self.AppendUnique(CPPPATH=[ '$QTDIR/include/'+module for module in modules]) if crosscompiling : @@ -498,7 +511,8 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) : self.AppendUnique(LINKFLAGS="-L$QTDIR/lib") #TODO clean! # FIXME: Phonon Hack - self.Append(LINKFLAGS=['-framework', "phonon"]) + if version == '4' : + self.Append(LINKFLAGS=['-framework', "phonon"]) for module in modules : if module in staticModules : @@ -506,9 +520,9 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) : self.AppendUnique(LIBPATH=[os.path.join("$QTDIR","lib")]) else : if len(self["QTDIR"]) > 0 : - self.Append(CPPFLAGS = ["-I" + os.path.join("$QTDIR", "lib", module + ".framework", "Versions", "4", "Headers")]) + self.Append(CPPFLAGS = ["-I" + os.path.join("$QTDIR", "lib", module + ".framework", "Versions", version, "Headers")]) else : - self.Append(CPPFLAGS = ["-I" + os.path.join("/Library/Frameworks", module + ".framework", "Versions", "4", "Headers")]) + self.Append(CPPFLAGS = ["-I" + os.path.join("/Library/Frameworks", module + ".framework", "Versions", version, "Headers")]) self.Append(LINKFLAGS=['-framework', module]) if 'QtOpenGL' in modules: self.AppendUnique(LINKFLAGS="-F/System/Library/Frameworks") diff --git a/BuildTools/scons2ninja.py b/BuildTools/scons2ninja.py new file mode 100755 index 0000000..2666ae6 --- /dev/null +++ b/BuildTools/scons2ninja.py @@ -0,0 +1,615 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +################################################################################ +# +# scons2ninja: A script to create a Ninja build file from SCons. +# +# Copyright (c) 2013 Remko Tronçon +# Licensed under the simplified BSD license. +# See COPYING for details. +# +################################################################################ + +import re, os, os.path, subprocess, sys, fnmatch, shlex + +################################################################################ +# Helper methods & variables +################################################################################ + +SCRIPT = sys.argv[0] +SCONS_ARGS = ' '.join(sys.argv[1:]) + +# TODO: Make this a tool-specific map +BINARY_FLAGS = ["-framework", "-arch", "-x", "--output-format", "-isystem", "-include"] + +if sys.platform == 'win32' : + LIB_PREFIX = "" + LIB_SUFFIX = "" + EXE_SUFFIX = ".exe" +else : + LIB_PREFIX = "lib" + LIB_SUFFIX = ".a" + EXE_SUFFIX = "" + +def is_regexp(x) : + return 'match' in dir(x) + +def is_list(l) : + return type(l) is list + +def escape(s) : + return s.replace(' ', '$ ').replace(':', '$:') + +def quote_spaces(s) : + if ' ' in s : + return '"' + s + '"' + else : + return s + +def to_list(l) : + if not l : + return [] + if is_list(l) : + return l + return [l] + +def partition(l, f) : + x = [] + y = [] + for v in l : + if f(v) : + x.append(v) + else : + y.append(v) + return (x, y) + +def get_unary_flags(prefix, flags) : + return [x[len(prefix):] for x in flags if x.lower().startswith(prefix.lower())] + +def extract_unary_flags(prefix, flags) : + f1, f2 = partition(flags, lambda x : x.lower().startswith(prefix.lower())) + return ([f[len(prefix):] for f in f1], f2) + +def extract_unary_flag(prefix, flags) : + flag, flags = extract_unary_flags(prefix, flags) + return (flag[0], flags) + +def extract_binary_flag(prefix, flags) : + i = flags.index(prefix) + flag = flags[i + 1] + del flags[i] + del flags[i] + return (flag, flags) + +def get_non_flags(flags) : + skip = False + result = [] + for f in flags : + if skip : + skip = False + elif f in BINARY_FLAGS : + skip = True + elif not f.startswith("/") and not f.startswith("-") : + result.append(f) + return result + +def extract_non_flags(flags) : + non_flags = get_non_flags(flags) + return (non_flags, filter(lambda x : x not in non_flags, flags)) + +def get_dependencies(target, build_targets) : + result = [] + queue = list(dependencies.get(target, [])) + while len(queue) > 0 : + n = queue.pop() + # Filter out Value() results + if n in build_targets or os.path.exists(n) : + result.append(n) + queue += list(dependencies.get(n, [])) + return result + +def get_built_libs(libs, libpaths, outputs) : + canonical_outputs = [os.path.abspath(p) for p in outputs] + result = [] + for libpath in libpaths : + for lib in libs : + lib_libpath = os.path.join(libpath, LIB_PREFIX + lib + LIB_SUFFIX) + if os.path.abspath(lib_libpath) in canonical_outputs : + result.append(lib_libpath) + return result + +def parse_tool_command(line) : + command = shlex.split(line) + flags = command[1:] + tool = os.path.splitext(os.path.basename(command[0]))[0] + if tool.startswith('clang++') or tool.startswith('g++') : + tool = "cxx" + elif tool.startswith('clang') or tool.startswith('gcc') : + tool = "cc" + if tool in ["cc", "cxx"] and not "-c" in flags : + tool = "glink" + tool = tool.replace('-qt4', '') + return tool, command, flags + +def rglob(pattern, root = '.') : + return [os.path.join(path, f) for path, dirs, files in os.walk(root) for f in fnmatch.filter(files, pattern)] + +################################################################################ +# Helper for building Ninja files +################################################################################ + +class NinjaBuilder : + def __init__(self) : + self._header = "" + self.variables = "" + self.rules = "" + self._build = "" + self.pools = "" + self._flags = {} + self.targets = [] + + def header(self, text) : + self._header += text + "\n" + + def rule(self, name, **kwargs) : + self.rules += "rule " + name + "\n" + for k, v in kwargs.iteritems() : + self.rules += " " + str(k) + " = " + str(v) + "\n" + self.rules += "\n" + + def pool(self, name, **kwargs) : + self.pools += "pool " + name + "\n" + for k, v in kwargs.iteritems() : + self.pools += " " + str(k) + " = " + str(v) + "\n" + self.pools += "\n" + + def variable(self, name, value) : + self.variables += str(name) + " = " + str(value) + "\n" + + def build(self, target, rule, sources = None, **kwargs) : + self._build += "build " + self.to_string(target) + ": " + rule + if sources : + self._build += " " + self.to_string(sources) + if 'deps' in kwargs and kwargs['deps'] : + self._build += " | " + self.to_string(kwargs["deps"]) + if 'order_deps' in kwargs : + self._build += " || " + self.to_string(kwargs['order_deps']) + self._build += "\n" + for var, value in kwargs.iteritems() : + if var in ['deps', 'order_deps'] : + continue + value = self.to_string(value, quote = True) + if var.endswith("flags") : + value = self.get_flags_variable(var, value) + self._build += " " + var + " = " + value + "\n" + self.targets += to_list(target) + + def header_targets(self) : + return [x for x in self.targets if x.endswith('.h') or x.endswith('.hh')] + + def serialize(self) : + result = "" + result += self._header + "\n" + result += self.variables + "\n" + for prefix in self._flags.values() : + for k, v in prefix.iteritems() : + result += v + " = " + k + "\n" + result += "\n" + result += self.pools + "\n" + result += self.rules + "\n" + result += self._build + "\n" + return result + + def to_string(self, lst, quote = False) : + if is_list(lst) : + if quote : + return ' '.join([quote_spaces(x) for x in lst]) + else : + return ' '.join([escape(x) for x in lst]) + if is_regexp(lst) : + return ' '.join([escape(x) for x in self.targets if lst.match(x)]) + return escape(lst) + + def get_flags_variable(self, flags_type, flags) : + if len(flags) == 0 : + return '' + if flags_type not in self._flags : + self._flags[flags_type] = {} + type_flags = self._flags[flags_type] + if flags not in type_flags : + type_flags[flags] = flags_type + "_" + str(len(type_flags)) + return "$" + type_flags[flags] + + +################################################################################ +# Configuration +################################################################################ + +ninja_post = [] +scons_cmd = "scons" +scons_dependencies = ['SConstruct'] + rglob('SConscript') + +def ninja_custom_command(ninja, line) : + return False + +CONFIGURATION_FILE = '.scons2ninja.conf' +execfile(CONFIGURATION_FILE) + +scons_dependencies = [os.path.normpath(x) for x in scons_dependencies] + + +################################################################################ +# Rules +################################################################################ + +ninja = NinjaBuilder() + +ninja.pool('scons_pool', depth = 1) + +if sys.platform == 'win32' : + ninja.rule('cl', + deps = 'msvc', + command = '$cl /showIncludes $clflags -c $in /Fo$out', + description = 'CXX $out') + + ninja.rule('link', + command = '$link $in $linkflags $libs /out:$out', + description = 'LINK $out') + + ninja.rule('link_mt', + command = '$link $in $linkflags $libs /out:$out ; $mt $mtflags', + description = 'LINK $out') + + ninja.rule('lib', + command = '$lib $libflags /out:$out $in', + description = 'AR $out') + + ninja.rule('rc', + command = '$rc $rcflags /Fo$out $in', + description = 'RC $out') + + # SCons doesn't touch files if they didn't change, which makes + # ninja rebuild the file over and over again. There's no touch on Windows :( + # Could implement it with a script, but for now, delete the file if + # this problem occurs. I'll fix it if it occurs too much. + ninja.rule('scons', + command = scons_cmd + " ${scons_args} $out", + pool = 'scons_pool', + description = 'GEN $out') + + ninja.rule('install', command = 'cmd /c copy $in $out') + ninja.rule('run', command = '$in') +else : + ninja.rule('cxx', + deps = 'gcc', + depfile = '$out.d', + command = '$cxx -MMD -MF $out.d $cxxflags -c $in -o $out', + description = 'CXX $out') + + ninja.rule('cc', + deps = 'gcc', + depfile = '$out.d', + command = '$cc -MMD -MF $out.d $ccflags -c $in -o $out', + description = 'CC $out') + + ninja.rule('link', + command = '$glink -o $out $in $linkflags', + description = 'LINK $out') + + ninja.rule('ar', + command = 'ar $arflags $out $in && ranlib $out', + description = 'AR $out') + + # SCons doesn't touch files if they didn't change, which makes + # ninja rebuild the file over and over again. Touching solves this. + ninja.rule('scons', + command = scons_cmd + " $out && touch $out", + pool = 'scons_pool', + description = 'GEN $out') + + ninja.rule('install', command = 'install $in $out') + ninja.rule('run', command = './$in') + + +ninja.rule('moc', + command = '$moc $mocflags -o $out $in', + description = 'MOC $out') + +ninja.rule('rcc', + command = '$rcc $rccflags -name $name -o $out $in', + description = 'RCC $out') + +ninja.rule('uic', + command = '$uic $uicflags -o $out $in', + description = 'UIC $out') + +ninja.rule('lrelease', + command = '$lrelease $lreleaseflags $in -qm $out', + description = 'LRELEASE $out') + +ninja.rule('ibtool', + command = '$ibtool $ibtoolflags --compile $out $in', + description = 'IBTOOL $out') + +ninja.rule('dsymutil', + command = '$dsymutil $dsymutilflags -o $out $in', + description = 'DSYMUTIL $out') + +ninja.rule('generator', + command = "python " + SCRIPT + " ${scons_args}", + depfile = ".scons2ninja.deps", + pool = 'scons_pool', + generator = '1', + description = 'Regenerating build.ninja') + + +################################################################################ +# Build Statements +################################################################################ + +scons_generate_cmd = scons_cmd + " " + SCONS_ARGS + " --tree=all,prune dump_trace=1" +#scons_generate_cmd = 'cmd /c type scons2ninja.in' +#scons_generate_cmd = 'cat scons2ninja.in' + +# Pass 1: Parse dependencies (and prefilter some build rules) +build_lines = [] +dependencies = {} +mtflags = {} +previous_file = None +f = subprocess.Popen(scons_generate_cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True) +stage = 'preamble' +skip_nth_line = -1 +stack = ['.'] +for line in f.stdout.readlines() : + line = line.rstrip() + + # Skip lines if requested from previous command + if skip_nth_line >= 0 : + skip_nth_line -= 1 + if skip_nth_line == 0 : + continue + + if line.startswith('scons: done building targets') : + break + + if stage == "preamble" : + # Pass all lines from the SCons configuration step to output + if re.match("^scons: Building targets ...", line) : + stage = "build" + else : + print line + + elif stage == "build" : + if line.startswith('+-') : + stage = "dependencies" + elif re.match("^Using tempfile", line) : + # Ignore response files from MSVS + skip_nth_line = 2 + else : + build_lines.append(line) + + # Already detect targets that will need 'mt' + tool, _, flags = parse_tool_command(line) + if tool == 'mt' : + target = get_unary_flags("-outputresource:", flags)[0] + target = target[0:target.index(';')] + mtflags[target] = flags + + elif stage == "dependencies" : + if not re.match('^[\s|]+\+\-', line) : + # Work around bug in SCons that splits output over multiple lines + continue + + level = line.index('+-') / 2 + filename = line[level*2+2:] + if filename.startswith('[') : + filename = filename[1:-1] + + # Check if we use the 'fixed' format which escapes filenamenames + if filename.startswith('\'') and filename.endswith('\'') : + filename = eval(filename) + + if level < len(stack) : + stack = stack[0:level] + elif level > len(stack) : + if level != len(stack) + 1 : + raise Exception("Internal Error" ) + stack.append(previous_filename) + + # Skip absolute paths + if not os.path.isabs(filename) : + target = stack[-1] + if target not in dependencies : + dependencies[target] = [] + dependencies[target].append(filename) + previous_filename = filename + +if f.wait() != 0 : + print "Error calling '" + scons_generate_cmd + "'" + print f.stderr.read() + exit(-1) + +# Pass 2: Parse build rules +tools = {} +for line in build_lines : + # Custom python function + m = re.match('^(\w+)\(\[([^\]]*)\]', line) + if m : + out = [x[1:-1] for x in m.group(2).split(',')] + for x in out : + # 'Note' = To be more correct, deps should also include $scons_dependencies, + # but this regenerates a bit too often, so leaving it out for now. + ninja.build(x, 'scons', None, deps = sorted(get_dependencies(x, ninja.targets))) + continue + + + # TextFile + m = re.match("^Creating '([^']+)'", line) + if m : + out = m.group(1) + # Note: To be more correct, deps should also include $scons_dependencies, + # but this regenerates a bit too often, so leaving it out for now. + ninja.build(out, 'scons', None, deps = sorted(get_dependencies(out, ninja.targets))) + continue + + # Install + m = re.match('^Install file: "(.*)" as "(.*)"', line) + if m : + ninja.build(m.group(2), 'install', m.group(1)) + continue + + m = re.match('^Install directory: "(.*)" as "(.*)"', line) + if m : + for source in rglob('*', m.group(1)) : + if os.path.isdir(source) : + continue + target = os.path.join(m.group(2), os.path.relpath(source, m.group(1))) + ninja.build(target, 'install', source) + continue + + # Tools + tool, command, flags = parse_tool_command(line) + tools[tool] = command[0] + + ############################################################ + # clang/gcc tools + ############################################################ + + if tool == 'cc': + out, flags = extract_binary_flag("-o", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'cc', files, order_deps = '_generated_headers', ccflags = flags) + + elif tool == 'cxx': + out, flags = extract_binary_flag("-o", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'cxx', files, order_deps = '_generated_headers', cxxflags = flags) + + elif tool == 'glink': + out, flags = extract_binary_flag("-o", flags) + files, flags = extract_non_flags(flags) + libs = get_unary_flags('-l', flags) + libpaths = get_unary_flags("-L", flags) + deps = get_built_libs(libs, libpaths, ninja.targets) + ninja.build(out, 'link', files, deps = sorted(deps), linkflags = flags) + + elif tool == 'ar': + objects, flags = partition(flags, lambda x: x.endswith('.o')) + libs, flags = partition(flags, lambda x: x.endswith('.a')) + out = libs[0] + ninja.build(out, 'ar', objects, arflags = flags) + + elif tool == 'ranlib': + pass + + + ############################################################ + # MSVC tools + ############################################################ + + elif tool == 'cl': + out, flags = extract_unary_flag("/Fo", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'cl', files, order_deps = '_generated_headers', clflags = flags) + + elif tool == 'lib': + out, flags = extract_unary_flag("/out:", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'lib', files, libflags = flags) + + elif tool == 'link': + objects, flags = partition(flags, lambda x: x.endswith('.obj') or x.endswith('.res')) + out, flags = extract_unary_flag("/out:", flags) + libs, flags = partition(flags, lambda x: not x.startswith("/") and x.endswith(".lib")) + libpaths = get_unary_flags("/libpath:", flags) + deps = get_built_libs(libs, libpaths, ninja.targets) + if out in mtflags : + ninja.build(out, 'link_mt', objects, deps = sorted(deps), + libs = libs, linkflags = flags, mtflags = mtflags[out]) + else : + ninja.build(out, 'link', objects, deps = sorted(deps), + libs = libs, linkflags = flags) + + elif tool == 'rc': + out, flags = extract_unary_flag("/fo", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'rc', files[0], order_deps = '_generated_headers', rcflags = flags) + + elif tool == 'mt': + # Already handled + pass + + ############################################################ + # Qt tools + ############################################################ + + elif tool == 'moc': + out, flags = extract_binary_flag("-o", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'moc', files, mocflags = flags) + + elif tool == 'uic': + out, flags = extract_binary_flag("-o", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'uic', files, uicflags = flags) + + elif tool == 'lrelease': + out, flags = extract_binary_flag("-qm", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'lrelease', files, lreleaseflags = flags) + + elif tool == 'rcc': + out, flags = extract_binary_flag("-o", flags) + name, flags = extract_binary_flag("-name", flags) + files, flags = extract_non_flags(flags) + deps = list(set(get_dependencies(out, ninja.targets)) - set(files)) + ninja.build(out, 'rcc', files, deps = sorted(deps), name = name, rccflags = flags) + + ############################################################ + # OS X tools + ############################################################ + + elif tool == 'ibtool': + out, flags = extract_binary_flag("--compile", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'ibtool', files, ibtoolflags = flags) + + elif tool == 'dsymutil': + out, flags = extract_binary_flag("-o", flags) + files, flags = extract_non_flags(flags) + ninja.build(out, 'dsymutil', files, dsymutilflags = flags) + + elif not ninja_custom_command(ninja, line) : + raise Exception("Unknown tool: '" + line + "'") + + +# Phony target for all generated headers, used as an order-only depency from all C/C++ sources +ninja.build('_generated_headers', 'phony', ninja.header_targets()) + +# Regenerate build.ninja file +ninja.build('build.ninja', 'generator', [], deps = [SCRIPT, CONFIGURATION_FILE]) + +# Header & variables +ninja.header("# This file is generated by " + SCRIPT) +ninja.variable("ninja_required_version", "1.3") +ninja.variable("scons_args", SCONS_ARGS) +for k, v in tools.iteritems() : + ninja.variable(k, v) + +# Extra customizations +if 'ninja_post' in dir() : + ninja_post(ninja) + + +################################################################################ +# Result +################################################################################ + +f = open(".scons2ninja.deps", "w") +f.write("build.ninja: " + " ".join([d for d in scons_dependencies if os.path.exists(d)]) + "\n") +f.close() + +f = open("build.ninja", "w") +f.write(ninja.serialize()) +f.close() |