Skip to content

Commit

Permalink
Make destDir optional in PCTCompile (#278)
Browse files Browse the repository at this point in the history
Issue #277
  • Loading branch information
cverbiest authored and gquerret committed Jan 9, 2018
1 parent 1773ffc commit bba4126
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 65 deletions.
27 changes: 12 additions & 15 deletions src/java/com/phenix/pct/PCTBgCompile.java
Expand Up @@ -96,26 +96,23 @@ public void setXCodeInit(boolean xcode) {
*/
@Override
public void execute() {
if (compAttrs.getDestDir() == null) {
this.cleanup();
throw new BuildException(Messages.getString("PCTCompile.34")); //$NON-NLS-1$
}

if (compDir.exists() || !compDir.mkdirs()) {
this.cleanup();
throw new BuildException("Unable to create temp directory for compile procedure");
}

// Test output directory
if (compAttrs.getDestDir().exists()) {
if (!compAttrs.getDestDir().isDirectory()) {
this.cleanup();
throw new BuildException(Messages.getString("PCTCompile.35")); //$NON-NLS-1$
}
} else {
if (!compAttrs.getDestDir().mkdirs()) {
this.cleanup();
throw new BuildException(Messages.getString("PCTCompile.36")); //$NON-NLS-1$
if (compAttrs.getDestDir() != null) {
if (compAttrs.getDestDir().exists()) {
if (!compAttrs.getDestDir().isDirectory()) {
this.cleanup();
throw new BuildException(Messages.getString("PCTCompile.35")); //$NON-NLS-1$
}
} else {
if (!compAttrs.getDestDir().mkdirs()) {
this.cleanup();
throw new BuildException(Messages.getString("PCTCompile.36")); //$NON-NLS-1$
}
}
}

Expand Down Expand Up @@ -310,7 +307,7 @@ private String getOptions() {
sb.append("").append(';'); // Previously stream-io
sb.append("").append(';'); // Previous v6frame
sb.append(Boolean.toString(PCTBgCompile.this.getOptions().useRelativePaths())).append(';');
sb.append(compAttrs.getDestDir().getAbsolutePath()).append(';');
sb.append(compAttrs.getDestDir() == null ? "" : compAttrs.getDestDir().getAbsolutePath()).append(';');
sb.append(Boolean.toString(compAttrs.isPreprocess())).append(';');
sb.append(compAttrs.getPreprocessDir() == null ? "" : compAttrs.getPreprocessDir().getAbsolutePath()).append(';');
sb.append(Boolean.toString(compAttrs.isListing())).append(';');
Expand Down
28 changes: 11 additions & 17 deletions src/java/com/phenix/pct/PCTCompile.java
Expand Up @@ -168,8 +168,10 @@ private void writeParams() {
try (FileWriter fw = new FileWriter(params); BufferedWriter bw = new BufferedWriter(fw)) {
bw.write("FILESETS=" + fsList.getAbsolutePath()); //$NON-NLS-1$
bw.newLine();
bw.write("OUTPUTDIR=" + compAttrs.getDestDir().getAbsolutePath()); //$NON-NLS-1$
bw.newLine();
if (compAttrs.getDestDir() != null) {
bw.write("OUTPUTDIR=" + compAttrs.getDestDir().getAbsolutePath()); //$NON-NLS-1$
bw.newLine();
}
bw.write("PCTDIR=" + compAttrs.getxRefDir().getAbsolutePath()); //$NON-NLS-1$
bw.newLine();
bw.write("FORCECOMPILE=" + (compAttrs.isForceCompile() ? 1 : 0)); //$NON-NLS-1$
Expand Down Expand Up @@ -263,11 +265,7 @@ private boolean createDir(File dir) {
@Override
public void execute() {
// Create dest directory if necessary
if (compAttrs.getDestDir() == null) {
cleanup();
throw new BuildException(Messages.getString("PCTCompile.34")); //$NON-NLS-1$
}
if (!createDir(compAttrs.getDestDir())) {
if (compAttrs.getDestDir() != null && !createDir(compAttrs.getDestDir())) {
cleanup();
throw new BuildException(MessageFormat.format(Messages.getString("PCTCompile.36"), "destDir")); //$NON-NLS-1$
}
Expand All @@ -287,17 +285,13 @@ public void execute() {
}

// If preprocessDir is set, then preprocess is always set to true
if (compAttrs.getPreprocessDir() != null) {
if (!createDir(compAttrs.getPreprocessDir())) {
cleanup();
throw new BuildException(MessageFormat.format(Messages.getString("PCTCompile.36"), "preprocessDir")); //$NON-NLS-1$
}
if (compAttrs.getPreprocessDir() != null && !createDir(compAttrs.getPreprocessDir())) {
cleanup();
throw new BuildException(MessageFormat.format(Messages.getString("PCTCompile.36"), "preprocessDir")); //$NON-NLS-1$
}
if (compAttrs.getDebugListingDir() != null) {
if (!createDir(compAttrs.getDebugListingDir())) {
cleanup();
throw new BuildException(MessageFormat.format(Messages.getString("PCTCompile.36"), "debugListingDir")); //$NON-NLS-1$
}
if (compAttrs.getDebugListingDir() != null && !createDir(compAttrs.getDebugListingDir())) {
cleanup();
throw new BuildException(MessageFormat.format(Messages.getString("PCTCompile.36"), "debugListingDir")); //$NON-NLS-1$
}

log(Messages.getString("PCTCompile.40"), Project.MSG_INFO); //$NON-NLS-1$
Expand Down
21 changes: 14 additions & 7 deletions src/progress/pct/compile.p
Expand Up @@ -81,6 +81,7 @@ DEFINE STREAM sWarnings.

/* PCTCompile attributes */
DEFINE VARIABLE OutputDir AS CHARACTER NO-UNDO.
DEFINE VARIABLE DestDir AS CHARACTER NO-UNDO INITIAL ?.
DEFINE VARIABLE PCTDir AS CHARACTER NO-UNDO.
DEFINE VARIABLE preprocessDir AS CHARACTER NO-UNDO.
DEFINE VARIABLE dbgListDir AS CHARACTER NO-UNDO.
Expand Down Expand Up @@ -127,7 +128,7 @@ PROCEDURE setOption.
DEFINE INPUT PARAMETER ipValue AS CHARACTER NO-UNDO.

CASE ipName:
WHEN 'OUTPUTDIR':U THEN ASSIGN OutputDir = ipValue.
when 'OUTPUTDIR':U THEN ASSIGN DestDir = ipValue.
WHEN 'PCTDIR':U THEN ASSIGN PCTDir = ipValue.
WHEN 'FORCECOMPILE':U THEN ASSIGN ForceComp = (ipValue EQ '1':U).
WHEN 'XCODE':U THEN ASSIGN lXCode = (ipValue EQ '1':U).
Expand Down Expand Up @@ -171,6 +172,7 @@ PROCEDURE initModule:
RETURN RETURN-VALUE.

/* Checks if valid config */
OutputDir = if DestDir ne ? then DestDir else ".".
IF NOT FileExists(OutputDir) THEN
RETURN '4'.
IF NOT FileExists(PCTDir) THEN
Expand All @@ -193,7 +195,7 @@ PROCEDURE initModule:
ASSIGN iNrSteps = iTotLines
ProgPerc = 100 / iNrSteps.
RUN logVerbose IN hSrcProc ("WARNING: Less files then percentage steps. Automatically increasing percentage to " + TRIM(STRING(ProgPerc, ">>9%":U))).
END.
END.
DO iStep = 1 TO iNrSteps:
ASSIGN cDspSteps = cDspSteps + (IF cDspSteps NE "" THEN "," ELSE "") + STRING(MIN(INTEGER((iTotLines / 100) * (ProgPerc * iStep)), iTotLines)).
END.
Expand Down Expand Up @@ -229,7 +231,7 @@ PROCEDURE compileXref.
DEFINE VARIABLE cFileExt2 AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSaveDir AS CHARACTER NO-UNDO.
DEFINE VARIABLE cXrefFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE cStrXrefFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE cStrXrefFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE preprocessFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE debugListingFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE warningsFile AS CHARACTER NO-UNDO.
Expand Down Expand Up @@ -258,7 +260,7 @@ PROCEDURE compileXref.
RUN logError IN hSrcProc (SUBSTITUTE("File [&1]/[&2] not found", ipInDir, ipInFile)).
ASSIGN opError = TRUE.
ASSIGN opComp = 0.
RETURN.
RETURN.
END.

RUN adecomm/_osprefx.p(INPUT ipInFile, OUTPUT cBase, OUTPUT cFile).
Expand All @@ -267,7 +269,11 @@ PROCEDURE compileXref.
IF (opError) THEN RETURN.
ASSIGN opError = NOT createDir(PCTDir, cBase).
IF (opError) THEN RETURN.
cSaveDir = IF cFileExt = ".cls" OR lRelative THEN outputDir ELSE outputDir + '/':U + cBase.
ASSIGN cSaveDir = (IF DestDir EQ ?
THEN ?
ELSE (IF cFileExt = ".cls":U OR lRelative
THEN outputDir
ELSE outputDir + '/':U + cBase)).

IF (ipOutFile EQ ?) OR (ipOutFile EQ '') THEN DO:
ASSIGN ipOutFile = SUBSTRING(ipInFile, 1, R-INDEX(ipInFile, cFileExt) - 1) + '.r':U.
Expand All @@ -286,8 +292,9 @@ PROCEDURE compileXref.
ASSIGN opComp = 5.
END.
ELSE DO:
/* Does .r file exists ? */
ASSIGN RCodeTS = getTimeStampDF(OutputDir, ipOutFile).
/* Does .r file exists ?,
if DestDir = unknown rcode will be located in the same directory as the source : ipInDir */
ASSIGN RCodeTS = getTimeStampDF(if DestDir = ? then ipInDir else OutputDir, ipOutFile).
IF (RCodeTS EQ ?) THEN DO:
opComp = 1.
END.
Expand Down
3 changes: 2 additions & 1 deletion src/progress/pct/pctBgCompile.p
Expand Up @@ -40,7 +40,8 @@ PROCEDURE setOptions:
RUN setOption IN hComp ('KEEPXREF', IF ENTRY(8, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('MULTICOMPILE', IF ENTRY(11, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('RELATIVE', IF ENTRY(14, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('OUTPUTDIR', ENTRY(15, ipPrm, ';')).
IF (ENTRY(15, ipPrm, ';') GT "") THEN
RUN setOption IN hComp ('OUTPUTDIR', ENTRY(15, ipPrm, ';')).
RUN setOption IN hComp ('PREPROCESS', IF ENTRY(16, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('PREPROCESSDIR', ENTRY(17, ipPrm, ';')).
RUN setOption IN hComp ('LISTING', IF ENTRY(18, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
Expand Down
43 changes: 36 additions & 7 deletions src/test/com/phenix/pct/PCTCompileExtTest.java
Expand Up @@ -27,7 +27,6 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.tools.ant.BuildException;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -44,12 +43,6 @@
public class PCTCompileExtTest extends BuildFileTestNg {
private static final String BASEDIR = "PCTCompileExt/";

@Test(groups = {"v10"}, expectedExceptions = BuildException.class)
public void test1() {
configureProject(BASEDIR + "test1/build.xml");
executeTarget("test");
}

@Test(groups = {"v10"})
public void test2() {
configureProject(BASEDIR + "test2/build.xml");
Expand Down Expand Up @@ -1076,6 +1069,42 @@ public void test66() throws InvalidRCodeException, IOException {
assertNotEquals(rci1.getRCodeSize(), rci5.getRCodeSize());
}

@Test(groups = {"v10"})
public void test65() {
// Test without destDir
configureProject(BASEDIR + "test65/build.xml");
executeTarget("build_a");
executeTarget("build_b");
executeTarget("build_c");

assertTrue(new File(BASEDIR + "test65/a/src/a/a.r").exists());
assertTrue(new File(BASEDIR + "test65/b/src/b/b.r").exists());
assertTrue(new File(BASEDIR + "test65/c/src/c/c.r").exists());

assertFalse(new File(BASEDIR + "test65/b/src/a/a.r").exists());
assertFalse(new File(BASEDIR + "test65/c/src/a/a.r").exists());
assertFalse(new File(BASEDIR + "test65/c/src/b/b.r").exists());
}

@Test(groups = {"v10"})
public void test67() {
configureProject(BASEDIR + "test67/build.xml");
executeTarget("test");
assertTrue(new File(BASEDIR + "test67/build-interface/rssw/pct/ITest.r").exists());
assertTrue(new File(BASEDIR + "test67/build-impl/rssw/pct/TestImpl.r").exists());
assertFalse(new File(BASEDIR + "test67/build-impl/rssw/pct/ITest.r").exists());
}

@Test(groups = {"v10"})
public void test68() {
configureProject(BASEDIR + "test68/build.xml");
executeTarget("test");
assertTrue(new File(BASEDIR + "test68/src1/rssw/pct/ITest.r").exists());
assertTrue(new File(BASEDIR + "test68/build-impl/rssw/pct/TestImpl.r").exists());
// This file shouldn't be there, and is incorrectly created by the compiler
// assertFalse(new File(BASEDIR + "test68/build-impl/rssw/pct/ITest.r").exists());
}

@Test(groups = {"v10"})
public void test101() {
configureProject(BASEDIR + "test101/build.xml");
Expand Down
44 changes: 37 additions & 7 deletions src/test/com/phenix/pct/PCTCompileTest.java
Expand Up @@ -21,7 +21,6 @@
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;

import org.apache.tools.ant.BuildException;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -44,12 +43,6 @@
public class PCTCompileTest extends BuildFileTestNg {
private static final String BASEDIR = "PCTCompile/";

@Test(groups = {"v10"}, expectedExceptions = BuildException.class)
public void test1() {
configureProject(BASEDIR + "test1/build.xml");
executeTarget("test");
}

@Test(groups = {"v10"})
public void test2() {
configureProject(BASEDIR + "test2/build.xml");
Expand Down Expand Up @@ -1066,6 +1059,23 @@ public void test64() {
expectLog("test-fr-2", new String[] { "FR1-FR1", "7", "FR2-FR2", "7"});
}

@Test(groups = {"v10"})
public void test65() {
// Test without destDir
configureProject(BASEDIR + "test65/build.xml");
executeTarget("build_a");
executeTarget("build_b");
executeTarget("build_c");

assertTrue(new File(BASEDIR + "test65/a/src/a/a.r").exists());
assertTrue(new File(BASEDIR + "test65/b/src/b/b.r").exists());
assertTrue(new File(BASEDIR + "test65/c/src/c/c.r").exists());

assertFalse(new File(BASEDIR + "test65/b/src/a/a.r").exists());
assertFalse(new File(BASEDIR + "test65/c/src/a/a.r").exists());
assertFalse(new File(BASEDIR + "test65/c/src/b/b.r").exists());
}

@Test(groups = {"v10", "win"})
public void test66() throws InvalidRCodeException, IOException {
configureProject(BASEDIR + "test66/build.xml");
Expand All @@ -1092,4 +1102,24 @@ public void test66() throws InvalidRCodeException, IOException {
assertNotEquals(rci1.getRCodeSize(), rci3.getRCodeSize());
assertNotEquals(rci1.getRCodeSize(), rci5.getRCodeSize());
}

@Test(groups = {"v10"})
public void test67() {
configureProject(BASEDIR + "test67/build.xml");
executeTarget("test");
assertTrue(new File(BASEDIR + "test67/build-interface/rssw/pct/ITest.r").exists());
assertTrue(new File(BASEDIR + "test67/build-impl/rssw/pct/TestImpl.r").exists());
assertFalse(new File(BASEDIR + "test67/build-impl/rssw/pct/ITest.r").exists());
}

@Test(groups = {"v10"})
public void test68() {
configureProject(BASEDIR + "test68/build.xml");
executeTarget("test");
assertTrue(new File(BASEDIR + "test68/src1/rssw/pct/ITest.r").exists());
assertTrue(new File(BASEDIR + "test68/build-impl/rssw/pct/TestImpl.r").exists());
// This file shouldn't be there, and is incorrectly created by the compiler
// assertFalse(new File(BASEDIR + "test68/build-impl/rssw/pct/ITest.r").exists());
}

}
11 changes: 0 additions & 11 deletions tests/PCTCompile/test1/build.xml

This file was deleted.

3 changes: 3 additions & 0 deletions tests/PCTCompile/test65/a/src/a/a.cls
@@ -0,0 +1,3 @@
class a.a:

end class.
4 changes: 4 additions & 0 deletions tests/PCTCompile/test65/b/src/b/b.cls
@@ -0,0 +1,4 @@
class b.b inherits a.a:

end class.

33 changes: 33 additions & 0 deletions tests/PCTCompile/test65/build.xml
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="PCTCompile-test65">

<taskdef resource="PCT.properties" />

<path id="PCTPropath">
<pathelement path="a/src" />
<pathelement path="b/src" />
<pathelement path="c/src" />
</path>

<target name="build_a">
<PCTCompile dlcHome="${DLC}" multiCompile="false" relativePaths="true">
<fileset dir="a/src" includes="**/*.cls" />
<propath refid="PCTPropath" />
</PCTCompile>
</target>

<target name="build_b">
<PCTCompile dlcHome="${DLC}" multiCompile="false" relativePaths="true">
<fileset dir="b/src" includes="**/*.cls" />
<propath refid="PCTPropath" />
</PCTCompile>
</target>

<target name="build_c">
<PCTCompile dlcHome="${DLC}" multiCompile="false" relativePaths="true">
<fileset dir="c/src" includes="**/*.cls" />
<propath refid="PCTPropath" />
</PCTCompile>
</target>

</project>
5 changes: 5 additions & 0 deletions tests/PCTCompile/test65/c/src/c/c.cls
@@ -0,0 +1,5 @@

class c.c inherits b.b:

end class.

0 comments on commit bba4126

Please sign in to comment.