Skip to content

Wip/write file atomic #10964

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Distribution/Utils/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ writeFileAtomic targetPath content = do
LBS.hPut handle content
hClose handle
Exception.catch
(renameFile tmpPath targetPath)
(replaceFile tmpPath targetPath)
( \(_ :: Exception.SomeException) -> do
copyFile tmpPath targetPath
removeFile tmpPath
Expand Down
4 changes: 3 additions & 1 deletion Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ componentAsmGhcOptions verbosity lbi bi clbi odir filename =
)
++ asmOptions bi
, ghcOptObjDir = toFlag odir
, ghcOptExtra = hcOptions GHC bi
}

componentJsGhcOptions
Expand All @@ -508,6 +509,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename =
, ghcOptPackageDBs = withPackageDB lbi
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
, ghcOptObjDir = toFlag odir
, ghcOptExtra = hcOptions GHC bi
}

componentGhcOptions
Expand Down Expand Up @@ -621,7 +623,7 @@ componentCmmGhcOptions verbosity lbi bi clbi odir filename =
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
, ghcOptOptimisation = toGhcOptimisation (withOptimization lbi)
, ghcOptDebugInfo = toFlag (withDebugInfo lbi)
, ghcOptExtra = cmmOptions bi
, ghcOptExtra = hcOptions GHC bi <> cmmOptions bi
, ghcOptObjDir = toFlag odir
}

Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/demo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = foo
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/js-arch.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

main = do
skipUnlessJavaScript
skipIfWindows ""
setupAndCabalTest $ do
skipUnlessGhcVersion ">= 9.12"
res <- cabal' "v2-run" ["demo"]
assertOutputContains "Hello definition!" res
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/jsbits/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//#OPTIONS: CPP

function foo() {
#ifdef PRINT_DEF
console.log("Hello definition!");
#else
console.log("Hello!");
#endif
}
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/jsghcoptions.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cabal-version: 3.0
name: jsghcoptions
version: 0
build-type: Simple

library
default-language: Haskell2010
js-sources: jsbits/lib.js
if arch(JavaScript)
ghc-options: -optJSP-DPRINT_DEF
hs-source-dirs: src
exposed-modules: Lib
build-depends: base

executable demo
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: demo
build-depends: base, jsghcoptions
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/other-arch.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal v2-run
Configuration is affected by the following files:
- cabal.project
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- jsghcoptions-0 (lib) (first run)
- jsghcoptions-0 (exe:demo) (first run)
Configuring library for jsghcoptions-0...
Preprocessing library for jsghcoptions-0...
Building library for jsghcoptions-0...
Configuring executable 'demo' for jsghcoptions-0...
Preprocessing executable 'demo' for jsghcoptions-0...
Building executable 'demo' for jsghcoptions-0...
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/other-arch.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

main = do
skipIfJavaScript
cabalTest $ do
-- Ensure the field `js-sources` does not raise issues
res <- cabal' "v2-run" ["demo"]
assertOutputContains "Not JS foo" res
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/JS/GhcOptions/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE CPP #-}
module Lib where

#if defined(javascript_HOST_ARCH)
foreign import javascript foo :: IO ()
#else
foo :: IO ()
foo = putStrLn "Not JS foo"
#endif
10 changes: 10 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ package cabal-install

package Cabal
flags: +git-rev

source-repository-package
type: git
location: https://github.com/zlonast/win32.git
tag: 1805af5af1db5131b23b14edf0e2ba8c16e6710f

source-repository-package
type: git
location: https://github.com/zlonast/directory.git
tag: e67c28da0f06d82d1f19dfcc2e0fb51e45a8399b
13 changes: 13 additions & 0 deletions changelog.d/pr-10949.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
synopsis: "ghc-options added to js, cmm and asm"
packages: [Cabal]
prs: 10949
---

Now we have the ability to pass ghc-options flags to all component.

```
js-sources: jsbits/lib.js
ghc-options: -optJSP-your_flag
```

Loading