]> git.tdb.fi Git - builder.git/commitdiff
Collapse the language-specific compilers into a single class
authorMikko Rasa <tdb@tdb.fi>
Fri, 1 Dec 2017 07:48:37 +0000 (09:48 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 1 Dec 2017 09:01:31 +0000 (11:01 +0200)
There's very little differences between languages of the C family, but on
the other hand different platform SDKs need their own tweaks.  It makes
more sense to abstract by platform rather than by language here.

24 files changed:
source/androidccompiler.cpp [deleted file]
source/androidccompiler.h [deleted file]
source/androidcompiler.cpp [new file with mode: 0644]
source/androidcompiler.h [new file with mode: 0644]
source/androidcxxcompiler.cpp [deleted file]
source/androidcxxcompiler.h [deleted file]
source/androidtools.cpp
source/clangccompiler.cpp [deleted file]
source/clangccompiler.h [deleted file]
source/clangcompiler.cpp [new file with mode: 0644]
source/clangcompiler.h [new file with mode: 0644]
source/clangcxxcompiler.cpp [deleted file]
source/clangcxxcompiler.h [deleted file]
source/clangobjccompiler.cpp [deleted file]
source/clangobjccompiler.h [deleted file]
source/gnuccompiler.cpp [deleted file]
source/gnuccompiler.h [deleted file]
source/gnucompiler.cpp
source/gnucompiler.h
source/gnucxxcompiler.cpp [deleted file]
source/gnucxxcompiler.h [deleted file]
source/gnuobjccompiler.cpp [deleted file]
source/gnuobjccompiler.h [deleted file]
source/systemtools.cpp

diff --git a/source/androidccompiler.cpp b/source/androidccompiler.cpp
deleted file mode 100644 (file)
index 8c9306e..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "androidccompiler.h"
-#include "androidtools.h"
-
-AndroidCCompiler::AndroidCCompiler(Builder &b, const Architecture &a, const AndroidNdk &ndk):
-       GnuCCompiler(b, a, ndk.get_platform_sysroot())
-{
-       set_command((ndk.get_bin_dir()/command).str());
-       build_info.incpath.insert(build_info.incpath.end(), system_path.begin(), system_path.end());
-}
diff --git a/source/androidccompiler.h b/source/androidccompiler.h
deleted file mode 100644 (file)
index f723a00..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef ANDROIDCCOMPILER_H_
-#define ANDROIDCCOMPILER_H_
-
-#include "gnuccompiler.h"
-
-class AndroidNdk;
-
-class AndroidCCompiler: public GnuCCompiler
-{
-public:
-       AndroidCCompiler(Builder &, const Architecture &, const AndroidNdk &);
-};
-
-#endif
diff --git a/source/androidcompiler.cpp b/source/androidcompiler.cpp
new file mode 100644 (file)
index 0000000..490c198
--- /dev/null
@@ -0,0 +1,41 @@
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/strings/format.h>
+#include "androidcompiler.h"
+#include "androidtools.h"
+#include "builder.h"
+
+using namespace std;
+using namespace Msp;
+
+AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string &t, const AndroidNdk &n):
+       GnuCompiler(b, a, t, n.get_platform_sysroot()),
+       ndk(n)
+{
+       set_command((ndk.get_bin_dir()/command).str());
+       build_info.incpath.insert(build_info.incpath.end(), system_path.begin(), system_path.end());
+       if(tag=="CXX")
+               build_info.libs.push_back("gnustl_static");
+}
+
+void AndroidCompiler::do_prepare()
+{
+       GnuCompiler::do_prepare();
+       if(executable && tag=="CXX")
+       {
+               FS::Path libstdcxx_path = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++"/version;
+
+               FS::Path public_dir = libstdcxx_path/"include";
+               system_path.push_back(public_dir);
+               build_info.incpath.push_back(public_dir);
+
+               FS::Path arch_path = libstdcxx_path/"libs";
+               builder.get_logger().log("files", format("Traversing %s", arch_path.str()));
+               string arch_dir = architecture->best_match(list_files(arch_path));
+               if(!arch_dir.empty())
+               {
+                       build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
+                       build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
+               }
+       }
+}
diff --git a/source/androidcompiler.h b/source/androidcompiler.h
new file mode 100644 (file)
index 0000000..dbd2da6
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef ANDROIDCOMPILER_H_
+#define ANDROIDCOMPILER_H_
+
+#include "gnucompiler.h"
+
+class AndroidNdk;
+
+class AndroidCompiler: public GnuCompiler
+{
+private:
+       const AndroidNdk &ndk;
+
+public:
+       AndroidCompiler(Builder &, const Architecture &, const std::string &, const AndroidNdk &);
+
+protected:
+       virtual void do_prepare();
+};
+
+#endif
diff --git a/source/androidcxxcompiler.cpp b/source/androidcxxcompiler.cpp
deleted file mode 100644 (file)
index 41f06ed..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <msp/fs/dir.h>
-#include <msp/strings/format.h>
-#include "androidcxxcompiler.h"
-#include "androidtools.h"
-#include "architecture.h"
-#include "builder.h"
-
-using namespace std;
-using namespace Msp;
-
-AndroidCxxCompiler::AndroidCxxCompiler(Builder &b, const Architecture &a, const AndroidNdk &n):
-       GnuCxxCompiler(b, a, n.get_platform_sysroot()),
-       ndk(n)
-{
-       set_command((ndk.get_bin_dir()/command).str());
-       build_info.incpath.insert(build_info.incpath.end(), system_path.begin(), system_path.end());
-       build_info.libs.push_back("gnustl_static");
-}
-
-void AndroidCxxCompiler::do_prepare()
-{
-       GnuCxxCompiler::do_prepare();
-       if(executable)
-       {
-               FS::Path libstdcxx_path = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++"/version;
-
-               FS::Path public_dir = libstdcxx_path/"include";
-               system_path.push_back(public_dir);
-               build_info.incpath.push_back(public_dir);
-
-               FS::Path arch_path = libstdcxx_path/"libs";
-               builder.get_logger().log("files", format("Traversing %s", arch_path.str()));
-               string arch_dir = architecture->best_match(list_files(arch_path));
-               if(!arch_dir.empty())
-               {
-                       build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
-                       build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
-               }
-       }
-}
diff --git a/source/androidcxxcompiler.h b/source/androidcxxcompiler.h
deleted file mode 100644 (file)
index e6c1478..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef ANDROIDCXXCOMPILER_H_
-#define ANDROIDCXXCOMPILER_H_
-
-#include "gnucxxcompiler.h"
-
-class AndroidNdk;
-
-class AndroidCxxCompiler: public GnuCxxCompiler
-{
-private:
-       const AndroidNdk &ndk;
-
-public:
-       AndroidCxxCompiler(Builder &, const Architecture &, const AndroidNdk &);
-
-protected:
-       virtual void do_prepare();
-};
-
-#endif
index 7fd04085ca9cbc12efb698fb268f56eab5c8d9c0..809da7dc9e3f45830cc3a18a233812a76961aa6e 100644 (file)
@@ -5,8 +5,7 @@
 #include <msp/strings/utils.h>
 #include "androidarchiver.h"
 #include "androidassetpackagingtool.h"
-#include "androidccompiler.h"
-#include "androidcxxcompiler.h"
+#include "androidcompiler.h"
 #include "androidlinker.h"
 #include "androidmanifestgenerator.h"
 #include "androidtools.h"
@@ -190,8 +189,8 @@ AndroidTools::AndroidTools(Builder &builder, const Architecture &arch):
        sdk.select_api_level(highest_common);
        ndk.select_api_level(highest_common);
 
-       add_tool(new AndroidCCompiler(builder, arch, ndk));
-       add_tool(new AndroidCxxCompiler(builder, arch, ndk));
+       add_tool(new AndroidCompiler(builder, arch, "CC", ndk));
+       add_tool(new AndroidCompiler(builder, arch, "CXX", ndk));
        add_tool(new AndroidLinker(builder, arch, ndk));
        add_tool(new AndroidArchiver(builder, arch, ndk));
        add_tool(new AndroidManifestGenerator(builder));
diff --git a/source/clangccompiler.cpp b/source/clangccompiler.cpp
deleted file mode 100644 (file)
index c92e3d7..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "clangccompiler.h"
-
-ClangCCompiler::ClangCCompiler(Builder &b, const Architecture &a):
-       GnuCCompiler(b, a)
-{
-       set_command("clang", true);
-}
diff --git a/source/clangccompiler.h b/source/clangccompiler.h
deleted file mode 100644 (file)
index 2a4ec29..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef CLANGCCOMPILER_H_
-#define CLANGCCOMPILER_H_
-
-#include "gnuccompiler.h"
-
-class ClangCCompiler: public GnuCCompiler
-{
-public:
-       ClangCCompiler(Builder &, const Architecture &);
-};
-
-#endif
diff --git a/source/clangcompiler.cpp b/source/clangcompiler.cpp
new file mode 100644 (file)
index 0000000..7ad47ed
--- /dev/null
@@ -0,0 +1,10 @@
+#include "clangcompiler.h"
+
+using namespace std;
+using namespace Msp;
+
+ClangCompiler::ClangCompiler(Builder &b, const Architecture &a, const string &t, const FS::Path &r):
+       GnuCompiler(b, a, t, r)
+{
+       set_command((tag=="CXX" ? "clang++" : "clang"), true);
+}
diff --git a/source/clangcompiler.h b/source/clangcompiler.h
new file mode 100644 (file)
index 0000000..c848b75
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef CLANGCOMPILER_H_
+#define CLANGCOMPILER_H_
+
+#include "gnucompiler.h"
+
+class ClangCompiler: public GnuCompiler
+{
+public:
+       ClangCompiler(Builder &, const Architecture &, const std::string &, const Msp::FS::Path & = Msp::FS::Path());
+};
+
+#endif
diff --git a/source/clangcxxcompiler.cpp b/source/clangcxxcompiler.cpp
deleted file mode 100644 (file)
index 4dcb9d3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "clangcxxcompiler.h"
-
-ClangCxxCompiler::ClangCxxCompiler(Builder &b, const Architecture &a):
-       GnuCxxCompiler(b, a)
-{
-       set_command("clang++", true);
-}
diff --git a/source/clangcxxcompiler.h b/source/clangcxxcompiler.h
deleted file mode 100644 (file)
index 95b901c..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef CLANGCXXCOMPILER_H_
-#define CLANGCXXCOMPILER_H_
-
-#include "gnucxxcompiler.h"
-
-class ClangCxxCompiler: public GnuCxxCompiler
-{
-public:
-       ClangCxxCompiler(Builder &, const Architecture &);
-};
-
-#endif
diff --git a/source/clangobjccompiler.cpp b/source/clangobjccompiler.cpp
deleted file mode 100644 (file)
index 557bf3e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "clangobjccompiler.h"
-
-ClangObjCCompiler::ClangObjCCompiler(Builder &b, const Architecture &a):
-       GnuObjCCompiler(b, a)
-{
-       set_command("clang", true);
-}
diff --git a/source/clangobjccompiler.h b/source/clangobjccompiler.h
deleted file mode 100644 (file)
index 64b96d0..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef CLANGOBJCCOMPILER_H_
-#define CLANGOBJCCOMPILER_H_
-
-#include "gnuobjccompiler.h"
-
-class ClangObjCCompiler: public GnuObjCCompiler
-{
-public:
-       ClangObjCCompiler(Builder &, const Architecture &);
-};
-
-#endif
diff --git a/source/gnuccompiler.cpp b/source/gnuccompiler.cpp
deleted file mode 100644 (file)
index 0210a6c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "csourcefile.h"
-#include "gnuccompiler.h"
-
-using namespace std;
-using namespace Msp;
-
-GnuCCompiler::GnuCCompiler(Builder &b, const Architecture &a, const FS::Path &sysroot):
-       GnuCompiler(b, a, "CC", sysroot)
-{
-       set_command("gcc", true);
-       input_suffixes.push_back(".c");
-       aux_suffixes.push_back(".h");
-}
-
-Target *GnuCCompiler::create_source(const Component &comp, const FS::Path &path) const
-{
-       return new CSourceFile(builder, comp, path);
-}
-
-Target *GnuCCompiler::create_source(const FS::Path &path) const
-{
-       return new CSourceFile(builder, path);
-}
diff --git a/source/gnuccompiler.h b/source/gnuccompiler.h
deleted file mode 100644 (file)
index c0b5701..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef GNUCCOMPILER_H_
-#define GNUCCOMPILER_H_
-
-#include "gnucompiler.h"
-
-/**
-The GNU C compiler, commonly known as gcc.
-*/
-class GnuCCompiler: public GnuCompiler
-{
-public:
-       GnuCCompiler(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
-
-       virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
-       virtual Target *create_source(const Msp::FS::Path &) const;
-};
-
-#endif
index 816a9a31eaf196e461e9ea3ca2423bd4804f2a38..ea04fbeacfb79ca92f444b8b374b68f592477271 100644 (file)
@@ -1,13 +1,16 @@
 #include <msp/core/maputils.h>
 #include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
 #include "architecture.h"
 #include "builder.h"
 #include "component.h"
+#include "csourcefile.h"
 #include "externaltask.h"
 #include "gnucompiler.h"
+#include "objcsourcefile.h"
 #include "objectfile.h"
 #include "sourcefile.h"
 #include "sourcepackage.h"
@@ -29,6 +32,27 @@ const char *cpus[] =
 GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t, const FS::Path &sysroot):
        Tool(b, a, t)
 {
+       if(tag=="CC")
+       {
+               input_suffixes.push_back(".c");
+               aux_suffixes.push_back(".h");
+       }
+       else if(tag=="CXX")
+       {
+               input_suffixes.push_back(".cpp");
+               input_suffixes.push_back(".cc");
+               aux_suffixes.push_back(".hpp");
+       }
+       else if(tag=="OBJC")
+       {
+               input_suffixes.push_back(".m");
+               build_info.libs.push_back("objc");
+       }
+       else
+               throw invalid_argument("GnuCompiler::GnuCompiler");
+
+       set_command((tag=="CXX" ? "g++" : "gcc"), true);
+
        if(!sysroot.empty())
        {
                build_info.sysroot = sysroot;
@@ -40,6 +64,22 @@ GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t, con
                system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/include");
 }
 
+Target *GnuCompiler::create_source(const Component &comp, const FS::Path &path) const
+{
+       if(tag=="OBJC")
+               return new ObjCSourceFile(builder, comp, path);
+       else
+               return new CSourceFile(builder, comp, path);
+}
+
+Target *GnuCompiler::create_source(const FS::Path &path) const
+{
+       if(tag=="OBJC")
+               return new ObjCSourceFile(builder, path);
+       else
+               return new CSourceFile(builder, path);
+}
+
 Target *GnuCompiler::create_target(const list<Target *> &sources, const string &)
 {
        if(sources.size()!=1)
@@ -83,6 +123,14 @@ void GnuCompiler::do_prepare()
                {
                        version = strip(ExternalTask::run_and_capture_output(argv));
                        builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), version));
+
+                       if(tag=="CXX")
+                       {
+                               const FS::Path &sysroot = build_info.sysroot;
+                               FS::Path cxx_path = sysroot/"usr"/"include"/"c++"/version;
+                               if(FS::is_dir(cxx_path))
+                                       system_path.push_back(cxx_path);
+                       }
                }
                catch(const runtime_error &)
                { }
index cd6aa52b6c8b73ca96b459c2d549554972d54137..0eb25d08c155ee836a575ca2d3d915a370c80efe 100644 (file)
@@ -15,9 +15,11 @@ class GnuCompiler: public Tool
 protected:
        std::string version;
 
+public:
        GnuCompiler(Builder &, const Architecture &, const std::string &, const Msp::FS::Path & = Msp::FS::Path());
 
-public:
+       virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
+       virtual Target *create_source(const Msp::FS::Path &) const;
        virtual Target *create_target(const std::list<Target *> &, const std::string &);
        virtual std::string create_build_signature(const BuildInfo &) const;
 protected:
diff --git a/source/gnucxxcompiler.cpp b/source/gnucxxcompiler.cpp
deleted file mode 100644 (file)
index 87fe164..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <msp/fs/stat.h>
-#include "csourcefile.h"
-#include "gnucxxcompiler.h"
-
-using namespace std;
-using namespace Msp;
-
-GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a, const FS::Path &sysroot):
-       GnuCompiler(b, a, "CXX", sysroot)
-{
-       set_command("g++", true);
-       input_suffixes.push_back(".cpp");
-       input_suffixes.push_back(".cc");
-       aux_suffixes.push_back(".hpp");
-}
-
-Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
-{
-       return new CSourceFile(builder, comp, path);
-}
-
-Target *GnuCxxCompiler::create_source(const FS::Path &path) const
-{
-       return new CSourceFile(builder, path);
-}
-
-void GnuCxxCompiler::do_prepare()
-{
-       GnuCompiler::do_prepare();
-       if(!version.empty())
-       {
-               const FS::Path &sysroot = build_info.sysroot;
-               FS::Path cxx_path = sysroot/"usr"/"include"/"c++"/version;
-               if(FS::is_dir(cxx_path))
-                       system_path.push_back(cxx_path);
-       }
-}
diff --git a/source/gnucxxcompiler.h b/source/gnucxxcompiler.h
deleted file mode 100644 (file)
index 491307e..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef GNUCXXCOMPILER_H_
-#define GNUCXXCOMPILER_H_
-
-#include "gnucompiler.h"
-
-/**
-The GNU C++ compiler, commonly known as g++.
-*/
-class GnuCxxCompiler: public GnuCompiler
-{
-public:
-       GnuCxxCompiler(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
-
-       virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
-       virtual Target *create_source(const Msp::FS::Path &) const;
-
-protected:
-       virtual void do_prepare();
-};
-
-#endif
diff --git a/source/gnuobjccompiler.cpp b/source/gnuobjccompiler.cpp
deleted file mode 100644 (file)
index 16e5215..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "gnuobjccompiler.h"
-#include "objcsourcefile.h"
-
-using namespace Msp;
-
-GnuObjCCompiler::GnuObjCCompiler(Builder &b, const Architecture &a, const FS::Path &sysroot):
-       GnuCompiler(b, a, "OBJC", sysroot)
-{
-       set_command("gcc", true);
-       input_suffixes.push_back(".m");
-       build_info.libs.push_back("objc");
-}
-
-Target *GnuObjCCompiler::create_source(const Component &comp, const FS::Path &path) const
-{
-       return new ObjCSourceFile(builder, comp, path);
-}
-
-Target *GnuObjCCompiler::create_source(const FS::Path &path) const
-{
-       return new ObjCSourceFile(builder, path);
-}
diff --git a/source/gnuobjccompiler.h b/source/gnuobjccompiler.h
deleted file mode 100644 (file)
index d82da03..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef GNUOBJCCOMPILER_H_
-#define GNUOBJCCOMPILER_H_
-
-#include "gnucompiler.h"
-
-class GnuObjCCompiler: public GnuCompiler
-{
-public:
-       GnuObjCCompiler(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
-
-       virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
-       virtual Target *create_source(const Msp::FS::Path &) const;
-};
-
-#endif
index bf90cf0cf2041b3024b7c72703194495175645dc..77fe2bedb9c2b701ad67f89fc05802de8c2fb1ad 100644 (file)
@@ -1,13 +1,9 @@
 #include "architecture.h"
 #include "builder.h"
-#include "clangccompiler.h"
-#include "clangcxxcompiler.h"
-#include "clangobjccompiler.h"
+#include "clangcompiler.h"
 #include "gnuarchiver.h"
-#include "gnuccompiler.h"
-#include "gnucxxcompiler.h"
+#include "gnucompiler.h"
 #include "gnulinker.h"
-#include "gnuobjccompiler.h"
 #include "mingwdlltool.h"
 #include "systemtools.h"
 
@@ -18,15 +14,15 @@ SystemTools::SystemTools(Builder &builder, const Architecture &arch)
        const string &sys = arch.get_system();
        if((sys=="darwin" || sys=="freebsd") && builder.get_vfs().find_binary("clang"))
        {
-               add_tool(new ClangCCompiler(builder, arch));
-               add_tool(new ClangCxxCompiler(builder, arch));
-               add_tool(new ClangObjCCompiler(builder, arch));
+               add_tool(new ClangCompiler(builder, arch, "CC"));
+               add_tool(new ClangCompiler(builder, arch, "CXX"));
+               add_tool(new ClangCompiler(builder, arch, "OBJC"));
        }
        else
        {
-               add_tool(new GnuCCompiler(builder, arch));
-               add_tool(new GnuCxxCompiler(builder, arch));
-               add_tool(new GnuObjCCompiler(builder, arch));
+               add_tool(new GnuCompiler(builder, arch, "CC"));
+               add_tool(new GnuCompiler(builder, arch, "CXX"));
+               add_tool(new GnuCompiler(builder, arch, "OBJC"));
        }
 
        add_tool(new GnuLinker(builder, arch));