1

My Goal

I am trying to replace ant by scons to build java files and create jar files.

Problem

  1. Expected Result : The following piece of code env.Java(target = 'classes', source = 'src') shall generate all .class files, then, when a clean build is launched (no changes are made), scons should tell be that my tartet is up-to-date
  2. Actual Result : Because package-info.java file is empty, scons java builder is NOT generating the .class file. The side effect is everytime I launch a build, scons tell me that he needs to generate package-info.class, then, the build is relaunch everytime. The target is never considered up to date.

What I have tried so far:

This question has been asked a long time ago. But, the solution is not working anymore, and what it tries to do is to remove package-info.class from target :

tgts = env.Java(target = 'classes', source = 'src')
for f in tgts:
  if f.path.endswith('package-info.class'):
    tgts.remove(f)

jar = env.Jar(target = 'dds-interface.jar', source = tgts)
Default(jar)

This generates the error

AttributeError: <class 'SCons.Node.FS.File'> object has no attribute 'upper':
  File "C:\SVN\products\faa_mx\vs2017.install2\SConstruct", line 31:
    sc_manager.build()
  File "C:\SVN\products\faa_mx\vs2017.install2\cm\env\scons\utilities\sconscriptManager.py", line 43:
    cache = SCons.Script.SConscript(str(script).strip(), exports='envService parentEnv vcxprojList', variant_dir=utils.createVariantDir(envService, script), duplicate=0)
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Script\SConscript.py", line 614:
    return method(*args, **kw)
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Script\SConscript.py", line 551:
    return _SConscript(self.fs, *files, **subst_kw)
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Script\SConscript.py", line 256:
    call_stack[-1].globals)
  File "C:\SVN\products\faa_mx\vs2017.install2\fwk\network\dds\simd\java\api\java_api.sc", line 51:
    source = tgts)
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Tool\jar.py", line 169:
    target_classes.extend(file_to_class(s))
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Tool\jar.py", line 143:
    if(str(_my_normcase(s)).endswith(java_suffix)):
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Node\FS.py", line 366:
    return x.upper()
  File "c:\python\python35\lib\site-packages\scons-3.0.1\SCons\Node\FS.py", line 632:
    (self.__class__, attr))

From what I read into the doc, Jar only accept java file or 'classes' as source.

Questions:

  1. Is it possible to tell scons to force the generation of package-info.class file (like with ant)?
  2. Would it be possible to just remove package-info.java file from the project instead, without breaking everything? I don`t think documentation is important for our project.

EDIT

I have found the solution, I should pass -Xpkginfo:always to scons JAVACFLAGS. Unfortunately, my version of javac (1.7.0_25) is crashing when I am passing this argument.

peterphonic
  • 951
  • 1
  • 19
  • 38
  • any particular reason for choosing scons over conventional java tooling like maven, gradle, or your before used ant? – Coderino Javarino Nov 30 '19 at 14:02
  • @CoderinoJavarino 95% of our code is `c++`. In the past years, we did a quite big build system migration from `make` to `scons`. Our `java` code has been always built via `ant`, even during `make` years. `Make` was simply invoking `ant` (same thing for `scons` today). The reason I want to use `scons` is i`d like to have a uniform build system. This will make our scripts much better and cleaner. – peterphonic Nov 30 '19 at 14:14
  • Can you run again but with ```--debug=stacktrace``` and post the stacktrace? – bdbaddog Nov 30 '19 at 16:56
  • @bdbaddog Added traces. By the way, is is equivalent to remove the `package-info.class` file as removing the `package-info.java` file from the project? – peterphonic Nov 30 '19 at 17:19
  • You're using SCons 3.0.1, can you try 3.1.1? – bdbaddog Dec 01 '19 at 17:40
  • @bdbaddog Crash is gone with 3.1.1. Unfortunately, scons still saying that needs to rebuild because of `package-info.class`. The real clean solution is `-Xpkginfo:always`. I can make it working see https://stackoverflow.com/questions/59126575/xpkginfoalways-arguments-causes-javac-1-7-0-25-to-crashes, but I will need to call `Java` builder twice : once with all package-info.java files, and once more with all non-empty files. Just sad, because I love the feature of just invoking `Java('classes', 'src')` and let scons looping over all folders... I have to do manually instead... – peterphonic Dec 01 '19 at 18:04

1 Answers1

0

Finally, it is quite easy, javac compiler has an argument to force package-info.class generation.

Just need to pass -Xpkginfo:always to scons JAVACFLAGS. Unfortunately, my version of javac (1.7.0_25) is crashing when I am passing this argument. javac 1.8 is working fine with this arguments.

peterphonic
  • 951
  • 1
  • 19
  • 38