diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 03:02:04 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 20:43:25 -0500 |
commit | c6fd3f43a9d2b2f38442602769e920803a7d43ba (patch) | |
tree | e1561087d27c603075b89877213818603c3787d3 /stage2 | |
parent | 4bd0255f0a39d87652c032533ce45eb65e8f3b1e (diff) | |
download | cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.tar.gz cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.tar.bz2 cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.zip |
separate type-safe proguard wrapper into self-contained library
also make logic to maintain auto-generated sections re-usable
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/BasicBuild.scala | 13 | ||||
-rw-r--r-- | stage2/plugins/GeneratedSections.scala | 40 |
2 files changed, 50 insertions, 3 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index b6a2870..910cd5e 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -13,8 +13,10 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge implicit def transientCache: java.util.Map[AnyRef,AnyRef] = context.transientCache object libraries{ - def eval = DirectoryDependency( context.cbtHome ++ "/libraries/eval" ) - def captureArgs = DirectoryDependency( context.cbtHome ++ "/libraries/capture_args" ) + private def dep(name: String) = DirectoryDependency( context.cbtHome / "libraries" / name ) + def captureArgs = dep( "capture_args" ) + def eval = dep( "eval" ) + def proguard = dep( "proguard" ) } // library available to builds @@ -86,8 +88,13 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge */ def compileStatusFile: File = compileTarget ++ ".last-success" + def generatedSources: Seq[File] = Seq( projectDirectory / "src_generated" ) /** Source directories and files. Defaults to .scala and .java files in src/ and top-level. */ - def sources: Seq[File] = Seq(defaultSourceDirectory) ++ projectDirectory.listFiles.toVector.filter(sourceFileFilter) + def sources: Seq[File] = ( + Seq(defaultSourceDirectory) + ++ generatedSources + ++ projectDirectory.listFiles.toVector.filter(sourceFileFilter) + ) /** Which file endings to consider being source files. */ def sourceFileFilter(file: File) = lib.sourceFileFilter(file) diff --git a/stage2/plugins/GeneratedSections.scala b/stage2/plugins/GeneratedSections.scala new file mode 100644 index 0000000..417278c --- /dev/null +++ b/stage2/plugins/GeneratedSections.scala @@ -0,0 +1,40 @@ +package cbt +import java.nio.file.Files._ +trait GeneratedSections extends BaseBuild{ + def generatedSectionStartMarker( name: String ) = s"AUTO GENERATED SECTION BEGIN: $name " + def generatedSectionEndMarker( name: String ) = s"AUTO GENERATED SECTION END: $name " + assert( + generatedSectionStartMarker("foo").endsWith(" "), + "generatedSectionStartMarker needs to end with a space character" + ) + assert( + generatedSectionEndMarker("foo").endsWith(" "), + "generatedSectionEndMarker needs to end with a space character" + ) + + def replacements: Seq[(String, String)] + + def generate = { + def replaceSections(subject: String, sections: Seq[(String, String)]): String = { + sections.headOption.map{ + case (name, replacement) => + replaceSections( + s"(?s)(\n[^\n]*AUTO GENERATED SECTION BEGIN: $name [^\n]*\n).*(\n[^\n]*AUTO GENERATED SECTION END: $name [^\n]*\n)" + .r.replaceAllIn( subject, m => m.group(1) ++ replacement ++ m.group(2) ), + sections.tail + ) + }.getOrElse(subject) + } + + val updated = sourceFiles.flatMap{ file => + val template = file.readAsString + val replaced = replaceSections( template, replacements ) + if( template != replaced ) { + write( file.toPath, replaced.getBytes ) + Some(file) + } else None + } + + logger.log("generated-sections","Updated:" + updated.map(_ ++ "\n").mkString) + } +} |