<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>experimentalworks &#187; scala</title>
	<atom:link href="http://blog.experimentalworks.net/tag/scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.experimentalworks.net</link>
	<description></description>
	<lastBuildDate>Wed, 14 Jul 2010 15:35:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Writing a simple PHP sourcecode buildscript in Scala</title>
		<link>http://blog.experimentalworks.net/2010/01/writing-a-simple-php-source-buildscript-in-scala/</link>
		<comments>http://blog.experimentalworks.net/2010/01/writing-a-simple-php-source-buildscript-in-scala/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 22:48:22 +0000</pubDate>
		<dc:creator>dsp</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://blog.experimentalworks.net/?p=356</guid>
		<description><![CDATA[Scala is a fascinating language. Running on the Java VM [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.scala-lang.org">Scala</a> is a fascinating language. Running on the <a href="http://java.com">Java VM</a>, Scala offers a powerful mixture from both the imperative Java world and functional programming including modern techniques like <a href="http://www.scala-lang.org/node/242">Actors</a>. Personally I prefer to not just learn programming languages, but also try them out while reading through the book.</p>
<p>As I wanted to have nice a build system for my <a href="http://php.net">PHP</a> <a href="http://svn.php.net">subversion</a> checkout, I used this need as a project to start coding Scala. So what do I exactly need? I want to build multiple versions of PHP from the same branch without checking out the code twice. I also want to configure these builds somewhere without always typing in the parameter list or so. For further versions I want to be able to configure these in a file that can easily be distributed to other machines.</p>
<p>I set down and wrote a parser for a configuration file that can configured build targets which is then build by<br />
the program. The configuration file I used is specialized for this purpose, which is why I didn&#8217;t used something like ant or so. The result is called <strong><a href='http://blog.experimentalworks.net/wp-content/uploads/2010/01/bauaffe-3.0.0a1.jar'>bauaffe-3.0.0a1.jar</a></strong>.</p>
<p>I&#8217;ll just show a few things done in the project, but mainly focus on what the nice script can do. Further blog posts will be about the actual implementation.</p>
<p>The configuration looks like this</p>
<pre>
$ cat ~/.buildmaker
begin default configuration
    define source "/Users/dsp/dev/c/php-src"
    define build "/Users/dsp/dev/c/php-src/build"
    define defaults as
        with "iconv=/opt/local"
    build trunk as
        "php60" using defaults
        "php60-debug" using defaults
            enable "debug"
    build branch "PHP_5_3" as
        "php53" using defaults
            environment PHP_AUTOCONF="autoconf213"
        "php53-debug" using defaults
            enable "debug"
            environment PHP_AUTOCONF="autoconf213"
</pre>
<p>.<br />
Proper indention is not necessary (as e.g in python).</p>
<hr />
You might want to think that parsing the configuration file can be difficult. Well, if you use C you would use YACC, if you use PHP, I don&#8217;t know what you would have done, but Scala is made to create this kind of Domain Specific Languages (for my the config is a DSL). You can easily transform a EBNF directly to scala code using the JavaTokenParsers provided by the Scala Library. As an example this it the statement that parses the first line:<br />
<code><br />
    def begin : Parser[Configuration] =<br />
        "begin" ~ ("default" | stringLiteral) ~ "configuration" ~ rep(define | build) ^^ {<br />
        case "begin"~name~"configuration"~confs => new Configuration(name, confs)<br />
    }<br />
</code><br />
which is directly taken from the BNF:<br />
<code><br />
      config ::= "begin" ( "default" | string ) "configuration" ( define | build )*<br />
</code></p>
<p>Did I mention that the actual parser is 170 lines of code with usual indention and formatting?</p>
<hr />
<p><strong>Configuration</strong><br />
The configuration file is searched in <i>~/.buildmaker</i>, or if <i>~/.builmaker</i> doesn&#8217;t exists, <i>buildmaker.conf</i> in the current directory. How do you configure the tool? First of all you can specify a configuration. It is usually called &#8220;default&#8221;. It is not yet supported to name it differently, although the parser is able to parse it. In further versions multiple configurations per file are allowed.</p>
<p><strong>Variables</strong><br />
Variables are set using the <i>define</i> syntax. At the moment you can set the <i>build</i> and <i>source</i> variable as well the <em>defaults</em> variable, which is usually a block of statements that can be used in the branch configurations. </p>
<p><strong>Branches</strong><br />
A branch is configured using the <em>build</em> syntax. You first have to specify which branch to build. Every branch can then configured to have build target with a given set of options. Branch options are:</p>
<ul>
<li>with <em>string</em>: Builds the target with the given extension</li>
<li>enable <em>string</em>: Builds the target with the given extension</li>
<li>environment <em>string=string</em>: Builds the target with environment variable</li>
</ul>
<p>. You can specify <i>using defaults</i> which will cause the runner to use the options specified in the <i>defaults</i> define.</p>
<p><em>At the moment the parser will not do a good job in notifying you what you are allowed to do and what not, although pure parse error will be emitted. You can also not set any other variable than the described once.</em></p>
<p><strong>Building</strong><br />
Calling</p>
<pre>
$ java -jar bauaffe-3.0.0a1.jar list
TARGET                         LAST BUILD
php60                          None
php60-debug                    None
php53                          Sat Jan 09 16:55:12 CET 2010
php53-debug                    Sat Jan 09 16:59:37 CET 2010
</pre>
<p>gives you a list of parsed targets and their last build date. You can build a target using</p>
<pre>
$ java -jar bauaffe-3.0.0a1.jar <targetname>
</targetname></pre>
<p>or build all using</p>
<pre>
$ java -jar bauaffe-3.0.0a1.jar all
</pre>
<p>Please notice that the current version requires that you now what you are doing. You might miss some error messages or find them not useful. I&#8217;ll change this before the first release, if I&#8217;ll do a final version of it. I hope you like the little tool.</p>
<p><a href='http://blog.experimentalworks.net/wp-content/uploads/2010/01/bauaffe-3.0.0a1.jar'>Download It!</a></p>
<p><em>Scala (pronounced /ˈskɑːlə, ˈskeɪlə/) is a multi-paradigm programming language designed to integrate features of object-oriented programming and functional programming.[1] The name Scala stands for &#8220;scalable language&#8221;, signifying that it is designed to grow with the demands of its users.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.experimentalworks.net/2010/01/writing-a-simple-php-source-buildscript-in-scala/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
