Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor client code and extract repository/library methods into new modules #510

Merged
merged 69 commits into from
Apr 6, 2022

Conversation

tobil4sk
Copy link
Member

@tobil4sk tobil4sk commented Apr 6, 2021

This PR aims to make the client code cleaner and put it into modules that might be reusable in other tools, such as IDEs, or other frontends to the compiler.

Right now the haxelib.client.Main class is where most of the client code is found. Separating the specific user interface elements of the haxelib client from the functionality behind managing the database would be a step towards making the haxe frontend independent of haxelib. It would be possible to just reuse these specific modules to fetch the library locations from where the haxelib client installs them.

Other more general changes are using final where possible to keep code clean, and making use of more modern haxe 4 features. Moved to #547

Progress:

  • Add hx3compat dependency to the haxelib.json, so that this can be used properly as a dependency for other projects.
  • Extract methods for managing the location of haxelib repositories into the new module RepoManager.
  • Refactor client initialization code
  • Extract methods for setting and getting library versions
  • Testing
    • Haxelib integration testing
    • API Testing
  • Documentation

Issues fixed:

@tobil4sk tobil4sk marked this pull request as draft April 9, 2021 21:31
@tobil4sk tobil4sk changed the title Extract repository management methods Refactor client code and extract repository/library methods into new modules Apr 12, 2021
@tobil4sk tobil4sk force-pushed the repo-refactor branch 8 times, most recently from 5124a38 to 26ec7cf Compare October 26, 2021 22:38
@tobil4sk tobil4sk marked this pull request as ready for review October 28, 2021 12:22
@tobil4sk
Copy link
Member Author

Pretty close to being done now, all that's left is to address #465 (because right now it's worse than it was before...) and to add some more tests for the new modules. I'll also go through and write down the full list of changes if anything was fixed/changed while rewriting the code.

@tobil4sk
Copy link
Member Author

tobil4sk commented Jan 6, 2022

Alright, so I've done all of the integration tests to cover the fixes I've made, and now I just want to write some more tests for the API by itself. Might be good to also consider how usable the API is in its current state as well.

There were some bugs/issues that got solved by rewriting the code, and so instead of reintroducing the bug for the sake of it I documented everything that got fixed by rewriting the code and I wrote new tests for most of these changes. There was also #529 which after rewriting the code was left completely broken, so instead of recreating the intricate buggy state that we had before, I attempted to fix it. I will follow up with a summary of all the changes.

@tobil4sk
Copy link
Member Author

tobil4sk commented Jan 6, 2022

Summary of changes:

GENERAL

API

  • Allow usage of all haxelib functionality via separate modules in the
    haxelib.api package
  • Running a haxelib cleans up environment variables after itself
  • Documented the new API

RUN

  • Fix specifying a version not working if a development directory is set
    (to match behaviour of path) compiler -lib: ignore .dev if library version specified #249
  • Show an error if a non-existent version is specified instead of
    silently using a different version
  • Reset environment variables and current working directory after a run
    so that it is safe to use as a function in a process
  • Fix check for whether to use --haxelib-global Minor fixes and cleanup #550
  • Fix version check breaking on old versions of haxe

PATH

  • If two versions of the same library are given to path, the error mentions
    them in the order they were passed in

PATH and LIBPATH

  • Show error if a non-existent library version is specified with either
    command, instead of silently using a different version, as now with
    the run command

LIST

  • Libraries are now correctly ordered alphabetically
  • Do not list invalid versions

INSTALL

  • Check for hlc hashlink target when installing from hxml
  • Installing from haxelib.json with --skip-dependencies now installs the
    libraries in the haxelib.json, but not their dependencies. Previously, it
    did nothing at all.
  • Prevent installing repeated library versions from hxml
  • List libraries in order they appear when installing from hxmls
  • When installing from hxmls, library names are now case insensitive haxelib install from hxml is case sensitive and should not (tested on version haxe 3.4.7) #503

SET

UPDATE

REMOVE

  • Prevent removal of git/hg version if there is a dev version set within it

DEV, GIT and HG

@tobil4sk
Copy link
Member Author

tobil4sk commented Jan 9, 2022

I wrote some tests for the API so everything should be good, I'll leave this now for review. I put some of the smaller general commits into #539 and #540 as they might be useful by themselves (and they are much less to review).

@nadako nadako removed their request for review January 20, 2022 13:58
@tobil4sk
Copy link
Member Author

tobil4sk commented Apr 3, 2022

Moved some more general changes into #547 and #548.

#546 is also required for the tests here to run properly.

@tobil4sk tobil4sk mentioned this pull request Apr 4, 2022
Generate the regex from TARGETS to avoid repetition
`-D run` requires hashlink library to be installed even for bytecode
compilation.
src/haxelib/api/LibraryData.hx Outdated Show resolved Hide resolved
src/haxelib/api/Vcs.hx Outdated Show resolved Hide resolved
err: Std.string(e)
}
}
final out = p.stdout.readAll().toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future: This is not guaranteed to work because stderr could be full before stdout finishes reading and vice versa. This is actually a really annoying problem with our Process API and the only way around it is to use threads to make sure the pipes don't clog. We should at some point look into this situation, even if in practice it is unlikely to make much of a difference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be fixed if the exitCode() call comes before those two?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the process still won't terminate if its pipes are full. Calling exitCode would trigger a flush, but that doesn't help if nobody picks anything up on the other side.

}
}

private class AlreadyUpToDate extends InstallationException {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep this for now, but in general I would prefer not to manage control flow via exceptions. I'm pretty used to it in OCaml, but it can be a mess even there and we really shouldn't have to do this in Haxe.

src/haxelib/api/Installer.hx Outdated Show resolved Hide resolved
src/haxelib/api/Installer.hx Outdated Show resolved Hide resolved
src/haxelib/api/Installer.hx Outdated Show resolved Hide resolved
It is now combined with installFromHaxelib, whose version argument is
now optional.
No need to check if the requested version matches the scope version, as
if that were the case it would have been caught in the check above.
Prevent reinstalling existing libraries
@Simn
Copy link
Member

Simn commented Apr 6, 2022

Happy birthday, PR #510!

@Simn Simn merged commit c05b4c6 into HaxeFoundation:development Apr 6, 2022
@tobil4sk
Copy link
Member Author

tobil4sk commented Apr 6, 2022

🥳🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants