Skip to content

Commit

Permalink
Add means to speed up encoding detection
Browse files Browse the repository at this point in the history
  • Loading branch information
17451k committed Feb 26, 2019
1 parent c4855d5 commit 354a62c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions clade/extensions/abstract.py
Expand Up @@ -219,6 +219,9 @@ def __get_cmd_chunk(self, cmds, chunk_size=1000):

def parse_cmds_in_parallel(self, cmds, unwrap, total_cmds=None):
if os.environ.get("CLADE_DEBUG"):
if total_cmds:
self.log("Parsing {} commands".format(total_cmds))

for cmd in cmds:
unwrap(self, cmd)
return
Expand Down
18 changes: 15 additions & 3 deletions clade/extensions/cl.py
Expand Up @@ -13,7 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import chardet
try:
import cchardet as chardet
except ImportError:
import chardet

import os
import re
import subprocess
Expand Down Expand Up @@ -141,7 +145,11 @@ def __collect_deps(self, cmd_id, cmd):

self.__preprocess_cmd(cmd)

encoding = chardet.detect(output_bytes)["encoding"]
if self.conf.get("CL.deps_encoding"):
encoding = self.conf.get("CL.deps_encoding")
else:
encoding = chardet.detect(output_bytes)["encoding"]

if not encoding:
return ""
return output_bytes.decode(encoding)
Expand Down Expand Up @@ -187,7 +195,11 @@ def __preprocess_cmd(self, cmd):

def __normalize_paths(self, c_file, cwd):
rawdata = open(c_file, 'rb').read()
encoding = chardet.detect(rawdata)["encoding"]

if self.conf.get("CL.deps_encoding"):
encoding = self.conf.get("CL.deps_encoding")
else:
encoding = chardet.detect(rawdata)["encoding"]

with open(c_file, "r", encoding=encoding) as c_file_fh, open(
c_file + ".new", "w", encoding="utf-8"
Expand Down
2 changes: 2 additions & 0 deletions clade/extensions/presets/presets.json
Expand Up @@ -9,6 +9,8 @@
"CC.ignore_cc1": true,
"CC.filter_deps": true,
"CC.with_system_header_files": true,
"CL.deps_encoding": null,
"CL.pre_encoding": null,
"Compiler.store_deps": true,
"Compiler.preprocess_cmds": false,
"Compiler.extra_preprocessor_opts": [],
Expand Down

0 comments on commit 354a62c

Please sign in to comment.