Skip to content

Dev branch #2

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

Open
wants to merge 4 commits 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vagrant
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# arduino-builder-service

Arduino Builder Service modifies codebender/compiler to compile skits with arduino-builder. As of now Arduino Builder Service compiles for version 166 for Arduino 1.6.6.

## Setup Arduino Builder Service with Vagrant
Install [Vagrant](https://www.vagrantup.com/downloads.html) on your machine.

Next, copy the code into any directory. `git clone https://github.com/codebendercc/arduino-builder-service.git`
Go into the directory with the code and `vagrant up`
SSH into the virtual machine using
```
host: localhost
port: 2222
username: vagrant
password: vagrant

```
Finally, set up the virtual machine by running `/vagrant/setup.sh`
To test if it work run `curl https://localhost/status` should return {"success":true,"status":"OK"}.
71 changes: 71 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = true

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 80

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
#config.vm.synced_folder "./", "/home/vagrant"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
vb.memory = "2048"
end
#
# View the documentation for the provider you are using for more
# information on available options.

# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
#sudo apt-get install -y apache2
SHELL
end
180 changes: 180 additions & 0 deletions modified-files/CompilerBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
/**
* \file
* \brief Functions used by the compiler backend.
*
* \author Dimitrios Christidis
* \author Vasilis Georgitzikis
*
* \copyright (c) 2012-2013, The Codebender Development Team
* \copyright Licensed under the Simplified BSD License
*/

namespace Codebender\CompilerBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Codebender\CompilerBundle\Handler\CompilerHandler;
use Codebender\CompilerBundle\Handler\DeletionHandler;
use Codebender\CompilerBundle\Handler\BuilderCompilerHandler;

class DefaultController extends Controller
{
public function statusAction()
{
return new Response(json_encode(array("success" => true, "status" => "OK")));
}

public function testAction($authorizationKey)
{
$params = $this->generateParameters();

if ($authorizationKey !== $params["authorizationKey"])
{
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid authorization key.")));
}

set_time_limit(0); // make the script execution time unlimited (otherwise the request may time out)

// change the current Symfony root dir
chdir($this->get('kernel')->getRootDir()."/../");

//TODO: replace this with a less horrible way to handle phpunit
exec("phpunit -c app --stderr 2>&1", $output, $return_val);

return new Response(json_encode(array("success" => (bool) !$return_val, "message" => implode("\n", $output))));
}

public function indexAction($authorizationKey, $version)
{
$params = $this->generateParameters();

if ($authorizationKey !== $params["authorizationKey"])
{
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid authorization key.")));
}

if ($version == "v1")
{
$request = $this->getRequest()->getContent();

//Get the compiler service
/** @var CompilerHandler $compiler */
$compiler = $this->get('builder_compiler_handler');

$reply = $compiler->main($request, $params);

return new Response(json_encode($reply));
}
else
{
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid API version.")));
}
}

public function deleteAllObjectsAction($authorizationKey, $version)
{
if ($this->container->getParameter('authorizationKey') != $authorizationKey) {
return new Response(json_encode(
array('success' => false, 'step' => 0, 'message' => 'Invalid authorization key.')
));
}

if ($version != 'v1') {
return new Response(json_encode(
array('success' => false, 'step' => 0, 'message' => 'Invalid API version.')
));
}

//Get the compiler service
/** @var DeletionHandler $deleter */
$deleter = $this->get('deletion_handler');

$response = $deleter->deleteAllObjects();

if ($response['success'] !== true) {
return new Response(json_encode(
array('success' => false, 'step' => 0, 'message' => 'Failed to access object files directory.')
));
}

return new Response(json_encode(
array_merge(
array(
'success' => true,
'message' => 'Object files deletion complete. Found ' . $response['fileCount'] . ' files.'
),
$response['deletionStats'],
array("Files not deleted" => $response['notDeletedFiles'])
)));
}

public function deleteSpecificObjectsAction($authorizationKey, $version, $option, $cachedObjectToDelete)
{
if ($this->container->getParameter('authorizationKey') != $authorizationKey) {
return new Response(json_encode(
array('success' => false, 'step' => 0, 'message' => 'Invalid authorization key.')
));
}

if ($version != 'v1') {
return new Response(json_encode(
array('success' => false, 'step' => 0, 'message' => 'Invalid API version.')
));
}

//Get the compiler service
/** @var DeletionHandler $deleter */
$deleter = $this->get('deletion_handler');

$response = $deleter->deleteSpecificObjects($option, $cachedObjectToDelete);

if ($response['success'] !== true) {
return new Response(json_encode(
array('success' => false, 'step' => 0, 'message' => 'Failed to access object files directory.')
));
}

if (!empty($response["notDeletedFiles"])) {
$message = 'Failed to delete one or more of the specified core object files.';
if ($option == 'library') {
$message = 'Failed to delete one or more of the specified library object files.';
}

return new Response(json_encode(
array_merge(array('success' => false, 'step' => 0, 'message' => $message), $response)
));
}

$message = 'Core object files deleted successfully.';
if ($option == 'library'){
$message = 'Library deleted successfully.';
}

return new Response(json_encode(array_merge(array('success' => true, 'message' => $message), $response)));
}

/**
* \brief Creates a list of the configuration parameters to be used in the compilation process.
*
* \return An array of the parameters.
*
* This function accesses the Symfony global configuration parameters, and creates an array that our handlers (which
* don't have access to them) can use them.

*/
private function generateParameters()
{
$parameters = array("binutils", "python", "clang", "logdir", "temp_dir", "archive_dir", "autocompletion_dir", "autocompleter", "cflags", "cppflags", "asflags", "arflags", "ldflags", "ldflags_tail", "clang_flags", "objcopy_flags", "size_flags", "output", "arduino_cores_dir", "external_core_files", "authorizationKey");

$compiler_config = array();

foreach ($parameters as $parameter)
{
$compiler_config[$parameter] = $this->container->getParameter($parameter);
}

return $compiler_config;
}

}
Loading