Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make builder recognize and fetch hpp files as headers #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
{
$apiHandler = $this->get('codebender_builder.handler');

$detectedHeaders = $apiHandler->readLibraries($projectFiles);
$detectedHeaderstemp = $apiHandler->readLibraries($projectFiles);

// declare arrays
$notFoundHeaders = [];
Expand All @@ -139,40 +139,54 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
$providedLibraries = array_keys($userLibraries);
$libraries = $userLibraries;

foreach ($detectedHeaders as $header) {
foreach ($detectedHeaderstemp as $header) {

$existsInRequest = false;
// TODO We can do this in a better way
foreach ($userLibraries as $library) {
foreach ($library as $libraryContent) {
if ($libraryContent["filename"] == $header.".h") {
if ($libraryContent["filename"] == $header) {
$existsInRequest = true;
$foundHeaders[] = $header . ".h";
$foundHeaders[] = $header;
}
}
}

if ($existsInRequest === true) {
continue;
}
$requestContent = ["type" => "fetch", "library" => $header];

//Fetch lib from library manager by name
$headername = pathinfo($header, PATHINFO_FILENAME);

$requestContent = ["type" => "fetch", "library" => $headername];
$data = $this->getLibraryInfo(json_encode($requestContent));

if ($data['success'] === false) {
$notFoundHeaders[] = $header . ".h";
$notFoundHeaders[] = $header;
continue;
}

$foundHeaders[] = $header . ".h";
$foundHeaders[] = $header;
$librariesFromLibman[] = $header;
$filesToBeAdded = [];
foreach ($data["files"] as $file) {
if (in_array(pathinfo($file['filename'], PATHINFO_EXTENSION), array('cpp', 'h', 'c', 'S', 'inc')))
if (in_array(pathinfo($file['filename'], PATHINFO_EXTENSION), array('cpp', 'h', 'hpp', 'c', 'S', 'inc')))
$filesToBeAdded[] = $file;
}
$libraries[$header] = $filesToBeAdded;
}

/*
* Get only the names of the header files.
* Until we make codebender handles headers along with their extensions (e.g. "Ethernet.h", not "Ethernet"),
* this must stay here for compatibility reasons.
*/
foreach ($detectedHeaderstemp as $headerfiles) {
$detectedHeaders[] = pathinfo($headerfiles, PATHINFO_FILENAME);
}


// store info about libraries and headers in the `additionalCode` class property;
$this->additionalCode = [
'providedLibraries' => $providedLibraries,
Expand Down
19 changes: 10 additions & 9 deletions Symfony/src/Codebender/BuilderBundle/Handler/DefaultHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ function detectHeadersInFile($code) {
* Examples:
* #include<stdio.h>
* # include "proto.h"
*
* #include "jsonlib.hpp"
*/
$arrowsRegex = "/^\s*#\s*include\s*<\s*([a-zA-Z0-9_+]*)\.h\s*>/";
$quotesRegex = "/^\s*#\s*include\s*\"\s*([a-zA-Z0-9_+]*)\.h\s*\"/";
$arrowsRegex = "/^\s*#\s*include\s*<\s*([a-zA-Z0-9_+]*\.h)\s*([p]{2})*\s*>/";
$quotesRegex = "/^\s*#\s*include\s*\"\s*([a-zA-Z0-9_+]*\.h)\s*([p]{2})*\s*\"/";

$headers = ["arrows" => [], "quotes" => []];
$matches= [[]];
foreach (explode("\n", $code) as $line)
{
if (preg_match($arrowsRegex, $line, $matches))
$headers["arrows"][] = $matches[1];
if (preg_match($quotesRegex, $line, $matches))
$headers["quotes"][] = $matches[1];
}
if (preg_match($arrowsRegex, $line, $matches)){
$headers["arrows"][] = $matches[1].$matches[2];}
if (preg_match($quotesRegex, $line, $matches)){
$headers["quotes"][] = $matches[1].$matches[2];
}}

$headers["arrows"] = array_unique($headers["arrows"]);
$headers["quotes"] = array_unique($headers["quotes"]);
Expand Down Expand Up @@ -88,7 +89,7 @@ function readLibraries($sketchFiles) {

foreach ($headers["quotes"] as $key => $header) {
foreach ($sketchFiles as $file) {
if ($file["filename"] == $header.".h")
if ($file["filename"] == $header)
unset($headers["quotes"][$key]);
}
}
Expand Down