4

Mai

Miks mulle Rake meeldib

Marek Tihkan

Esmane kokkupuude Rakega oli mul ühest avatud lähtekoodiga .NET-i projektist. Kuna NAnt ja MSBuild on küllaltki mürarikkad, siis ei mõistnud hästi, et miks selle projektiga tegelejad ei investeerinud piisavalt aega, et see veel loetavamaks teha. Siiski hea, et edasiminek oli.

Praegu käsil olevas projektis viin vaikselt NAnt skriptid üle Rake ja nagu eelnevalt ka lubasin näidet selle kohta, siis siin see ka on.

desc "Cleans the working directory"
task :clean do
  Show.message "Cleaning solution from previous build."
  Delete.directory Path.to.build
end

desc "Prepares the working directory for a new build"
task :prepare do
  Show.message "Creating build directories."
  Create.directory Path.to.build
  Create.directory Path.to.build.binary
  Create.directory Path.to.build.tests
  Create.directory Path.to.build.results
end

desc "Update the version information for the build"
task :version do
  Show.message "Creating versioning file."
  Create.versioning_file.
      for_product_named(SOLUTION_NAME).
      versioned(SOLUTION_VERSION).
      reserve_all_rights_to(SOLUTION_OWNER).
      to(Path.to.source.file('CommonAssemblyInfo.cs'))
end

desc "Compiles the solution"
task :compile => [:clean, :prepare, :version] do
  Show.message "Compiling solution."
  Run.MSBuild.for_solution(SOLUTION_NAME).
      with_configuration(SOLUTION_CONFIGURATION).
      rebuild

  Copy.assemblies.
      from(Path.to.source.any.bin.directory(SOLUTION_CONFIGURATION)).
      to(Path.to.build.binary)
  Copy.configuration.
      from(Path.to.source.any.bin.directory(SOLUTION_CONFIGURATION)).
      to(Path.to.build.binary)
  Copy.binaries.
      from(Path.to.tests.any.bin.directory(SOLUTION_CONFIGURATION)).
      to(Path.to.build.tests)
  Copy.configuration.
      from(Path.to.tests.any.bin.directory(SOLUTION_CONFIGURATION)).
      to(Path.to.build.tests)
end

desc "Runs tests"
task :test => [:unit_test, :integration_test]

desc "Runs unit tests"
task :unit_test => :compile do
  Show.message 'Running unit tests.'
  Run.xUnitTests.located_at(Path.to.build.tests).
      save_results_to(Path.to.build.results).
      from_assembly('Arc.Unit.Tests')
end

desc "Runs integration tests"
task :integration_test => :compile do
  Show.message 'Running integration tests.'
  Run.xUnitTests.located_at(Path.to.build.tests).
      save_results_to(Path.to.build.results).
      from_assembly('Arc.Integration.Tests')
end

NAnti skriptidest mõned lõigud ka võrdluseks.

<target name="Compile"
    description="Builds entire solution"
    depends="Build,CopyAssemblies" />

<target name="Build" depends="Prepare,Version">

  <property name="verbosity" value="quiet" />
  <property name="verbosity" value="normal" if="${verbose}" />

  <exec program="${path.msbuild.console}">
    <arg value="${project.root.path}/${project.name}.sln" />
    <arg value="/property:Configuration=${project.config}" />
    <arg value="/target:Rebuild" />
    <arg value="/verbosity:${verbosity}" />
    <arg value="/nologo" />
  </exec>

</target>

<target name="CopyAssemblies" depends="CopyBinaries, CopyTests" />

<target name="CopyBinaries">
  <copy todir="${build.binary.path}" flatten="true" overwrite="true">
    <fileset basedir="${project.source.path}">
      <include name="**\bin\${project.config}\*.dll" />
      <include name="**\bin\${project.config}\*.exe" />
      <include name="**\bin\${project.config}\*.xml" />
      <include name="**\bin\${project.config}\*.pdb" />
    </fileset>
  </copy>

  <copy todir="${build.binary.path}" overwrite="true">
    <fileset basedir="${project.config.path}">
      <include name="*.xml" />
      <include name="*.config" />
    </fileset>
  </copy>
</target>

<target name="CopyTests">
  <copy todir="${build.tests.path}" flatten="true" overwrite="true">
    <fileset basedir="${project.tests.path}">
      <include name="**\bin\${project.config}\*.dll" />
      <include name="**\bin\${project.config}\*.exe" />
      <include name="**\bin\${project.config}\*.xml" />
    </fileset>
  </copy>

  <copy todir="${build.tests.path}" overwrite="true">
    <fileset basedir="${project.config.path}">
      <include name="*.xml" />
      <include name="*.config" />
    </fileset>
  </copy>
</target>

Kui teil on ideid, kuidas seda veel paremaks teha, siis andke teada. Praegu on alles pool teekonda läbitud.

  • Share/Bookmark

KATEGOORIAD » Arendus

SILDID » , ,

Lisa kommentaar

  • * Kuvatakse kommentaari juures
  • * Ei publitseerita