Skip to content

Commit

Permalink
Merge pull request #2 from Suresoft-GLaDOS/develop
Browse files Browse the repository at this point in the history
Fix #1 and modify .gitignore file
  • Loading branch information
HansolChoe committed Nov 9, 2021
2 parents c9d9255 + a6b8373 commit 4c4224c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/build
/dist

/python
/venv

/share
/.idea
**/__pychache__/

/version.py
__pychache__/
*.py[cod]
91 changes: 43 additions & 48 deletions compiler/_gnu_compiler_tool.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
import os
import re
import cslib
import subprocess
import libcsbuild
from .icompiler_tool import *


class _GnuCompilerTool(ICompilerTool):
def __init__(self, compiler_path: str, command: list):
self.toolchain_name = "GnuCompilerTool"
self.command = command
self.compiler_path = compiler_path

def get_include_option_name(self):
return "-I"

def split_command(self):
sources = [command for command in self.command if cslib.is_source_file(command)]
options = [command for command in self.command if command not in sources]
return options, sources

def get_system_include_list(self):
"""find system includes from 'gcc -c -v __test_dummy_source__.c'"""
dummy_src_path = libcsbuild.get_new_file_path("__test_dummy_source__.c")
redirect_path = libcsbuild.get_new_file_path("__redirect__.stdout")
with open(dummy_src_path, "w") as f:
f.flush()
pass

with open(redirect_path, "w") as f:
f.flush()
subprocess.call([self.compiler_path, '-v', '-c', dummy_src_path], stdout=f, stderr=f)

collect = False
collected = []
with open(redirect_path, "r") as f:

for line in f.readlines():
if line.strip().startswith("#include <...>"):
collect = True
elif line.strip().startswith("End of"):
collect = False

if collect:
collected.append(line.strip())
# remove 0 index cuz, collected[0] == "#include <...>"
return collected[1:]
import os
import re
import cslib
import subprocess
import libcsbuild

from .icompiler_tool import *


class _GnuCompilerTool(ICompilerTool):
def __init__(self, compiler_path: str, command: list):
self.toolchain_name = "GnuCompilerTool"
self.command = command
self.compiler_path = compiler_path

def get_include_option_name(self):
return "-I"

def split_command(self):
sources = [command for command in self.command if cslib.is_source_file(command)]
options = [command for command in self.command if command not in sources]
return options, sources

def get_system_include_list(self):
compiler_kind = os.path.basename(self.compiler_path)
if compiler_kind == "gcc":
command = "gcc -E -Wp,-v -xc /dev/null"
elif compiler_kind == "g++" or compiler_kind == "c++":
command = "g++ -E -Wp,-v -xc++ /dev/null"
else:
# TODO: Make no such compiler exception, and Exit gracefully
raise Exception("No Such Compiler Exception")
output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True).decode("utf-8")
collect = False
collected = []
for line in output.splitlines():
if line.strip().startswith("#include <...>"):
collect = True
elif line.strip().startswith("End of"):
collect = False
if collect:
collected.append(line.strip())
return collected[1:]
1 change: 0 additions & 1 deletion version.py

This file was deleted.

0 comments on commit 4c4224c

Please sign in to comment.