Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,274
    • Issues 4,274
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 412
    • Merge Requests 412
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Merge Requests
  • !3897

Merged
Opened Aug 21, 2020 by fendor@fendorDeveloper5 of 5 tasks completed5/5 tasks

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch "https://gitlab.haskell.org/fendor/ghc.git" "expose-target-parsing"
git checkout -b "fendor/ghc-expose-target-parsing" FETCH_HEAD

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout "master"
git merge --no-ff "fendor/ghc-expose-target-parsing"

Step 4. Push the result of the merge to GitLab

git push origin "master"

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

Move file target parsing from `ghc/Main` to library

  • Overview 20
  • Commits 1
  • Pipelines 9
  • Changes 2

Thank you for your contribution to GHC!

Please take a few moments to verify that your commits fulfill the following:

  • are either individually buildable or squashed
  • have commit messages which describe what they do (referring to [Notes][notes] and tickets using #NNNN syntax when appropriate)
  • have added source comments describing your change. For larger changes you likely should add a [Note][notes] and cross-reference it from the relevant places.
  • add a testcase to the testsuite. Only code refactoring.
  • replace this message with a description motivating your change

Motivation

A number of downstream consumers want to parse arguments to GHC and process them before actually passing them to the GHC monad. An example of such an consumer is hie-bios which copies a notable number of argument parsing functions from ghc/Main.hs. Example:

  • Normalise filepaths like GHC https://github.com/mpickering/hie-bios/blob/master/src/HIE/Bios/Environment.hs#L167 https://gitlab.haskell.org/ghc/ghc/-/blob/master/ghc/Main.hs#L229
  • Partition arguments: https://github.com/mpickering/hie-bios/blob/master/src/HIE/Bios/Environment.hs#L226
    https://gitlab.haskell.org/ghc/ghc/-/blob/master/ghc/Main.hs#L299

Proposal

Move the functions in question to the library so that downstream consumers such as hie-bios can use them. This should be trivial, the only question for me is, to which module it should be used. Functions in question are:

normalise_hyp :: FilePath -> FilePath 
normalise_hyp fp
        | strt_dot_sl && "-" `isPrefixOf` nfp = cur_dir ++ nfp
        | otherwise                           = nfp
        where
#if defined(mingw32_HOST_OS)
          strt_dot_sl = "./" `isPrefixOf` fp || ".\\" `isPrefixOf` fp
#else
          strt_dot_sl = "./" `isPrefixOf` fp
#endif
          cur_dir = '.' : [pathSeparator]
          nfp = normalise fp

parseTargetFiles :: DynFlags -> [Located String] -> (DynFlags, [(String, Maybe Phase)], [String])
parseTargetFiles dflags4 fileish_args =
    normal_fileish_paths = map (normalise_hyp . unLoc) fileish_args
    (srcs, objs)         = partition_args normal_fileish_paths [] []

    dflags5 = dflags4 { ldInputs = map (FileOption "") objs
                                   ++ ldInputs dflags4 }
  in (dflags5, srcs, objs)

-- Optionally, also expose
partition_args :: [String] -> [(String, Maybe Phase)] -> [String]
               -> ([(String, Maybe Phase)], [String])
looks_like_an_input :: String -> Bool

I propose to move these functions to compiler/GHC.hs, next to parseDynamicFlags and expose at least parseTargetFiles.

closes #18596 (closed)

Edited Sep 30, 2020 by fendor
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
Reference: ghc/ghc!3897
Source branch: expose-target-parsing

Revert this commit

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this commit

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.