Skip to content

Best way to output multiple executables for the same chapter and language #954

Closed

Description

@PeanutbutterWarrior

Current Behaviour

Currently SCons assumes that each language's implementation of each chapter has only a single file that needs building. Having multiple files that are compiled together into a single executable is a special case that justifies a SConstruct file to handle it specifically, but often there are two or more files that are compiled into separate executables, such as in Stacks and Queues. An minimal example of the current structure generated is

arcane-algorithm-archive/
|──build/
|   |──c/
|   |   +  barnsley.exe
|   |   +  euclidean_algorithm.exe
|   |
|   |──python/
|   |   +  barnsley.py
|   |   +  euclidean_algorithm.py

If a language has multiple implementations for a chapter, or implements parts of the chapter in separate files then the executable generated from one file will overwrite the other (SCons will actually detect this, throw an error and not build either which is arguably worse).

Desired behaviour

We want all the files to be compiled into separate executables. In order to do this they need either different names or to be put into different folders. Multiple ways to do this have been suggested, described below along with pros and cons for them.

Option 1: Duplicate the structure of arcane-algorithm-archive/contents

This would be putting the executables into folders depending on their chapter, in folders based on language. The executables would be named the same as the source file (with the extension changed as necessary). The structure of this is below

arcane-algorithm-archive/
|──build/
|   |──barnsley/
|   |   |──python/
|   |   |   +  barnsley.py
|   |   |──c/
|   |   |   +  barnsley_1.exe
|   |   |   +  barnsley_2.exe
|   |
|   |──euclidean_algorithm/
|   |   |──python/
|   |   |   +  euclidean_algorithm.py
|   |   |──c/
|   |   |   +  euclidean_algorithm.exe

Pros:

  • Easy to navigate
  • Will not run have naming issues in future unless the structure of arcane-algorithm-archive/contents is changed
  • Building specific chapters is easy with SCons

Cons:

  • Deeply nested
  • Redundant folder dulplication of the language folders
  • Building specific languages is difficult with SCons (unless this is implemented specifically)

Option 2: Same as Option 1, but with languages being the outer folders

This has most of the same pros and cons as Option 1, however building specific languages is easy and specific chapters hard

Option 3: Suffix files with _source_file_name

This would have the same structure as currently, however the executable names would be chapter_filename. The folder structure this would generate is below

arcane-algorithm-archive/
|──build/
|   |──c/
|   |   +  barnsley_barnsley_1.exe
|   |   +  barnsley_barnsley_2.exe
|   |   +  euclidean_algorithm_euclidean.exe
|   |
|   |──python/
|   |   +  barnsley_barnsley.py
|   |   +  euclidean_algorithm_euclidean.py

Pros:

  • Folders are no more deeply nested than currently
  • Building specific langauges is easy

Cons:

  • Many redundant file names e.g. barnsley_barnsley.py
  • 'Feels' like a rehash of Option 2, with prefixes instead of folders

Option 4: Only suffix with file name when multiple files are present

Example structure:

arcane-algorithm-archive/
|──build/
|   |──c/
|   |   +  barnsley_barnsley_1.exe
|   |   +  barnsley_barnsley_2.exe
|   |   +  euclidean_algorithm.exe
|   |
|   |──python/
|   |   +  barnsley.py
|   |   +  euclidean_algorithm.py

Pros:

  • Folders are no more deeply nested than currently
  • Building specific langauges is easy
  • No redundant file names

Cons:

  • Still 'feels' like a rehash of Option 2

Option 5: Use subfolder when multiple files are present

This is a mix of Option 4 and Option 2. The executables are named after the chapter name when there is only 1 file, and named after the source file name when multiple are present

arcane-algorithm-archive/
|──build/
|   |──c/
|   |   |──barnsley/
|   |   |   +  barnsley_1.exe
|   |   |   +  barnsley_2.exe
|   |   +  euclidean_algorithm.exe
|   |
|   |──python/
|   |   +  barnsley.py
|   |   +  euclidean_algorithm.py

Pros:

  • Building specific langauges is easy
  • No redundant file names
  • Uses folders instead of prefixes

Cons:

  • Sometimes more deeply nested than currently, albeit rarely
  • (Slightly) harder to traverse programatically

Conclusion

All of these are technically possible, with the exception of being able to build by language in Option 1 and the equivilents in the other options. This isn't a problem with SCons, a decision will be needed regardless of if its built with SCons, make, or our own script.

Activity

  1. PeanutbutterWarrior commented on Nov 29, 2021

    @PeanutbutterWarrior
    ContributorAuthor

    If anyone has another suggestion I'm happy to add it to the post.

    My personal prefernce is Option 5. None of these solutions are perfect, but it feels like it's the best of them

  2. Amaras commented on Nov 29, 2021

    @Amaras
    Member

    Okay, I think I need to explain my thought process during the creation of the SCons hierarchy (or atleast what I remember of it).

    I originally worked to provide Option 2, but elected against it because of the deep hierarchy concern.
    Because of this, I chose to do the current behaviour.

    IMO Option 2 is the better of the 5 options that you provide.
    The reason why is that we could provide VariantDirs where all the build artifacts stay iside the variant dir.

    Although, it is slightly annoying to do, I think we could provide Alias targets to compile all the chapter's code into their relevant folders.

    Option 5 is way more annoying to deal with from both the compilation and exploration points of view.
    I think it might confuse users, but that could be just me.
    However it is the best one after Option 2 from the compilation point of view.

    Overall, I don't know what hierarchy to choose from between Option 2 and Option 5.

  3. Amaras commented on Nov 30, 2021

    @Amaras
    Member

    @leios and @stormofice, your opinions are probably the most important in this matter.
    What do you think about this issue?

    Others can obviously weigh in, and don't hesitate to do so 😃

  4. stormofice commented on Nov 30, 2021

    @stormofice
    Contributor

    As I need to adjust the file traversal and execution of language implementations in the verifier anyway (to make use of SCons), it doesn't matter too much which option gets picked (at least regarding the effort to implement it).

    I personally lean towards Options 2 and 5, but slightly prefer Option 2, as it resembles the original file hierarchy more closely.

    In my opinion the filenames generated by Option 3 and 4 are a bit too complex and Option 1 is a little messy regarding the deep hierarchies it would create (as discussed above).

  5. leios commented on Dec 1, 2021

    @leios
    Member

    I also agree with everyone else. I think option 2 is good. I am a bit concerned about chapters with sub-chapters (like convolutions, for example), but I think option 2 will cover that as well.

    Thanks a bunch for looking at this!

  6. PeanutbutterWarrior commented on Dec 1, 2021

    @PeanutbutterWarrior
    ContributorAuthor

    Sounds like there's agreement on Option 2. I'll get to work on a PR to make SCons work.

  7. Amaras commented on Dec 1, 2021

    @Amaras
    Member

    Perfect, looking forward to seeing it in PR form! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions