Browse Source

Merge pull request #1 from mono/master

Merging mono/CppSharp
pull/517/head
Pedro Miguel Casaleiro Dias 10 years ago
parent
commit
9e180d26b8
  1. 11
      .travis.yml
  2. 41
      build/ci/vagrant/ubuntu_x64/Vagrantfile
  3. 12
      src/CppParser/Parser.cpp
  4. 269
      src/CppParser/VSLookup.cpp
  5. 1
      src/CppParser/premake4.lua
  6. 1
      src/Generator.Tests/ASTTestFixture.cs
  7. 4
      src/Generator.Tests/GeneratorTest.cs
  8. 10
      src/Generator/Driver.cs
  9. 2
      src/Generator/Passes/GenerateInlinesCodePass.cs

11
.travis.yml

@ -6,21 +6,20 @@ addons: @@ -6,21 +6,20 @@ addons:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- gcc-4.8-multilib
- g++-4.8
- g++-4.8-multilib
install:
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
- echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
- echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
- sudo apt-get update -qq
- sudo apt-get install -y mono-devel nuget
- build/premake5-linux-64 --file=build/premake4.lua gmake
- sudo apt-get install -y mono-devel nuget p7zip-full
- nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
- wget -O llvm_linux_x86_64.7z https://www.dropbox.com/s/zxigif3vghsdfli/llvm_linux_x86_64.7z?dl=0
- 7z x llvm_linux_x86_64.7z -odeps/llvm -y
script:
- build/premake5-linux-64 --file=build/premake4.lua gmake
- config=release_x64 make -C build/gmake/
- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe build/gmake/lib/Debug_x32/CppSharp.*Tests*.dll
- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe build/gmake/lib/Release_x64/CppSharp.*Tests*.dll

41
build/ci/vagrant/ubuntu_x64/Vagrantfile vendored

@ -93,6 +93,8 @@ Vagrant.configure(2) do |config| @@ -93,6 +93,8 @@ Vagrant.configure(2) do |config|
# Build tools
apt-get install -y git build-essential clang cmake ninja-build
aot-get install -y p7zip-full
# Mono
apt-get install -y mono-devel
@ -128,5 +130,44 @@ Vagrant.configure(2) do |config| @@ -128,5 +130,44 @@ Vagrant.configure(2) do |config|
ninja
# make the output package
cd ..
if [ -d "out" ]; then rm -rf out; fi
mkdir out
mkdir -p out/tools/clang
mkdir -p out/tools/clang/lib/CodeGen
mkdir -p out/build/
mkdir -p out/build/lib
mkdir -p out/build/tools/clang
mkdir -p out/build/tools/clang/lib
cp -R include/ out/
cp -R build/include/ out/build
cp build/lib/*.a out/build/lib
cp -R tools/clang/include/ out/tools/clang
cp -R tools/clang/lib/CodeGen/*.h out/tools/clang/lib/CodeGen
cp -R build/tools/clang/include/ out/build/tools/clang
rm out/build/lib/libllvm*ObjCARCOpts*.a
rm out/build/lib/libclang*ARC*.a
rm out/build/lib/libclang*Matchers*.a
rm out/build/lib/libclang*Rewrite*.a
rm out/build/lib/libclang*StaticAnalyzer*.a
rm out/build/lib/libclang*Tooling*.a
7z a llvm_linux_x86_64.7z ./out/*
# upload to dropbox
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
echo APPKEY= > ~/.dropbox_uploader
echo APPSECRET= >> ~/.dropbox_uploader
echo ACCESS_LEVEL=sandbox >> ~/.dropbox_uploader
echo OAUTH_ACCESS_TOKEN= >> ~/.dropbox_uploader
echo OAUTH_ACCESS_TOKEN_SECRET= >> ~/.dropbox_uploader
./dropbox_uploader.sh upload llvm_linux_x86_64.7z llvm_linux_x86_64.7z
SHELL
end

12
src/CppParser/Parser.cpp

@ -87,10 +87,6 @@ static std::string GetClangBuiltinIncludeDir() @@ -87,10 +87,6 @@ static std::string GetClangBuiltinIncludeDir()
//-----------------------------------//
#ifdef _MSC_VER
std::vector<std::string> GetWindowsSystemIncludeDirs();
#endif
static clang::TargetCXXABI::Kind
ConvertToClangTargetCXXABI(CppSharp::CppParser::AST::CppAbi abi)
{
@ -228,14 +224,6 @@ void Parser::SetupHeader() @@ -228,14 +224,6 @@ void Parser::SetupHeader()
/*IsFramework=*/false, /*IgnoreSysRoot=*/false);
#ifdef _MSC_VER
if (!Opts->NoBuiltinIncludes)
{
std::vector<std::string> SystemDirs = GetWindowsSystemIncludeDirs();
for(unsigned i = 0; i < SystemDirs.size(); i++)
HSOpts.AddPath(SystemDirs[i], frontend::System, /*IsFramework=*/false,
/*IgnoreSysRoot=*/false);
}
if (Opts->MicrosoftMode)
{
LangOpts.MSCompatibilityVersion = Opts->ToolSetToUse;

269
src/CppParser/VSLookup.cpp

@ -1,269 +0,0 @@ @@ -1,269 +0,0 @@
/************************************************************************
*
* CppSharp
* Licensed under the simplified BSD license. All rights reserved.
*
************************************************************************/
#ifdef _MSC_VER
#include <string>
#include <vector>
#include <cctype>
// Include the necessary headers to interface with the Windows registry and
// environment.
#define WIN32_LEAN_AND_MEAN
#define NOGDI
#define NOMINMAX
#include <Windows.h>
/// \brief Read registry string.
/// This also supports a means to look for high-versioned keys by use
/// of a $VERSION placeholder in the key path.
/// $VERSION in the key path is a placeholder for the version number,
/// causing the highest value path to be searched for and used.
/// I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
/// There can be additional characters in the component. Only the numeric
/// characters are compared.
static bool getSystemRegistryString(const char *keyPath, const char *valueName,
char *value, size_t maxLength) {
HKEY hRootKey = NULL;
HKEY hKey = NULL;
const char* subKey = NULL;
DWORD valueType;
DWORD valueSize = maxLength - 1;
long lResult;
bool returnValue = false;
if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
hRootKey = HKEY_CLASSES_ROOT;
subKey = keyPath + 18;
} else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) {
hRootKey = HKEY_USERS;
subKey = keyPath + 11;
} else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) {
hRootKey = HKEY_LOCAL_MACHINE;
subKey = keyPath + 19;
} else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) {
hRootKey = HKEY_CURRENT_USER;
subKey = keyPath + 18;
} else {
return false;
}
const char *placeHolder = strstr(subKey, "$VERSION");
char bestName[256];
bestName[0] = '\0';
// If we have a $VERSION placeholder, do the highest-version search.
if (placeHolder) {
const char *keyEnd = placeHolder - 1;
const char *nextKey = placeHolder;
// Find end of previous key.
while ((keyEnd > subKey) && (*keyEnd != '\\'))
keyEnd--;
// Find end of key containing $VERSION.
while (*nextKey && (*nextKey != '\\'))
nextKey++;
size_t partialKeyLength = keyEnd - subKey;
char partialKey[256];
if (partialKeyLength > sizeof(partialKey))
partialKeyLength = sizeof(partialKey);
strncpy(partialKey, subKey, partialKeyLength);
partialKey[partialKeyLength] = '\0';
HKEY hTopKey = NULL;
lResult = RegOpenKeyExA(hRootKey, partialKey, 0, KEY_READ, &hTopKey);
if (lResult == ERROR_SUCCESS) {
char keyName[256];
int bestIndex = -1;
double bestValue = 0.0;
DWORD index, size = sizeof(keyName) - 1;
for (index = 0; RegEnumKeyExA(hTopKey, index, keyName, &size, NULL,
NULL, NULL, NULL) == ERROR_SUCCESS; index++) {
const char *sp = keyName;
while (*sp && !isdigit(*sp))
sp++;
if (!*sp)
continue;
const char *ep = sp + 1;
while (*ep && (isdigit(*ep) || (*ep == '.')))
ep++;
char numBuf[32];
strncpy(numBuf, sp, sizeof(numBuf) - 1);
numBuf[sizeof(numBuf) - 1] = '\0';
double value = strtod(numBuf, NULL);
// Check if InstallDir key value exists.
bool isViableVersion = false;
lResult = RegOpenKeyExA(hTopKey, keyName, 0, KEY_READ, &hKey);
if (lResult == ERROR_SUCCESS) {
lResult = RegQueryValueExA(hKey, valueName, NULL, NULL, NULL, NULL);
if (lResult == ERROR_SUCCESS)
isViableVersion = true;
RegCloseKey(hKey);
}
if (isViableVersion && (value > bestValue)) {
bestIndex = (int)index;
bestValue = value;
strcpy(bestName, keyName);
}
size = sizeof(keyName) - 1;
}
// If we found the highest versioned key, open the key and get the value.
if (bestIndex != -1) {
// Append rest of key.
strncat(bestName, nextKey, sizeof(bestName) - 1);
bestName[sizeof(bestName) - 1] = '\0';
// Open the chosen key path remainder.
lResult = RegOpenKeyExA(hTopKey, bestName, 0, KEY_READ, &hKey);
if (lResult == ERROR_SUCCESS) {
lResult = RegQueryValueExA(hKey, valueName, NULL, &valueType,
(LPBYTE)value, &valueSize);
if (lResult == ERROR_SUCCESS)
returnValue = true;
RegCloseKey(hKey);
}
}
RegCloseKey(hTopKey);
}
} else {
lResult = RegOpenKeyExA(hRootKey, subKey, 0, KEY_READ, &hKey);
if (lResult == ERROR_SUCCESS) {
lResult = RegQueryValueExA(hKey, valueName, NULL, &valueType,
(LPBYTE)value, &valueSize);
if (lResult == ERROR_SUCCESS)
returnValue = true;
RegCloseKey(hKey);
}
}
return returnValue;
}
/// \brief Get Windows SDK installation directory.
static bool getWindowsSDKDir(std::string &path) {
char windowsSDKInstallDir[256];
// Try the Windows registry.
bool hasSDKDir = getSystemRegistryString(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
"InstallationFolder",
windowsSDKInstallDir,
sizeof(windowsSDKInstallDir) - 1);
// If we have both vc80 and vc90, pick version we were compiled with.
if (hasSDKDir && windowsSDKInstallDir[0]) {
path = windowsSDKInstallDir;
return true;
}
return false;
}
// Get Visual Studio installation directory.
static bool getVisualStudioDir(std::string &path) {
// First check the environment variables that vsvars32.bat sets.
const char* vcinstalldir = getenv("VCINSTALLDIR");
if (vcinstalldir) {
char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC"));
if (p)
*p = '\0';
path = vcinstalldir;
return true;
}
char vsIDEInstallDir[256];
char vsExpressIDEInstallDir[256];
// Then try the windows registry.
bool hasVCDir = getSystemRegistryString(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
"InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1);
bool hasVCExpressDir = getSystemRegistryString(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION",
"InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1);
// If we have both vc80 and vc90, pick version we were compiled with.
if (hasVCDir && vsIDEInstallDir[0]) {
char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
if (p)
*p = '\0';
path = vsIDEInstallDir;
return true;
}
if (hasVCExpressDir && vsExpressIDEInstallDir[0]) {
char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE");
if (p)
*p = '\0';
path = vsExpressIDEInstallDir;
return true;
}
// Try the environment.
const char *vs120comntools = getenv("VS120COMNTOOLS");
const char *vs110comntools = getenv("VS110COMNTOOLS");
const char *vs100comntools = getenv("VS100COMNTOOLS");
const char *vs90comntools = getenv("VS90COMNTOOLS");
const char *vs80comntools = getenv("VS80COMNTOOLS");
const char *vscomntools = NULL;
// Try to find the version that we were compiled with
if(false) {}
#if (_MSC_VER >= 1800) // VC120
else if (vs120comntools) {
vscomntools = vs120comntools;
}
#elif (_MSC_VER == 1700) // VC110
else if (vs110comntools) {
vscomntools = vs110comntools;
}
#elif (_MSC_VER == 1600) // VC100
else if(vs100comntools) {
vscomntools = vs100comntools;
}
#elif (_MSC_VER == 1500) // VC80
else if(vs90comntools) {
vscomntools = vs90comntools;
}
#elif (_MSC_VER == 1400) // VC80
else if(vs80comntools) {
vscomntools = vs80comntools;
}
#endif
// Otherwise find any version we can
else if (vs120comntools)
vscomntools = vs120comntools;
else if (vs110comntools)
vscomntools = vs110comntools;
else if (vs100comntools)
vscomntools = vs100comntools;
else if (vs90comntools)
vscomntools = vs90comntools;
else if (vs80comntools)
vscomntools = vs80comntools;
if (vscomntools && *vscomntools) {
const char *p = strstr(vscomntools, "\\Common7\\Tools");
path = p ? std::string(vscomntools, p) : vscomntools;
return true;
}
return false;
}
std::vector<std::string> GetWindowsSystemIncludeDirs() {
std::vector<std::string> Paths;
std::string VSDir;
std::string WindowsSDKDir;
// When built with access to the proper Windows APIs, try to actually find
// the correct include paths first.
if (getVisualStudioDir(VSDir)) {
Paths.push_back(VSDir + "\\VC\\include");
if (getWindowsSDKDir(WindowsSDKDir))
Paths.push_back(WindowsSDKDir + "\\include");
else
Paths.push_back(VSDir + "\\VC\\PlatformSDK\\Include");
}
return Paths;
}
#endif

1
src/CppParser/premake4.lua

@ -17,7 +17,6 @@ project "CppSharp.CppParser" @@ -17,7 +17,6 @@ project "CppSharp.CppParser"
configuration "vs*"
buildoptions { clang_msvc_flags }
files { "VSLookup.cpp" }
configuration "*"

1
src/Generator.Tests/ASTTestFixture.cs

@ -20,6 +20,7 @@ namespace CppSharp.Generator.Tests @@ -20,6 +20,7 @@ namespace CppSharp.Generator.Tests
Options.Headers.AddRange(files);
Driver = new Driver(Options, new TextDiagnosticPrinter());
Driver.SetupIncludes();
Driver.BuildParseOptions();
if (!Driver.ParseCode())
throw new Exception("Error parsing the code");

4
src/Generator.Tests/GeneratorTest.cs

@ -49,10 +49,6 @@ namespace CppSharp.Utils @@ -49,10 +49,6 @@ namespace CppSharp.Utils
Path.GetFullPath(Path.Combine(path, "../../deps/llvm/tools/clang/lib/Headers"))
};
if (Platform.IsMacOS) {
options.SetupXcode();
}
foreach (var header in headersPaths)
options.addSystemIncludeDirs(header);

10
src/Generator/Driver.cs

@ -76,10 +76,20 @@ namespace CppSharp @@ -76,10 +76,20 @@ namespace CppSharp
{
ValidateOptions(Options);
SetupIncludes();
TypeDatabase.SetupTypeMaps(Options.GeneratorKind);
Generator = CreateGeneratorFromKind(Options.GeneratorKind);
}
public void SetupIncludes()
{
if (Platform.IsMacOS)
Options.SetupXcode();
else if (Platform.IsWindows && !Options.NoBuiltinIncludes)
Options.SetupMSVC();
}
void OnSourceFileParsed(SourceFile file, ParserResult result)
{
OnFileParsed(file.Path, result);

2
src/Generator/Passes/GenerateInlinesCodePass.cs

@ -17,7 +17,7 @@ namespace CppSharp.Passes @@ -17,7 +17,7 @@ namespace CppSharp.Passes
{
var cppBuilder = new StringBuilder();
foreach (var header in Driver.Options.Headers)
cppBuilder.AppendFormat("#include \"{0}\"\n", header);
cppBuilder.AppendFormat("#include <{0}>\n", header);
var cpp = string.Format("{0}.cpp", Driver.Options.InlinesLibraryName);
var path = Path.Combine(Driver.Options.OutputDir, cpp);
File.WriteAllText(path, cppBuilder.ToString());

Loading…
Cancel
Save